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 one or several branches.
167
Opens a graphical window to allow you to see branches history and
168
relationships between revisions in a visual manner,
170
If no revision is specified, the branch last revision is taken as a
171
starting point. When a revision is specified, the presented graph starts
172
with it (as a side effect, when a shared repository is used, any revision
173
can be used even if it's not part of the branch history).
177
Option('limit', "Maximum number of revisions to display.",
179
takes_args = [ "locations*" ]
180
aliases = [ "visualize", "vis", "viz" ]
182
def run(self, locations_list, revision=None, limit=None):
184
if locations_list is None:
185
locations_list = ["."]
187
for location in locations_list:
188
(br, path) = branch.Branch.open_containing(location)
190
revids.append(br.last_revision())
192
revids.append(revision[0].as_revision_id(br))
194
pp = start_viz_window(br, revids, limit)
195
pp.connect("destroy", lambda w: gtk.main_quit())
200
class cmd_gannotate(GTKCommand):
203
Browse changes to FILENAME line by line in a GTK+ window.
205
Within the annotate window, you can use Ctrl-F to search for text, and
206
Ctrl-G to jump to a line by number.
209
takes_args = ["filename", "line?"]
211
Option("all", help="Show annotations on all lines."),
212
Option("plain", help="Don't highlight annotation lines."),
213
Option("line", type=int, argname="lineno",
214
help="Jump to specified line number."),
217
aliases = ["gblame", "gpraise"]
219
def run(self, filename, all=False, plain=False, line='1', revision=None):
225
raise BzrCommandError('Line argument ("%s") is not a number.' %
228
from annotate.gannotate import GAnnotateWindow
229
from annotate.config import GAnnotateConfig
230
from bzrlib.bzrdir import BzrDir
232
wt, br, path = BzrDir.open_containing_tree_or_branch(filename)
236
tree = br.basis_tree()
238
file_id = tree.path2id(path)
241
raise NotVersionedError(filename)
242
if revision is not None:
243
if len(revision) != 1:
244
raise BzrCommandError("Only 1 revion may be specified.")
245
revision_id = revision[0].as_revision_id(br)
246
tree = br.repository.revision_tree(revision_id)
248
revision_id = getattr(tree, 'get_revision_id', lambda: None)()
250
window = GAnnotateWindow(all, plain, branch=br)
251
window.connect("destroy", lambda w: gtk.main_quit())
252
config = GAnnotateConfig(window)
258
window.annotate(tree, br, file_id)
259
window.jump_to_line(line)
268
class cmd_gcommit(GTKCommand):
269
"""GTK+ commit dialog
271
Graphical user interface for committing revisions"""
277
def run(self, filename=None):
279
from commit import CommitDialog
284
(wt, path) = workingtree.WorkingTree.open_containing(filename)
286
except NoWorkingTree, e:
287
from dialog import error_dialog
288
error_dialog(_i18n('Directory does not have a working tree'),
289
_i18n('Operation aborted.'))
290
return 1 # should this be retval=3?
292
# It is a good habit to keep things locked for the duration, but it
293
# could cause difficulties if someone wants to do things in another
294
# window... We could lock_read() until we actually go to commit
295
# changes... Just a thought.
298
dlg = CommitDialog(wt)
304
class cmd_gstatus(GTKCommand):
305
"""GTK+ status dialog
307
Graphical user interface for showing status
311
takes_args = ['PATH?']
312
takes_options = ['revision']
314
def run(self, path='.', revision=None):
316
from bzrlib.plugins.gtk.status import StatusWindow
317
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
319
if revision is not None:
321
revision_id = revision[0].as_revision_id(wt.branch)
323
from bzrlib.errors import BzrError
324
raise BzrError('Revision %r doesn\'t exist'
325
% revision[0].user_spec )
329
status = StatusWindow(wt, wt_path, revision_id)
330
status.connect("destroy", gtk.main_quit)
335
class cmd_gsend(GTKCommand):
336
"""GTK+ send merge directive.
340
(br, path) = branch.Branch.open_containing(".")
342
from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
343
from StringIO import StringIO
344
dialog = SendMergeDirectiveDialog(br)
345
if dialog.run() == gtk.RESPONSE_OK:
347
outf.writelines(dialog.get_merge_directive().to_lines())
348
mail_client = br.get_config().get_mail_client()
349
mail_client.compose_merge_request(dialog.get_mail_to(), "[MERGE]",
355
class cmd_gconflicts(GTKCommand):
358
Select files from the list of conflicts and run an external utility to
362
(wt, path) = workingtree.WorkingTree.open_containing('.')
364
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
365
dialog = ConflictsDialog(wt)
369
class cmd_gpreferences(GTKCommand):
370
""" GTK+ preferences dialog.
375
from bzrlib.plugins.gtk.preferences import PreferencesWindow
376
dialog = PreferencesWindow()
380
class cmd_gmerge(Command):
381
""" GTK+ merge dialog
384
takes_args = ["merge_from_path?"]
385
def run(self, merge_from_path=None):
386
from bzrlib.plugins.gtk.dialog import error_dialog
387
from bzrlib.plugins.gtk.merge import MergeDialog
389
(wt, path) = workingtree.WorkingTree.open_containing('.')
390
old_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
391
delta = wt.changes_from(old_tree)
392
if len(delta.added) or len(delta.removed) or len(delta.renamed) or len(delta.modified):
393
error_dialog(_i18n('There are local changes in the branch'),
394
_i18n('Please commit or revert the changes before merging.'))
396
parent_branch_path = wt.branch.get_parent()
397
merge = MergeDialog(wt, path, parent_branch_path)
398
response = merge.run()
402
class cmd_gmissing(Command):
403
""" GTK+ missing revisions dialog.
406
takes_args = ["other_branch?"]
407
def run(self, other_branch=None):
408
pygtk = import_pygtk()
411
except RuntimeError, e:
412
if str(e) == "could not open display":
415
from bzrlib.plugins.gtk.missing import MissingWindow
416
from bzrlib.branch import Branch
418
local_branch = Branch.open_containing(".")[0]
419
if other_branch is None:
420
other_branch = local_branch.get_parent()
422
if other_branch is None:
423
raise BzrCommandError("No peer location known or specified.")
424
remote_branch = Branch.open_containing(other_branch)[0]
426
local_branch.lock_read()
428
remote_branch.lock_read()
430
dialog = MissingWindow(local_branch, remote_branch)
433
remote_branch.unlock()
435
local_branch.unlock()
438
class cmd_ginit(GTKCommand):
441
Graphical user interface for initializing new branches.
446
from initialize import InitDialog
447
dialog = InitDialog(os.path.abspath(os.path.curdir))
451
class cmd_gtags(GTKCommand):
454
Graphical user interface to view, create, or remove tags.
458
br = branch.Branch.open_containing('.')[0]
461
from tags import TagsWindow
462
window = TagsWindow(br)