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 (
37
from bzrlib.plugins.gtk.i18n import _i18n
40
class NoDisplayError(errors.BzrCommandError):
41
"""gtk could not find a proper display"""
44
return "No DISPLAY. Unable to run GTK+ application."
49
from gi.repository import Gtk
50
except RuntimeError, e:
51
if str(e) == "could not open display":
58
class GTKCommand(Command):
59
"""Abstract class providing GTK specific run commands."""
63
dialog = self.get_gtk_dialog(os.path.abspath('.'))
67
class cmd_gbranch(GTKCommand):
72
def get_gtk_dialog(self, path):
73
from bzrlib.plugins.gtk.branch import BranchDialog
74
return BranchDialog(path)
77
class cmd_gcheckout(GTKCommand):
82
def get_gtk_dialog(self, path):
83
from bzrlib.plugins.gtk.checkout import CheckoutDialog
84
return CheckoutDialog(path)
88
class cmd_gpush(GTKCommand):
92
takes_args = [ "location?" ]
94
def run(self, location="."):
95
(br, path) = branch.Branch.open_containing(location)
97
from bzrlib.plugins.gtk.push import PushDialog
98
dialog = PushDialog(br.repository, br.last_revision(), br)
102
class cmd_gloom(GTKCommand):
106
takes_args = [ "location?" ]
108
def run(self, location="."):
110
(tree, path) = workingtree.WorkingTree.open_containing(location)
112
except NoWorkingTree, e:
113
(br, path) = branch.Branch.open_containing(location)
116
from bzrlib.plugins.gtk.loom import LoomDialog
117
dialog = LoomDialog(br, tree)
121
class cmd_gdiff(GTKCommand):
122
"""Show differences in working tree in a GTK+ Window.
124
Otherwise, all changes for the tree are listed.
126
takes_args = ['filename?']
127
takes_options = ['revision']
130
def run(self, revision=None, filename=None):
132
wt = workingtree.WorkingTree.open_containing(".")[0]
136
if revision is not None:
137
if len(revision) == 1:
139
revision_id = revision[0].as_revision_id(tree1.branch)
140
tree2 = branch.repository.revision_tree(revision_id)
141
elif len(revision) == 2:
142
revision_id_0 = revision[0].as_revision_id(branch)
143
tree2 = branch.repository.revision_tree(revision_id_0)
144
revision_id_1 = revision[1].as_revision_id(branch)
145
tree1 = branch.repository.revision_tree(revision_id_1)
148
tree2 = tree1.basis_tree()
150
from diff import DiffWindow
151
from gi.repository import Gtk
152
window = DiffWindow()
153
window.connect("destroy", Gtk.main_quit)
154
window.set_diff("Working Tree", tree1, tree2)
155
if filename is not None:
156
tree_filename = wt.relpath(filename)
158
window.set_file(tree_filename)
160
if (tree1.path2id(tree_filename) is None and
161
tree2.path2id(tree_filename) is None):
162
raise NotVersionedError(filename)
163
raise BzrCommandError('No changes found for file "%s"' %
172
def start_viz_window(branch, revisions, limit=None):
173
"""Start viz on branch with revision revision.
175
:return: The viz window object.
177
from bzrlib.plugins.gtk.viz import BranchWindow
178
return BranchWindow(branch, revisions, limit)
181
class cmd_visualise(Command):
182
"""Graphically visualise one or several branches.
184
Opens a graphical window to allow you to see branches history and
185
relationships between revisions in a visual manner,
187
If no revision is specified, the branch last revision is taken as a
188
starting point. When a revision is specified, the presented graph starts
189
with it (as a side effect, when a shared repository is used, any revision
190
can be used even if it's not part of the branch history).
194
Option('limit', "Maximum number of revisions to display.",
196
takes_args = [ "locations*" ]
197
aliases = [ "visualize", "vis", "viz" ]
199
def run(self, locations_list, revision=None, limit=None):
201
if locations_list is None:
202
locations_list = ["."]
204
for location in locations_list:
205
(br, path) = branch.Branch.open_containing(location)
207
revids.append(br.last_revision())
209
revids.append(revision[0].as_revision_id(br))
210
from gi.repository import Gtk
211
pp = start_viz_window(br, revids, limit)
212
pp.connect("destroy", lambda w: Gtk.main_quit())
217
class cmd_gannotate(GTKCommand):
220
Browse changes to FILENAME line by line in a GTK+ window.
222
Within the annotate window, you can use Ctrl-F to search for text, and
223
Ctrl-G to jump to a line by number.
226
takes_args = ["filename", "line?"]
228
Option("all", help="Show annotations on all lines."),
229
Option("plain", help="Don't highlight annotation lines."),
230
Option("line", type=int, argname="lineno",
231
help="Jump to specified line number."),
234
aliases = ["gblame", "gpraise"]
236
def run(self, filename, all=False, plain=False, line='1', revision=None):
242
raise BzrCommandError('Line argument ("%s") is not a number.' %
245
from annotate.gannotate import GAnnotateWindow
246
from annotate.config import GAnnotateConfig
247
from bzrlib.bzrdir import BzrDir
249
wt, br, path = BzrDir.open_containing_tree_or_branch(filename)
253
tree = br.basis_tree()
255
file_id = tree.path2id(path)
258
raise NotVersionedError(filename)
259
if revision is not None:
260
if len(revision) != 1:
261
raise BzrCommandError("Only 1 revion may be specified.")
262
revision_id = revision[0].as_revision_id(br)
263
tree = br.repository.revision_tree(revision_id)
265
revision_id = getattr(tree, 'get_revision_id', lambda: None)()
267
window = GAnnotateWindow(all, plain, branch=br)
268
window.connect("destroy", lambda w: Gtk.main_quit())
269
config = GAnnotateConfig(window)
275
window.annotate(tree, br, file_id)
276
window.jump_to_line(line)
285
class cmd_gcommit(GTKCommand):
286
"""GTK+ commit dialog
288
Graphical user interface for committing revisions"""
294
def run(self, filename=None):
296
from commit import CommitDialog
301
(wt, path) = workingtree.WorkingTree.open_containing(filename)
303
except NoWorkingTree, e:
304
from dialog import error_dialog
305
error_dialog(_i18n('Directory does not have a working tree'),
306
_i18n('Operation aborted.'))
307
return 1 # should this be retval=3?
309
# It is a good habit to keep things locked for the duration, but it
310
# could cause difficulties if someone wants to do things in another
311
# window... We could lock_read() until we actually go to commit
312
# changes... Just a thought.
315
dlg = CommitDialog(wt)
321
class cmd_gstatus(GTKCommand):
322
"""GTK+ status dialog
324
Graphical user interface for showing status
328
takes_args = ['PATH?']
329
takes_options = ['revision']
331
def run(self, path='.', revision=None):
333
from bzrlib.plugins.gtk.status import StatusWindow
334
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
336
if revision is not None:
338
revision_id = revision[0].as_revision_id(wt.branch)
340
from bzrlib.errors import BzrError
341
raise BzrError('Revision %r doesn\'t exist'
342
% revision[0].user_spec )
346
status = StatusWindow(wt, wt_path, revision_id)
347
status.connect("destroy", Gtk.main_quit)
352
class cmd_gsend(GTKCommand):
353
"""GTK+ send merge directive.
357
(br, path) = branch.Branch.open_containing(".")
359
from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
360
from StringIO import StringIO
361
dialog = SendMergeDirectiveDialog(br)
362
if dialog.run() == Gtk.ResponseType.OK:
364
outf.writelines(dialog.get_merge_directive().to_lines())
365
mail_client = br.get_config().get_mail_client()
366
mail_client.compose_merge_request(dialog.get_mail_to(), "[MERGE]",
372
class cmd_gconflicts(GTKCommand):
375
Select files from the list of conflicts and run an external utility to
379
(wt, path) = workingtree.WorkingTree.open_containing('.')
381
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
382
dialog = ConflictsDialog(wt)
386
class cmd_gpreferences(GTKCommand):
387
""" GTK+ preferences dialog.
392
from bzrlib.plugins.gtk.preferences import PreferencesWindow
393
dialog = PreferencesWindow()
397
class cmd_gmerge(Command):
398
""" GTK+ merge dialog
401
takes_args = ["merge_from_path?"]
402
def run(self, merge_from_path=None):
403
from bzrlib.plugins.gtk.dialog import error_dialog
404
from bzrlib.plugins.gtk.merge import MergeDialog
406
(wt, path) = workingtree.WorkingTree.open_containing('.')
407
old_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
408
delta = wt.changes_from(old_tree)
409
if len(delta.added) or len(delta.removed) or len(delta.renamed) or len(delta.modified):
410
error_dialog(_i18n('There are local changes in the branch'),
411
_i18n('Please commit or revert the changes before merging.'))
413
parent_branch_path = wt.branch.get_parent()
414
merge = MergeDialog(wt, path, parent_branch_path)
415
response = merge.run()
419
class cmd_gmissing(Command):
420
""" GTK+ missing revisions dialog.
423
takes_args = ["other_branch?"]
424
def run(self, other_branch=None):
426
from gi.repository import Gtk
427
except RuntimeError, e:
428
if str(e) == "could not open display":
431
from bzrlib.plugins.gtk.missing import MissingWindow
432
from bzrlib.branch import Branch
434
local_branch = Branch.open_containing(".")[0]
435
if other_branch is None:
436
other_branch = local_branch.get_parent()
438
if other_branch is None:
439
raise BzrCommandError("No peer location known or specified.")
440
remote_branch = Branch.open_containing(other_branch)[0]
442
local_branch.lock_read()
444
remote_branch.lock_read()
446
dialog = MissingWindow(local_branch, remote_branch)
449
remote_branch.unlock()
451
local_branch.unlock()
454
class cmd_ginit(GTKCommand):
457
Graphical user interface for initializing new branches.
462
from initialize import InitDialog
463
dialog = InitDialog(os.path.abspath(os.path.curdir))
467
class cmd_gtags(GTKCommand):
470
Graphical user interface to view, create, or remove tags.
474
br = branch.Branch.open_containing('.')[0]
477
from tags import TagsWindow
478
window = TagsWindow(br)