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 (
38
from bzrlib.plugins.gtk.i18n import _i18n
41
class NoDisplayError(errors.BzrCommandError):
42
"""gtk could not find a proper display"""
45
return "No DISPLAY. Unable to run GTK+ application."
49
pygtk = import_pygtk()
52
except RuntimeError, e:
53
if str(e) == "could not open display":
60
class GTKCommand(Command):
61
"""Abstract class providing GTK specific run commands."""
65
dialog = self.get_gtk_dialog(os.path.abspath('.'))
69
class cmd_gbranch(GTKCommand):
74
def get_gtk_dialog(self, path):
75
from bzrlib.plugins.gtk.branch import BranchDialog
76
return BranchDialog(path)
79
class cmd_gcheckout(GTKCommand):
84
def get_gtk_dialog(self, path):
85
from bzrlib.plugins.gtk.checkout import CheckoutDialog
86
return CheckoutDialog(path)
90
class cmd_gpush(GTKCommand):
94
takes_args = [ "location?" ]
96
def run(self, location="."):
97
(br, path) = branch.Branch.open_containing(location)
99
from bzrlib.plugins.gtk.push import PushDialog
100
dialog = PushDialog(br.repository, br.last_revision(), br)
104
class cmd_gloom(GTKCommand):
108
takes_args = [ "location?" ]
110
def run(self, location="."):
112
(tree, path) = workingtree.WorkingTree.open_containing(location)
114
except NoWorkingTree, e:
115
(br, path) = branch.Branch.open_containing(location)
118
from bzrlib.plugins.gtk.loom import LoomDialog
119
dialog = LoomDialog(br, tree)
123
class cmd_gdiff(GTKCommand):
124
"""Show differences in working tree in a GTK+ Window.
126
Otherwise, all changes for the tree are listed.
128
takes_args = ['filename?']
129
takes_options = ['revision']
132
def run(self, revision=None, filename=None):
134
wt = workingtree.WorkingTree.open_containing(".")[0]
138
if revision is not None:
139
if len(revision) == 1:
141
revision_id = revision[0].as_revision_id(tree1.branch)
142
tree2 = branch.repository.revision_tree(revision_id)
143
elif len(revision) == 2:
144
revision_id_0 = revision[0].as_revision_id(branch)
145
tree2 = branch.repository.revision_tree(revision_id_0)
146
revision_id_1 = revision[1].as_revision_id(branch)
147
tree1 = branch.repository.revision_tree(revision_id_1)
150
tree2 = tree1.basis_tree()
152
from diff import DiffWindow
154
window = DiffWindow()
155
window.connect("destroy", gtk.main_quit)
156
window.set_diff("Working Tree", tree1, tree2)
157
if filename is not None:
158
tree_filename = wt.relpath(filename)
160
window.set_file(tree_filename)
162
if (tree1.path2id(tree_filename) is None and
163
tree2.path2id(tree_filename) is None):
164
raise NotVersionedError(filename)
165
raise BzrCommandError('No changes found for file "%s"' %
174
def start_viz_window(branch, revisions, limit=None):
175
"""Start viz on branch with revision revision.
177
:return: The viz window object.
179
from bzrlib.plugins.gtk.viz import BranchWindow
180
return BranchWindow(branch, revisions, limit)
183
class cmd_visualise(Command):
184
"""Graphically visualise one or several branches.
186
Opens a graphical window to allow you to see branches history and
187
relationships between revisions in a visual manner,
189
If no revision is specified, the branch last revision is taken as a
190
starting point. When a revision is specified, the presented graph starts
191
with it (as a side effect, when a shared repository is used, any revision
192
can be used even if it's not part of the branch history).
196
Option('limit', "Maximum number of revisions to display.",
198
takes_args = [ "locations*" ]
199
aliases = [ "visualize", "vis", "viz" ]
201
def run(self, locations_list, revision=None, limit=None):
203
if locations_list is None:
204
locations_list = ["."]
206
for location in locations_list:
207
(br, path) = branch.Branch.open_containing(location)
209
revids.append(br.last_revision())
211
revids.append(revision[0].as_revision_id(br))
213
pp = start_viz_window(br, revids, limit)
214
pp.connect("destroy", lambda w: gtk.main_quit())
219
class cmd_gannotate(GTKCommand):
222
Browse changes to FILENAME line by line in a GTK+ window.
224
Within the annotate window, you can use Ctrl-F to search for text, and
225
Ctrl-G to jump to a line by number.
228
takes_args = ["filename", "line?"]
230
Option("all", help="Show annotations on all lines."),
231
Option("plain", help="Don't highlight annotation lines."),
232
Option("line", type=int, argname="lineno",
233
help="Jump to specified line number."),
236
aliases = ["gblame", "gpraise"]
238
def run(self, filename, all=False, plain=False, line='1', revision=None):
244
raise BzrCommandError('Line argument ("%s") is not a number.' %
247
from annotate.gannotate import GAnnotateWindow
248
from annotate.config import GAnnotateConfig
249
from bzrlib.bzrdir import BzrDir
251
wt, br, path = BzrDir.open_containing_tree_or_branch(filename)
255
tree = br.basis_tree()
257
file_id = tree.path2id(path)
260
raise NotVersionedError(filename)
261
if revision is not None:
262
if len(revision) != 1:
263
raise BzrCommandError("Only 1 revion may be specified.")
264
revision_id = revision[0].as_revision_id(br)
265
tree = br.repository.revision_tree(revision_id)
267
revision_id = getattr(tree, 'get_revision_id', lambda: None)()
269
window = GAnnotateWindow(all, plain, branch=br)
270
window.connect("destroy", lambda w: gtk.main_quit())
271
config = GAnnotateConfig(window)
277
window.annotate(tree, br, file_id)
278
window.jump_to_line(line)
287
class cmd_gcommit(GTKCommand):
288
"""GTK+ commit dialog
290
Graphical user interface for committing revisions"""
296
def run(self, filename=None):
298
from commit import CommitDialog
303
(wt, path) = workingtree.WorkingTree.open_containing(filename)
305
except NoWorkingTree, e:
306
from dialog import error_dialog
307
error_dialog(_i18n('Directory does not have a working tree'),
308
_i18n('Operation aborted.'))
309
return 1 # should this be retval=3?
311
# It is a good habit to keep things locked for the duration, but it
312
# could cause difficulties if someone wants to do things in another
313
# window... We could lock_read() until we actually go to commit
314
# changes... Just a thought.
317
dlg = CommitDialog(wt)
323
class cmd_gstatus(GTKCommand):
324
"""GTK+ status dialog
326
Graphical user interface for showing status
330
takes_args = ['PATH?']
331
takes_options = ['revision']
333
def run(self, path='.', revision=None):
335
from bzrlib.plugins.gtk.status import StatusWindow
336
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
338
if revision is not None:
340
revision_id = revision[0].as_revision_id(wt.branch)
342
from bzrlib.errors import BzrError
343
raise BzrError('Revision %r doesn\'t exist'
344
% revision[0].user_spec )
348
status = StatusWindow(wt, wt_path, revision_id)
349
status.connect("destroy", gtk.main_quit)
354
class cmd_gsend(GTKCommand):
355
"""GTK+ send merge directive.
359
(br, path) = branch.Branch.open_containing(".")
361
from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
362
from StringIO import StringIO
363
dialog = SendMergeDirectiveDialog(br)
364
if dialog.run() == gtk.RESPONSE_OK:
366
outf.writelines(dialog.get_merge_directive().to_lines())
367
mail_client = br.get_config().get_mail_client()
368
mail_client.compose_merge_request(dialog.get_mail_to(), "[MERGE]",
374
class cmd_gconflicts(GTKCommand):
377
Select files from the list of conflicts and run an external utility to
381
(wt, path) = workingtree.WorkingTree.open_containing('.')
383
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
384
dialog = ConflictsDialog(wt)
388
class cmd_gpreferences(GTKCommand):
389
""" GTK+ preferences dialog.
394
from bzrlib.plugins.gtk.preferences import PreferencesWindow
395
dialog = PreferencesWindow()
399
class cmd_gmerge(Command):
400
""" GTK+ merge dialog
403
takes_args = ["merge_from_path?"]
404
def run(self, merge_from_path=None):
405
from bzrlib.plugins.gtk.dialog import error_dialog
406
from bzrlib.plugins.gtk.merge import MergeDialog
408
(wt, path) = workingtree.WorkingTree.open_containing('.')
409
old_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
410
delta = wt.changes_from(old_tree)
411
if len(delta.added) or len(delta.removed) or len(delta.renamed) or len(delta.modified):
412
error_dialog(_i18n('There are local changes in the branch'),
413
_i18n('Please commit or revert the changes before merging.'))
415
parent_branch_path = wt.branch.get_parent()
416
merge = MergeDialog(wt, path, parent_branch_path)
417
response = merge.run()
421
class cmd_gmissing(Command):
422
""" GTK+ missing revisions dialog.
425
takes_args = ["other_branch?"]
426
def run(self, other_branch=None):
427
pygtk = import_pygtk()
430
except RuntimeError, e:
431
if str(e) == "could not open display":
434
from bzrlib.plugins.gtk.missing import MissingWindow
435
from bzrlib.branch import Branch
437
local_branch = Branch.open_containing(".")[0]
438
if other_branch is None:
439
other_branch = local_branch.get_parent()
441
if other_branch is None:
442
raise BzrCommandError("No peer location known or specified.")
443
remote_branch = Branch.open_containing(other_branch)[0]
445
local_branch.lock_read()
447
remote_branch.lock_read()
449
dialog = MissingWindow(local_branch, remote_branch)
452
remote_branch.unlock()
454
local_branch.unlock()
457
class cmd_ginit(GTKCommand):
460
Graphical user interface for initializing new branches.
465
from initialize import InitDialog
466
dialog = InitDialog(os.path.abspath(os.path.curdir))
470
class cmd_gtags(GTKCommand):
473
Graphical user interface to view, create, or remove tags.
477
br = branch.Branch.open_containing('.')[0]
480
from tags import TagsWindow
481
window = TagsWindow(br)