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
21
from bzrlib.commands import (
25
from bzrlib.errors import (
30
from bzrlib.option import Option
32
from bzrlib.plugins.gtk import (
38
class GTKCommand(Command):
39
"""Abstract class providing GTK specific run commands."""
43
dialog = self.get_gtk_dialog(os.path.abspath('.'))
47
class cmd_gbranch(GTKCommand):
52
def get_gtk_dialog(self, path):
53
from bzrlib.plugins.gtk.branch import BranchDialog
54
return BranchDialog(path)
57
class cmd_gcheckout(GTKCommand):
62
def get_gtk_dialog(self, path):
63
from bzrlib.plugins.gtk.checkout import CheckoutDialog
64
return CheckoutDialog(path)
68
class cmd_gpush(GTKCommand):
72
takes_args = [ "location?" ]
74
def run(self, location="."):
75
(br, path) = branch.Branch.open_containing(location)
77
from bzrlib.plugins.gtk.push import PushDialog
78
dialog = PushDialog(br.repository, br.last_revision(), br)
82
class cmd_gloom(GTKCommand):
86
takes_args = [ "location?" ]
88
def run(self, location="."):
90
(tree, path) = workingtree.WorkingTree.open_containing(location)
92
except NoWorkingTree, e:
93
(br, path) = branch.Branch.open_containing(location)
96
from bzrlib.plugins.gtk.loom import LoomDialog
97
dialog = LoomDialog(br, tree)
101
class cmd_gdiff(GTKCommand):
102
"""Show differences in working tree in a GTK+ Window.
104
Otherwise, all changes for the tree are listed.
106
takes_args = ['filename?']
107
takes_options = ['revision']
110
def run(self, revision=None, filename=None):
112
wt = workingtree.WorkingTree.open_containing(".")[0]
116
if revision is not None:
117
if len(revision) == 1:
119
revision_id = revision[0].as_revision_id(tree1.branch)
120
tree2 = branch.repository.revision_tree(revision_id)
121
elif len(revision) == 2:
122
revision_id_0 = revision[0].as_revision_id(branch)
123
tree2 = branch.repository.revision_tree(revision_id_0)
124
revision_id_1 = revision[1].as_revision_id(branch)
125
tree1 = branch.repository.revision_tree(revision_id_1)
128
tree2 = tree1.basis_tree()
130
from diff import DiffWindow
132
window = DiffWindow()
133
window.connect("destroy", gtk.main_quit)
134
window.set_diff("Working Tree", tree1, tree2)
135
if filename is not None:
136
tree_filename = wt.relpath(filename)
138
window.set_file(tree_filename)
140
if (tree1.path2id(tree_filename) is None and
141
tree2.path2id(tree_filename) is None):
142
raise NotVersionedError(filename)
143
raise BzrCommandError('No changes found for file "%s"' %
152
def start_viz_window(branch, revisions, limit=None):
153
"""Start viz on branch with revision revision.
155
:return: The viz window object.
157
from bzrlib.plugins.gtk.viz import BranchWindow
158
return BranchWindow(branch, revisions, limit)
161
class cmd_visualise(Command):
162
"""Graphically visualise this branch.
164
Opens a graphical window to allow you to see the history of the branch
165
and relationships between revisions in a visual manner,
167
The default starting point is latest revision on the branch, you can
168
specify a starting point with -r revision.
172
Option('limit', "Maximum number of revisions to display.",
174
takes_args = [ "locations*" ]
175
aliases = [ "visualize", "vis", "viz" ]
177
def run(self, locations_list, revision=None, limit=None):
179
if locations_list is None:
180
locations_list = ["."]
182
for location in locations_list:
183
(br, path) = branch.Branch.open_containing(location)
185
revids.append(br.last_revision())
187
revids.append(revision[0].as_revision_id(br))
189
pp = start_viz_window(br, revids, limit)
190
pp.connect("destroy", lambda w: gtk.main_quit())
195
class cmd_gannotate(GTKCommand):
198
Browse changes to FILENAME line by line in a GTK+ window.
201
takes_args = ["filename", "line?"]
203
Option("all", help="Show annotations on all lines."),
204
Option("plain", help="Don't highlight annotation lines."),
205
Option("line", type=int, argname="lineno",
206
help="Jump to specified line number."),
209
aliases = ["gblame", "gpraise"]
211
def run(self, filename, all=False, plain=False, line='1', revision=None):
217
raise BzrCommandError('Line argument ("%s") is not a number.' %
220
from annotate.gannotate import GAnnotateWindow
221
from annotate.config import GAnnotateConfig
222
from bzrlib.bzrdir import BzrDir
224
wt, br, path = BzrDir.open_containing_tree_or_branch(filename)
228
tree = br.basis_tree()
230
file_id = tree.path2id(path)
233
raise NotVersionedError(filename)
234
if revision is not None:
235
if len(revision) != 1:
236
raise BzrCommandError("Only 1 revion may be specified.")
237
revision_id = revision[0].as_revision_id(br)
238
tree = br.repository.revision_tree(revision_id)
240
revision_id = getattr(tree, 'get_revision_id', lambda: None)()
242
window = GAnnotateWindow(all, plain, branch=br)
243
window.connect("destroy", lambda w: gtk.main_quit())
244
config = GAnnotateConfig(window)
250
window.annotate(tree, br, file_id)
251
window.jump_to_line(line)
260
class cmd_gcommit(GTKCommand):
261
"""GTK+ commit dialog
263
Graphical user interface for committing revisions"""
269
def run(self, filename=None):
272
from commit import CommitDialog
273
from bzrlib.errors import (BzrCommandError,
280
(wt, path) = workingtree.WorkingTree.open_containing(filename)
282
except NoWorkingTree, e:
283
from dialog import error_dialog
284
error_dialog(_i18n('Directory does not have a working tree'),
285
_i18n('Operation aborted.'))
286
return 1 # should this be retval=3?
288
# It is a good habit to keep things locked for the duration, but it
289
# could cause difficulties if someone wants to do things in another
290
# window... We could lock_read() until we actually go to commit
291
# changes... Just a thought.
294
dlg = CommitDialog(wt)
300
class cmd_gstatus(GTKCommand):
301
"""GTK+ status dialog
303
Graphical user interface for showing status
307
takes_args = ['PATH?']
308
takes_options = ['revision']
310
def run(self, path='.', revision=None):
313
from bzrlib.plugins.gtk.status import StatusWindow
314
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
316
if revision is not None:
318
revision_id = revision[0].as_revision_id(wt.branch)
320
from bzrlib.errors import BzrError
321
raise BzrError('Revision %r doesn\'t exist'
322
% revision[0].user_spec )
326
status = StatusWindow(wt, wt_path, revision_id)
327
status.connect("destroy", gtk.main_quit)
332
class cmd_gsend(GTKCommand):
333
"""GTK+ send merge directive.
337
(br, path) = branch.Branch.open_containing(".")
339
from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
340
from StringIO import StringIO
341
dialog = SendMergeDirectiveDialog(br)
342
if dialog.run() == gtk.RESPONSE_OK:
344
outf.writelines(dialog.get_merge_directive().to_lines())
345
mail_client = br.get_config().get_mail_client()
346
mail_client.compose_merge_request(dialog.get_mail_to(), "[MERGE]",
352
class cmd_gconflicts(GTKCommand):
355
Select files from the list of conflicts and run an external utility to
359
(wt, path) = workingtree.WorkingTree.open_containing('.')
361
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
362
dialog = ConflictsDialog(wt)
366
class cmd_gpreferences(GTKCommand):
367
""" GTK+ preferences dialog.
372
from bzrlib.plugins.gtk.preferences import PreferencesWindow
373
dialog = PreferencesWindow()
377
class cmd_ginfo(Command):
382
from bzrlib import workingtree
383
from bzrlib.plugins.gtk.olive.info import InfoDialog
384
wt = workingtree.WorkingTree.open_containing('.')[0]
385
info = InfoDialog(wt.branch)
390
class cmd_gmerge(Command):
391
""" GTK+ merge dialog
394
takes_args = ["merge_from_path?"]
395
def run(self, merge_from_path=None):
396
from bzrlib.plugins.gtk.dialog import error_dialog
397
from bzrlib.plugins.gtk.merge import MergeDialog
399
(wt, path) = workingtree.WorkingTree.open_containing('.')
400
old_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
401
delta = wt.changes_from(old_tree)
402
if len(delta.added) or len(delta.removed) or len(delta.renamed) or len(delta.modified):
403
error_dialog(_i18n('There are local changes in the branch'),
404
_i18n('Please commit or revert the changes before merging.'))
406
parent_branch_path = wt.branch.get_parent()
407
merge = MergeDialog(wt, path, parent_branch_path)
408
response = merge.run()
412
class cmd_gmissing(Command):
413
""" GTK+ missing revisions dialog.
416
takes_args = ["other_branch?"]
417
def run(self, other_branch=None):
418
pygtk = import_pygtk()
421
except RuntimeError, e:
422
if str(e) == "could not open display":
425
from bzrlib.plugins.gtk.missing import MissingWindow
426
from bzrlib.branch import Branch
428
local_branch = Branch.open_containing(".")[0]
429
if other_branch is None:
430
other_branch = local_branch.get_parent()
432
if other_branch is None:
433
raise errors.BzrCommandError("No peer location known or specified.")
434
remote_branch = Branch.open_containing(other_branch)[0]
436
local_branch.lock_read()
438
remote_branch.lock_read()
440
dialog = MissingWindow(local_branch, remote_branch)
443
remote_branch.unlock()
445
local_branch.unlock()
448
class cmd_ginit(GTKCommand):
451
from initialize import InitDialog
452
dialog = InitDialog(os.path.abspath(os.path.curdir))
456
class cmd_gtags(GTKCommand):
458
br = branch.Branch.open_containing('.')[0]
461
from tags import TagsWindow
462
window = TagsWindow(br)
467
class cmd_gselftest(GTKCommand):
468
"""Version of selftest that displays a notification at the end"""
470
takes_args = builtins.cmd_selftest.takes_args
471
takes_options = builtins.cmd_selftest.takes_options
472
_see_also = ['selftest']
474
def run(self, *args, **kwargs):
477
default_encoding = sys.getdefaultencoding()
478
# prevent gtk from blowing up later
480
# prevent gtk from messing with default encoding
482
if sys.getdefaultencoding() != default_encoding:
484
sys.setdefaultencoding(default_encoding)
485
result = builtins.cmd_selftest().run(*args, **kwargs)
488
body = 'Selftest succeeded in "%s"' % os.getcwd()
491
body = 'Selftest failed in "%s"' % os.getcwd()
492
pynotify.init("bzr gselftest")
493
note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
494
note.set_timeout(pynotify.EXPIRES_NEVER)