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
15
"""GTK+ frontends to Bazaar commands """
19
__version__ = '0.15.0'
20
version_info = tuple(int(n) for n in __version__.split('.'))
23
def check_bzrlib_version(desired):
24
"""Check that bzrlib is compatible.
26
If version is < bzr-gtk version, assume incompatible.
27
If version == bzr-gtk version, assume completely compatible
28
If version == bzr-gtk version + 1, assume compatible, with deprecations
29
Otherwise, assume incompatible.
31
desired_plus = (desired[0], desired[1]+1)
32
bzrlib_version = bzrlib.version_info[:2]
33
if bzrlib_version == desired:
36
from bzrlib.trace import warning
38
# get the message out any way we can
39
from warnings import warn as warning
40
if bzrlib_version < desired:
41
warning('Installed bzr version %s is too old to be used with bzr-gtk'
42
' %s.' % (bzrlib.__version__, __version__))
43
# Not using BzrNewError, because it may not exist.
44
raise Exception, ('Version mismatch', version_info)
46
warning('bzr-gtk is not up to date with installed bzr version %s.'
47
' \nThere should be a newer version available, e.g. %i.%i.'
48
% (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
49
if bzrlib_version != desired_plus:
50
raise Exception, 'Version mismatch'
53
check_bzrlib_version(version_info[:2])
55
from bzrlib import errors
56
from bzrlib.commands import Command, register_command, display_command
57
from bzrlib.errors import NotVersionedError, BzrCommandError, NoSuchFile
58
from bzrlib.commands import Command, register_command
59
from bzrlib.option import Option
60
from bzrlib.branch import Branch
61
from bzrlib.workingtree import WorkingTree
62
from bzrlib.bzrdir import BzrDir
70
raise errors.BzrCommandError("PyGTK not installed.")
76
pygtk = import_pygtk()
77
from ui import GtkUIFactory
79
bzrlib.ui.ui_factory = GtkUIFactory()
82
class cmd_gbranch(Command):
88
pygtk = import_pygtk()
91
except RuntimeError, e:
92
if str(e) == "could not open display":
95
from bzrlib.plugins.gtk.branch import BranchDialog
98
dialog = BranchDialog(os.path.abspath('.'))
101
register_command(cmd_gbranch)
103
class cmd_gcheckout(Command):
109
pygtk = import_pygtk()
112
except RuntimeError, e:
113
if str(e) == "could not open display":
116
from bzrlib.plugins.gtk.checkout import CheckoutDialog
119
dialog = CheckoutDialog(os.path.abspath('.'))
122
register_command(cmd_gcheckout)
124
class cmd_gpush(Command):
128
takes_args = [ "location?" ]
130
def run(self, location="."):
131
(branch, path) = Branch.open_containing(location)
133
pygtk = import_pygtk()
136
except RuntimeError, e:
137
if str(e) == "could not open display":
140
from push import PushDialog
143
dialog = PushDialog(branch)
146
register_command(cmd_gpush)
148
class cmd_gdiff(Command):
149
"""Show differences in working tree in a GTK+ Window.
151
Otherwise, all changes for the tree are listed.
153
takes_args = ['filename?']
154
takes_options = ['revision']
157
def run(self, revision=None, filename=None):
159
wt = WorkingTree.open_containing(".")[0]
161
if revision is not None:
162
if len(revision) == 1:
164
revision_id = revision[0].in_history(branch).rev_id
165
tree2 = branch.repository.revision_tree(revision_id)
166
elif len(revision) == 2:
167
revision_id_0 = revision[0].in_history(branch).rev_id
168
tree2 = branch.repository.revision_tree(revision_id_0)
169
revision_id_1 = revision[1].in_history(branch).rev_id
170
tree1 = branch.repository.revision_tree(revision_id_1)
173
tree2 = tree1.basis_tree()
175
from viz.diffwin import DiffWindow
177
window = DiffWindow()
178
window.connect("destroy", lambda w: gtk.main_quit())
179
window.set_diff("Working Tree", tree1, tree2)
180
if filename is not None:
181
tree_filename = wt.relpath(filename)
183
window.set_file(tree_filename)
185
if (tree1.inventory.path2id(tree_filename) is None and
186
tree2.inventory.path2id(tree_filename) is None):
187
raise NotVersionedError(filename)
188
raise BzrCommandError('No changes found for file "%s"' %
194
register_command(cmd_gdiff)
196
class cmd_visualise(Command):
197
"""Graphically visualise this branch.
199
Opens a graphical window to allow you to see the history of the branch
200
and relationships between revisions in a visual manner,
202
The default starting point is latest revision on the branch, you can
203
specify a starting point with -r revision.
207
Option('limit', "maximum number of revisions to display",
209
takes_args = [ "location?" ]
210
aliases = [ "visualize", "vis", "viz" ]
212
def run(self, location=".", revision=None, limit=None):
214
(branch, path) = Branch.open_containing(location)
216
branch.repository.lock_read()
219
revid = branch.last_revision()
223
(revno, revid) = revision[0].in_history(branch)
225
from viz.bzrkapp import BzrkApp
228
app.show(branch, revid, limit)
230
branch.repository.unlock()
235
register_command(cmd_visualise)
237
class cmd_gannotate(Command):
240
Browse changes to FILENAME line by line in a GTK+ window.
243
takes_args = ["filename", "line?"]
245
Option("all", help="show annotations on all lines"),
246
Option("plain", help="don't highlight annotation lines"),
247
Option("line", type=int, argname="lineno",
248
help="jump to specified line number"),
251
aliases = ["gblame", "gpraise"]
253
def run(self, filename, all=False, plain=False, line='1', revision=None):
254
pygtk = import_pygtk()
258
except RuntimeError, e:
259
if str(e) == "could not open display":
266
raise BzrCommandError('Line argument ("%s") is not a number.' %
269
from annotate.gannotate import GAnnotateWindow
270
from annotate.config import GAnnotateConfig
273
(tree, path) = WorkingTree.open_containing(filename)
275
except errors.NoWorkingTree:
276
(branch, path) = Branch.open_containing(filename)
277
tree = branch.basis_tree()
279
file_id = tree.path2id(path)
282
raise NotVersionedError(filename)
283
if revision is not None:
284
if len(revision) != 1:
285
raise BzrCommandError("Only 1 revion may be specified.")
286
revision_id = revision[0].in_history(branch).rev_id
287
tree = branch.repository.revision_tree(revision_id)
289
revision_id = getattr(tree, 'get_revision_id', lambda: None)()
291
window = GAnnotateWindow(all, plain)
292
window.connect("destroy", lambda w: gtk.main_quit())
293
window.set_title(path + " - gannotate")
294
config = GAnnotateConfig(window)
298
window.annotate(tree, branch, file_id)
301
window.jump_to_line(line)
305
register_command(cmd_gannotate)
307
class cmd_gcommit(Command):
308
"""GTK+ commit dialog
310
Graphical user interface for committing revisions"""
315
def run(self, filename=None):
317
pygtk = import_pygtk()
321
except RuntimeError, e:
322
if str(e) == "could not open display":
326
from commit import CommitDialog
327
from bzrlib.commit import Commit
328
from bzrlib.errors import (BzrCommandError,
338
(wt, path) = WorkingTree.open_containing(filename)
340
except NotBranchError, e:
342
except NoWorkingTree, e:
345
(branch, path) = Branch.open_containing(path)
346
except NotBranchError, e:
350
commit = CommitDialog(wt, path, not branch)
353
register_command(cmd_gcommit)
355
class NoDisplayError(BzrCommandError):
356
"""gtk could not find a proper display"""
359
return "No DISPLAY. Unable to run GTK+ application."
362
from unittest import TestSuite
365
result.addTest(tests.test_suite())