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 """
17
from bzrlib.commands import Command, register_command, display_command
18
from bzrlib.errors import NotVersionedError, BzrCommandError, NoSuchFile
19
from bzrlib.commands import Command, register_command
20
from bzrlib.option import Option
21
from bzrlib.branch import Branch
22
from bzrlib.workingtree import WorkingTree
23
from bzrlib.bzrdir import BzrDir
25
__version__ = '0.12.0'
27
class cmd_gbranch(Command):
37
except RuntimeError, e:
38
if str(e) == "could not open display":
41
from bzrlib.plugins.gtk.olive.branch import BranchDialog
43
window = BranchDialog('.')
46
register_command(cmd_gbranch)
48
class cmd_gdiff(Command):
49
"""Show differences in working tree in a GTK+ Window.
51
Otherwise, all changes for the tree are listed.
53
takes_args = ['filename?']
54
takes_options = ['revision']
57
def run(self, revision=None, filename=None):
58
wt = WorkingTree.open_containing(".")[0]
60
if revision is not None:
61
if len(revision) == 1:
63
revision_id = revision[0].in_history(branch).rev_id
64
tree2 = branch.repository.revision_tree(revision_id)
65
elif len(revision) == 2:
66
revision_id_0 = revision[0].in_history(branch).rev_id
67
tree2 = branch.repository.revision_tree(revision_id_0)
68
revision_id_1 = revision[1].in_history(branch).rev_id
69
tree1 = branch.repository.revision_tree(revision_id_1)
72
tree2 = tree1.basis_tree()
74
from viz.diffwin import DiffWindow
77
window.connect("destroy", lambda w: gtk.main_quit())
78
window.set_diff("Working Tree", tree1, tree2)
79
if filename is not None:
80
tree_filename = tree1.relpath(filename)
82
window.set_file(tree_filename)
84
if (tree1.inventory.path2id(tree_filename) is None and
85
tree2.inventory.path2id(tree_filename) is None):
86
raise NotVersionedError(filename)
87
raise BzrCommandError('No changes found for file "%s"' %
93
register_command(cmd_gdiff)
95
class cmd_visualise(Command):
96
"""Graphically visualise this branch.
98
Opens a graphical window to allow you to see the history of the branch
99
and relationships between revisions in a visual manner,
101
The default starting point is latest revision on the branch, you can
102
specify a starting point with -r revision.
106
Option('limit', "maximum number of revisions to display",
108
takes_args = [ "location?" ]
109
aliases = [ "visualize", "vis", "viz" ]
111
def run(self, location=".", revision=None, limit=None):
112
(branch, path) = Branch.open_containing(location)
114
branch.repository.lock_read()
117
revid = branch.last_revision()
121
(revno, revid) = revision[0].in_history(branch)
123
from viz.bzrkapp import BzrkApp
126
app.show(branch, revid, limit)
128
branch.repository.unlock()
133
register_command(cmd_visualise)
135
class cmd_gannotate(Command):
138
Browse changes to FILENAME line by line in a GTK+ window.
141
takes_args = ["filename", "line?"]
143
Option("all", help="show annotations on all lines"),
144
Option("plain", help="don't highlight annotation lines"),
145
Option("line", type=int, argname="lineno",
146
help="jump to specified line number"),
149
aliases = ["gblame", "gpraise"]
151
def run(self, filename, all=False, plain=False, line='1', revision=None):
157
except RuntimeError, e:
158
if str(e) == "could not open display":
164
raise BzrCommandError('Line argument ("%s") is not a number.' %
167
from annotate.gannotate import GAnnotateWindow
168
from annotate.config import GAnnotateConfig
170
(wt, path) = WorkingTree.open_containing(filename)
173
file_id = wt.path2id(path)
176
raise NotVersionedError(filename)
177
if revision is not None:
178
if len(revision) != 1:
179
raise BzrCommandError("Only 1 revion may be specified.")
180
revision_id = revision[0].in_history(branch).rev_id
184
window = GAnnotateWindow(all, plain)
185
window.connect("destroy", lambda w: gtk.main_quit())
186
window.set_title(path + " - gannotate")
187
config = GAnnotateConfig(window)
191
window.annotate(branch, file_id, revision_id)
194
window.jump_to_line(line)
198
register_command(cmd_gannotate)
200
class cmd_gcommit(Command):
201
"""GTK+ commit dialog
203
Graphical user interface for committing revisions"""
208
def run(self, filename=None):
215
except RuntimeError, e:
216
if str(e) == "could not open display":
219
from olive.commit import CommitDialog
220
from bzrlib.commit import Commit
221
from bzrlib.errors import (BzrCommandError,
231
(wt, path) = WorkingTree.open_containing(filename)
233
except NotBranchError, e:
235
except NoWorkingTree, e:
238
(branch, path) = Branch.open_containing(path)
239
except NotBranchError, e:
242
dialog = CommitDialog(wt, path, not branch)
244
dialog.window.connect("destroy", lambda w: gtk.main_quit())
247
register_command(cmd_gcommit)
249
class NoDisplayError(BzrCommandError):
250
"""gtk could not find a proper display"""
253
return "No DISPLAY. gannotate is disabled."