1
# This program is free software; you can redistribute it and/or modify
2
# it under the terms of the GNU General Public License as published by
3
# the Free Software Foundation; either version 2 of the License, or
4
# (at your option) any later version.
6
# This program is distributed in the hope that it will be useful,
7
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
# GNU General Public License for more details.
11
# You should have received a copy of the GNU General Public License
12
# along with this program; if not, write to the Free Software
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
from bzrlib.commands import (
26
from bzrlib.errors import (
32
from bzrlib.option import Option
34
from bzrlib.plugins.gtk import (
41
class GTKCommand(Command):
42
"""Abstract class providing GTK specific run commands."""
46
dialog = self.get_gtk_dialog(os.path.abspath('.'))
50
class cmd_gbranch(GTKCommand):
55
def get_gtk_dialog(self, path):
56
from bzrlib.plugins.gtk.branch import BranchDialog
57
return BranchDialog(path)
60
class cmd_gcheckout(GTKCommand):
65
def get_gtk_dialog(self, path):
66
from bzrlib.plugins.gtk.checkout import CheckoutDialog
67
return CheckoutDialog(path)
71
class cmd_gpush(GTKCommand):
75
takes_args = [ "location?" ]
77
def run(self, location="."):
78
(br, path) = branch.Branch.open_containing(location)
80
from bzrlib.plugins.gtk.push import PushDialog
81
dialog = PushDialog(br.repository, br.last_revision(), br)
85
class cmd_gloom(GTKCommand):
89
takes_args = [ "location?" ]
91
def run(self, location="."):
93
(tree, path) = workingtree.WorkingTree.open_containing(location)
95
except NoWorkingTree, e:
96
(br, path) = branch.Branch.open_containing(location)
99
from bzrlib.plugins.gtk.loom import LoomDialog
100
dialog = LoomDialog(br, tree)
104
class cmd_gdiff(GTKCommand):
105
"""Show differences in working tree in a GTK+ Window.
107
Otherwise, all changes for the tree are listed.
109
takes_args = ['filename?']
110
takes_options = ['revision']
113
def run(self, revision=None, filename=None):
115
wt = workingtree.WorkingTree.open_containing(".")[0]
119
if revision is not None:
120
if len(revision) == 1:
122
revision_id = revision[0].as_revision_id(tree1.branch)
123
tree2 = branch.repository.revision_tree(revision_id)
124
elif len(revision) == 2:
125
revision_id_0 = revision[0].as_revision_id(branch)
126
tree2 = branch.repository.revision_tree(revision_id_0)
127
revision_id_1 = revision[1].as_revision_id(branch)
128
tree1 = branch.repository.revision_tree(revision_id_1)
131
tree2 = tree1.basis_tree()
133
from diff import DiffWindow
135
window = DiffWindow()
136
window.connect("destroy", gtk.main_quit)
137
window.set_diff("Working Tree", tree1, tree2)
138
if filename is not None:
139
tree_filename = wt.relpath(filename)
141
window.set_file(tree_filename)
143
if (tree1.path2id(tree_filename) is None and
144
tree2.path2id(tree_filename) is None):
145
raise NotVersionedError(filename)
146
raise BzrCommandError('No changes found for file "%s"' %
155
def start_viz_window(branch, revisions, limit=None):
156
"""Start viz on branch with revision revision.
158
:return: The viz window object.
160
from bzrlib.plugins.gtk.viz import BranchWindow
161
return BranchWindow(branch, revisions, limit)
164
class cmd_visualise(Command):
165
"""Graphically visualise this branch.
167
Opens a graphical window to allow you to see the history of the branch
168
and relationships between revisions in a visual manner,
170
The default starting point is latest revision on the branch, you can
171
specify a starting point with -r revision.
175
Option('limit', "Maximum number of revisions to display.",
177
takes_args = [ "locations*" ]
178
aliases = [ "visualize", "vis", "viz" ]
180
def run(self, locations_list, revision=None, limit=None):
182
if locations_list is None:
183
locations_list = ["."]
185
for location in locations_list:
186
(br, path) = branch.Branch.open_containing(location)
188
revids.append(br.last_revision())
190
revids.append(revision[0].as_revision_id(br))
192
pp = start_viz_window(br, revids, limit)
193
pp.connect("destroy", lambda w: gtk.main_quit())
198
class cmd_gannotate(GTKCommand):
201
Browse changes to FILENAME line by line in a GTK+ window.
204
takes_args = ["filename", "line?"]
206
Option("all", help="Show annotations on all lines."),
207
Option("plain", help="Don't highlight annotation lines."),
208
Option("line", type=int, argname="lineno",
209
help="Jump to specified line number."),
212
aliases = ["gblame", "gpraise"]
214
def run(self, filename, all=False, plain=False, line='1', revision=None):
220
raise BzrCommandError('Line argument ("%s") is not a number.' %
223
from annotate.gannotate import GAnnotateWindow
224
from annotate.config import GAnnotateConfig
225
from bzrlib.bzrdir import BzrDir
227
wt, br, path = BzrDir.open_containing_tree_or_branch(filename)
231
tree = br.basis_tree()
233
file_id = tree.path2id(path)
236
raise NotVersionedError(filename)
237
if revision is not None:
238
if len(revision) != 1:
239
raise BzrCommandError("Only 1 revion may be specified.")
240
revision_id = revision[0].as_revision_id(br)
241
tree = br.repository.revision_tree(revision_id)
243
revision_id = getattr(tree, 'get_revision_id', lambda: None)()
245
window = GAnnotateWindow(all, plain, branch=br)
246
window.connect("destroy", lambda w: gtk.main_quit())
247
config = GAnnotateConfig(window)
253
window.annotate(tree, br, file_id)
254
window.jump_to_line(line)
263
class cmd_gcommit(GTKCommand):
264
"""GTK+ commit dialog
266
Graphical user interface for committing revisions"""
272
def run(self, filename=None):
274
from commit import CommitDialog
279
(wt, path) = workingtree.WorkingTree.open_containing(filename)
281
except NoWorkingTree, e:
282
from dialog import error_dialog
283
error_dialog(_i18n('Directory does not have a working tree'),
284
_i18n('Operation aborted.'))
285
return 1 # should this be retval=3?
287
# It is a good habit to keep things locked for the duration, but it
288
# could cause difficulties if someone wants to do things in another
289
# window... We could lock_read() until we actually go to commit
290
# changes... Just a thought.
293
dlg = CommitDialog(wt)
299
class cmd_gstatus(GTKCommand):
300
"""GTK+ status dialog
302
Graphical user interface for showing status
306
takes_args = ['PATH?']
307
takes_options = ['revision']
309
def run(self, path='.', revision=None):
311
from bzrlib.plugins.gtk.status import StatusWindow
312
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
314
if revision is not None:
316
revision_id = revision[0].as_revision_id(wt.branch)
318
from bzrlib.errors import BzrError
319
raise BzrError('Revision %r doesn\'t exist'
320
% revision[0].user_spec )
324
status = StatusWindow(wt, wt_path, revision_id)
325
status.connect("destroy", gtk.main_quit)
330
class cmd_gsend(GTKCommand):
331
"""GTK+ send merge directive.
335
(br, path) = branch.Branch.open_containing(".")
337
from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
338
from StringIO import StringIO
339
dialog = SendMergeDirectiveDialog(br)
340
if dialog.run() == gtk.RESPONSE_OK:
342
outf.writelines(dialog.get_merge_directive().to_lines())
343
mail_client = br.get_config().get_mail_client()
344
mail_client.compose_merge_request(dialog.get_mail_to(), "[MERGE]",
350
class cmd_gconflicts(GTKCommand):
353
Select files from the list of conflicts and run an external utility to
357
(wt, path) = workingtree.WorkingTree.open_containing('.')
359
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
360
dialog = ConflictsDialog(wt)
364
class cmd_gpreferences(GTKCommand):
365
""" GTK+ preferences dialog.
370
from bzrlib.plugins.gtk.preferences import PreferencesWindow
371
dialog = PreferencesWindow()
375
class cmd_ginfo(Command):
380
from bzrlib import workingtree
381
from bzrlib.plugins.gtk.olive.info import InfoDialog
382
wt = workingtree.WorkingTree.open_containing('.')[0]
383
info = InfoDialog(wt.branch)
388
class cmd_gmerge(Command):
389
""" GTK+ merge dialog
392
takes_args = ["merge_from_path?"]
393
def run(self, merge_from_path=None):
394
from bzrlib.plugins.gtk.dialog import error_dialog
395
from bzrlib.plugins.gtk.merge import MergeDialog
397
(wt, path) = workingtree.WorkingTree.open_containing('.')
398
old_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
399
delta = wt.changes_from(old_tree)
400
if len(delta.added) or len(delta.removed) or len(delta.renamed) or len(delta.modified):
401
error_dialog(_i18n('There are local changes in the branch'),
402
_i18n('Please commit or revert the changes before merging.'))
404
parent_branch_path = wt.branch.get_parent()
405
merge = MergeDialog(wt, path, parent_branch_path)
406
response = merge.run()
410
class cmd_gmissing(Command):
411
""" GTK+ missing revisions dialog.
414
takes_args = ["other_branch?"]
415
def run(self, other_branch=None):
416
pygtk = import_pygtk()
419
except RuntimeError, e:
420
if str(e) == "could not open display":
423
from bzrlib.plugins.gtk.missing import MissingWindow
424
from bzrlib.branch import Branch
426
local_branch = Branch.open_containing(".")[0]
427
if other_branch is None:
428
other_branch = local_branch.get_parent()
430
if other_branch is None:
431
raise BzrCommandError("No peer location known or specified.")
432
remote_branch = Branch.open_containing(other_branch)[0]
434
local_branch.lock_read()
436
remote_branch.lock_read()
438
dialog = MissingWindow(local_branch, remote_branch)
441
remote_branch.unlock()
443
local_branch.unlock()
446
class cmd_ginit(GTKCommand):
449
Graphical user interface for initializing new branches.
454
from initialize import InitDialog
455
dialog = InitDialog(os.path.abspath(os.path.curdir))
459
class cmd_gtags(GTKCommand):
462
Graphical user interface to view, create, or remove tags.
466
br = branch.Branch.open_containing('.')[0]
469
from tags import TagsWindow
470
window = TagsWindow(br)
475
class cmd_gselftest(GTKCommand):
476
"""Version of selftest that displays a notification at the end"""
478
takes_args = builtins.cmd_selftest.takes_args
479
takes_options = builtins.cmd_selftest.takes_options
480
_see_also = ['selftest']
482
def run(self, *args, **kwargs):
485
default_encoding = sys.getdefaultencoding()
486
# prevent gtk from blowing up later
488
# prevent gtk from messing with default encoding
490
if sys.getdefaultencoding() != default_encoding:
492
sys.setdefaultencoding(default_encoding)
493
result = builtins.cmd_selftest().run(*args, **kwargs)
496
body = 'Selftest succeeded in "%s"' % os.getcwd()
499
body = 'Selftest failed in "%s"' % os.getcwd()
500
pynotify.init("bzr gselftest")
501
note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
502
note.set_timeout(pynotify.EXPIRES_NEVER)