14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
19
pygtk.require("2.0")
32
from bzrlib import version_info
34
28
import bzrlib.errors as errors
35
from bzrlib.workingtree import WorkingTree
29
from bzrlib import osutils
31
from dialog import error_dialog, question_dialog
32
from guifiles import GLADEFILENAME
38
36
""" Display Commit dialog and perform the needed actions. """
39
def __init__(self, gladefile, comm, dialog):
40
""" Initialize the Commit dialog. """
41
self.gladefile = gladefile
42
self.glade = gtk.glade.XML(self.gladefile, 'window_commit', 'olive-gtk')
44
# Communication object
37
def __init__(self, wt, wtpath, notbranch):
38
""" Initialize the Commit dialog.
39
:param wt: bzr working tree object
40
:param wtpath: path to working tree root
41
:param notbranch: flag that path is not a brach
44
self.glade = gtk.glade.XML(GLADEFILENAME, 'window_commit', 'olive-gtk')
48
self.notbranch = notbranch
49
50
# Get some important widgets
50
51
self.window = self.glade.get_widget('window_commit')
51
52
self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
52
53
self.textview = self.glade.get_widget('textview_commit')
54
self.file_expander = self.glade.get_widget('expander_commit_select')
53
55
self.file_view = self.glade.get_widget('treeview_commit_select')
55
# Check if current location is a branch
57
(self.wt, path) = WorkingTree.open_containing(self.comm.get_path())
58
branch = self.wt.branch
59
except errors.NotBranchError:
65
file_id = self.wt.path2id(path)
67
self.notbranch = False
56
self.pending_expander = self.glade.get_widget('expander_commit_pending')
57
self.pending_label = self.glade.get_widget('label_commit_pending')
58
self.pending_view = self.glade.get_widget('treeview_commit_pending')
60
if wt is None or notbranch:
73
64
self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
74
if version_info < (0, 9):
75
self.delta = compare_trees(self.old_tree, self.wt)
77
self.delta = self.wt.changes_from(self.old_tree)
65
self.delta = self.wt.changes_from(self.old_tree)
68
self.pending = self._pending_merges(self.wt)
79
70
# Dictionary for signal_autoconnect
80
71
dic = { "on_button_commit_commit_clicked": self.commit,
81
72
"on_button_commit_cancel_clicked": self.close }
83
74
# Connect the signals to the handlers
84
75
self.glade.signal_autoconnect(dic)
86
77
# Create the file list
87
78
self._create_file_view()
79
# Create the pending merges
80
self._create_pending_merges()
90
""" Display the Push dialog. """
83
""" Display the Push dialog.
84
@return: True if dialog is shown.
86
if self.wt is None and not self.notbranch:
87
error_dialog(_('Directory does not have a working tree'),
88
_('Operation aborted.'))
92
self.dialog.error_dialog(_('Directory is not a branch'),
93
_('You can perform this action only in a branch.'))
92
error_dialog(_('Directory is not a branch'),
93
_('You can perform this action only in a branch.'))
96
from bzrlib.branch import Branch
97
branch = Branch.open_containing(self.comm.get_path())[0]
99
if branch.get_bound_location() is not None:
97
if self.wt.branch.get_bound_location() is not None:
100
98
# we have a checkout, so the local commit checkbox must appear
101
99
self.checkbutton_local.show()
102
# There are pending merges, file selection not supported
103
self.file_expander.set_expanded(False)
104
self.file_view.set_sensitive(False)
107
self.pending_expander.hide()
103
109
self.textview.modify_font(pango.FontDescription("Monospace"))
104
110
self.window.show()
107
# This code is from Jelmer Vernooij's bzr-gtk branch
108
113
def _create_file_view(self):
109
self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,
114
self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN, # [0] checkbox
115
gobject.TYPE_STRING, # [1] path to display
116
gobject.TYPE_STRING, # [2] changes type
117
gobject.TYPE_STRING) # [3] real path
112
118
self.file_view.set_model(self.file_store)
113
119
crt = gtk.CellRendererToggle()
114
120
crt.set_property("activatable", True)
121
127
gtk.CellRendererText(), text=2))
123
129
for path, id, kind in self.delta.added:
124
self.file_store.append([ True, path, _('added') ])
130
marker = osutils.kind_marker(kind)
131
self.file_store.append([ True, path+marker, _('added'), path ])
126
133
for path, id, kind in self.delta.removed:
127
self.file_store.append([ True, path, _('removed') ])
134
marker = osutils.kind_marker(kind)
135
self.file_store.append([ True, path+marker, _('removed'), path ])
129
137
for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
130
self.file_store.append([ True, oldpath, _('renamed') ])
138
marker = osutils.kind_marker(kind)
139
if text_modified or meta_modified:
140
changes = _('renamed and modified')
142
changes = _('renamed')
143
self.file_store.append([ True,
144
oldpath+marker + ' => ' + newpath+marker,
132
149
for path, id, kind, text_modified, meta_modified in self.delta.modified:
133
self.file_store.append([ True, path, _('modified') ])
150
marker = osutils.kind_marker(kind)
151
self.file_store.append([ True, path+marker, _('modified'), path ])
153
def _create_pending_merges(self):
155
# hide unused pending merge part
156
scrolled_window = self.glade.get_widget('scrolledwindow_commit_pending')
157
parent = scrolled_window.get_parent()
158
parent.remove(scrolled_window)
159
parent = self.pending_label.get_parent()
160
parent.remove(self.pending_label)
163
liststore = gtk.ListStore(gobject.TYPE_STRING,
166
self.pending_view.set_model(liststore)
168
self.pending_view.append_column(gtk.TreeViewColumn(_('Date'),
169
gtk.CellRendererText(), text=0))
170
self.pending_view.append_column(gtk.TreeViewColumn(_('Committer'),
171
gtk.CellRendererText(), text=1))
172
self.pending_view.append_column(gtk.TreeViewColumn(_('Summary'),
173
gtk.CellRendererText(), text=2))
175
for item in self.pending:
176
liststore.append([ item['date'],
135
180
def _get_specific_files(self):
137
182
it = self.file_store.get_iter_first()
139
184
if self.file_store.get_value(it, 0):
140
ret.append(self.file_store.get_value(it, 1))
185
# get real path from hidden column 3
186
ret.append(self.file_store.get_value(it, 3))
141
187
it = self.file_store.iter_next(it)
144
# end of bzr-gtk code
146
191
def _toggle_commit(self, cell, path, model):
147
192
model[path][0] = not model[path][0]
195
def _pending_merges(self, wt):
196
""" Return a list of pending merges or None if there are none of them. """
197
parents = wt.get_parent_ids()
202
from bzrlib.osutils import format_date
204
pending = parents[1:]
206
last_revision = parents[0]
208
if last_revision is not None:
210
ignore = set(branch.repository.get_ancestry(last_revision))
211
except errors.NoSuchRevision:
212
# the last revision is a ghost : assume everything is new
214
ignore = set([None, last_revision])
219
for merge in pending:
222
m_revision = branch.repository.get_revision(merge)
225
rev['committer'] = re.sub('<.*@.*>', '', m_revision.committer).strip(' ')
226
rev['summary'] = m_revision.get_summary()
227
rev['date'] = format_date(m_revision.timestamp,
228
m_revision.timezone or 0,
229
'original', date_fmt="%Y-%m-%d",
234
inner_merges = branch.repository.get_ancestry(merge)
235
assert inner_merges[0] is None
237
inner_merges.reverse()
238
for mmerge in inner_merges:
241
mm_revision = branch.repository.get_revision(mmerge)
244
rev['committer'] = re.sub('<.*@.*>', '', mm_revision.committer).strip(' ')
245
rev['summary'] = mm_revision.get_summary()
246
rev['date'] = format_date(mm_revision.timestamp,
247
mm_revision.timezone or 0,
248
'original', date_fmt="%Y-%m-%d",
254
except errors.NoSuchRevision:
255
print "DEBUG: NoSuchRevision:", merge
150
259
def commit(self, widget):
151
260
textbuffer = self.textview.get_buffer()
152
261
start, end = textbuffer.get_bounds()
153
message = textbuffer.get_text(start, end)
262
message = textbuffer.get_text(start, end).decode('utf-8')
155
264
checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
156
265
checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
158
specific_files = self._get_specific_files()
160
self.comm.set_busy(self.window)
161
# merged from Jelmer Vernooij's olive integration branch
268
specific_files = self._get_specific_files()
270
specific_files = None
273
response = question_dialog('Commit with an empty message ?',
274
'You can describe your commit intent'
276
if response == gtk.RESPONSE_NO:
277
# Kindly give focus to message area
278
self.textview.grab_focus()
163
self.wt.commit(message,
282
self.wt.commit(message,
164
283
allow_pointless=checkbutton_force.get_active(),
165
284
strict=checkbutton_strict.get_active(),
166
285
local=self.checkbutton_local.get_active(),
167
286
specific_files=specific_files)
168
287
except errors.NotBranchError:
169
self.dialog.error_dialog(_('Directory is not a branch'),
170
_('You can perform this action only in a branch.'))
171
self.comm.set_busy(self.window, False)
288
error_dialog(_('Directory is not a branch'),
289
_('You can perform this action only in a branch.'))
173
291
except errors.LocalRequiresBoundBranch:
174
self.dialog.error_dialog(_('Directory is not a checkout'),
175
_('You can perform local commit only on checkouts.'))
176
self.comm.set_busy(self.window, False)
292
error_dialog(_('Directory is not a checkout'),
293
_('You can perform local commit only on checkouts.'))
178
295
except errors.PointlessCommit:
179
self.dialog.error_dialog(_('No changes to commit'),
180
_('Try force commit if you want to commit anyway.'))
181
self.comm.set_busy(self.window, False)
296
error_dialog(_('No changes to commit'),
297
_('Try force commit if you want to commit anyway.'))
183
299
except errors.ConflictsInTree:
184
self.dialog.error_dialog(_('Conflicts in tree'),
185
_('You need to resolve the conflicts before committing.'))
186
self.comm.set_busy(self.window, False)
300
error_dialog(_('Conflicts in tree'),
301
_('You need to resolve the conflicts before committing.'))
188
303
except errors.StrictCommitFailed:
189
self.dialog.error_dialog(_('Strict commit failed'),
190
_('There are unknown files in the working tree.\nPlease add or delete them.'))
191
self.comm.set_busy(self.window, False)
304
error_dialog(_('Strict commit failed'),
305
_('There are unknown files in the working tree.\nPlease add or delete them.'))
193
307
except errors.BoundBranchOutOfDate, errmsg:
194
self.dialog.error_dialog(_('Bound branch is out of date'),
196
self.comm.set_busy(self.window, False)
308
error_dialog(_('Bound branch is out of date'),
311
except errors.BzrError, msg:
312
error_dialog(_('Unknown bzr error'), str(msg))
314
except Exception, msg:
315
error_dialog(_('Unknown error'), str(msg))
202
self.comm.refresh_right()
204
320
def close(self, widget=None):
205
321
self.window.destroy()