1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
import bzrlib.errors as errors
29
from bzrlib import osutils
31
from dialog import error_dialog, question_dialog
32
from guifiles import GLADEFILENAME
36
""" Display Commit dialog and perform the needed actions. """
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
50
# Get some important widgets
51
self.window = self.glade.get_widget('window_commit')
52
self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
53
self.textview = self.glade.get_widget('textview_commit')
54
self.file_expander = self.glade.get_widget('expander_commit_select')
55
self.file_view = self.glade.get_widget('treeview_commit_select')
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:
64
self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
65
self.delta = self.wt.changes_from(self.old_tree)
68
self.pending = self._pending_merges(self.wt)
70
# Dictionary for signal_autoconnect
71
dic = { "on_button_commit_commit_clicked": self.commit,
72
"on_button_commit_cancel_clicked": self.close }
74
# Connect the signals to the handlers
75
self.glade.signal_autoconnect(dic)
77
# Create the file list
78
self._create_file_view()
79
# Create the pending merges
80
self._create_pending_merges()
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
error_dialog(_('Directory is not a branch'),
93
_('You can perform this action only in a branch.'))
97
if self.wt.branch.get_bound_location() is not None:
98
# we have a checkout, so the local commit checkbox must appear
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()
109
self.textview.modify_font(pango.FontDescription("Monospace"))
113
# Gives the focus to the commit message area
114
self.textview.grab_focus()
117
def _create_file_view(self):
118
self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN, # [0] checkbox
119
gobject.TYPE_STRING, # [1] path to display
120
gobject.TYPE_STRING, # [2] changes type
121
gobject.TYPE_STRING) # [3] real path
122
self.file_view.set_model(self.file_store)
123
crt = gtk.CellRendererToggle()
124
crt.set_property("activatable", True)
125
crt.connect("toggled", self._toggle_commit, self.file_store)
126
self.file_view.append_column(gtk.TreeViewColumn(_('Commit'),
128
self.file_view.append_column(gtk.TreeViewColumn(_('Path'),
129
gtk.CellRendererText(), text=1))
130
self.file_view.append_column(gtk.TreeViewColumn(_('Type'),
131
gtk.CellRendererText(), text=2))
133
for path, id, kind in self.delta.added:
134
marker = osutils.kind_marker(kind)
135
self.file_store.append([ True, path+marker, _('added'), path ])
137
for path, id, kind in self.delta.removed:
138
marker = osutils.kind_marker(kind)
139
self.file_store.append([ True, path+marker, _('removed'), path ])
141
for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
142
marker = osutils.kind_marker(kind)
143
if text_modified or meta_modified:
144
changes = _('renamed and modified')
146
changes = _('renamed')
147
self.file_store.append([ True,
148
oldpath+marker + ' => ' + newpath+marker,
153
for path, id, kind, text_modified, meta_modified in self.delta.modified:
154
marker = osutils.kind_marker(kind)
155
self.file_store.append([ True, path+marker, _('modified'), path ])
157
def _create_pending_merges(self):
158
liststore = gtk.ListStore(gobject.TYPE_STRING,
161
self.pending_view.set_model(liststore)
163
self.pending_view.append_column(gtk.TreeViewColumn(_('Date'),
164
gtk.CellRendererText(), text=0))
165
self.pending_view.append_column(gtk.TreeViewColumn(_('Committer'),
166
gtk.CellRendererText(), text=1))
167
self.pending_view.append_column(gtk.TreeViewColumn(_('Summary'),
168
gtk.CellRendererText(), text=2))
173
for item in self.pending:
174
liststore.append([ item['date'],
178
def _get_specific_files(self):
180
it = self.file_store.get_iter_first()
182
if self.file_store.get_value(it, 0):
183
# get real path from hidden column 3
184
ret.append(self.file_store.get_value(it, 3))
185
it = self.file_store.iter_next(it)
189
def _toggle_commit(self, cell, path, model):
190
model[path][0] = not model[path][0]
193
def _pending_merges(self, wt):
194
""" Return a list of pending merges or None if there are none of them. """
195
parents = wt.get_parent_ids()
200
from bzrlib.osutils import format_date
202
pending = parents[1:]
204
last_revision = parents[0]
206
if last_revision is not None:
208
ignore = set(branch.repository.get_ancestry(last_revision))
209
except errors.NoSuchRevision:
210
# the last revision is a ghost : assume everything is new
212
ignore = set([None, last_revision])
217
for merge in pending:
220
m_revision = branch.repository.get_revision(merge)
223
rev['committer'] = re.sub('<.*@.*>', '', m_revision.committer).strip(' ')
224
rev['summary'] = m_revision.get_summary()
225
rev['date'] = format_date(m_revision.timestamp,
226
m_revision.timezone or 0,
227
'original', date_fmt="%Y-%m-%d",
232
inner_merges = branch.repository.get_ancestry(merge)
233
assert inner_merges[0] is None
235
inner_merges.reverse()
236
for mmerge in inner_merges:
239
mm_revision = branch.repository.get_revision(mmerge)
242
rev['committer'] = re.sub('<.*@.*>', '', mm_revision.committer).strip(' ')
243
rev['summary'] = mm_revision.get_summary()
244
rev['date'] = format_date(mm_revision.timestamp,
245
mm_revision.timezone or 0,
246
'original', date_fmt="%Y-%m-%d",
252
except errors.NoSuchRevision:
253
print "DEBUG: NoSuchRevision:", merge
257
def commit(self, widget):
258
textbuffer = self.textview.get_buffer()
259
start, end = textbuffer.get_bounds()
260
message = textbuffer.get_text(start, end).decode('utf-8')
262
checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
263
checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
266
specific_files = self._get_specific_files()
268
specific_files = None
271
response = question_dialog('Commit with an empty message ?',
272
'You can describe your commit intent'
274
if response == gtk.RESPONSE_NO:
275
# Kindly give focus to message area
276
self.textview.grab_focus()
280
self.wt.commit(message,
281
allow_pointless=checkbutton_force.get_active(),
282
strict=checkbutton_strict.get_active(),
283
local=self.checkbutton_local.get_active(),
284
specific_files=specific_files)
285
except errors.NotBranchError:
286
error_dialog(_('Directory is not a branch'),
287
_('You can perform this action only in a branch.'))
289
except errors.LocalRequiresBoundBranch:
290
error_dialog(_('Directory is not a checkout'),
291
_('You can perform local commit only on checkouts.'))
293
except errors.PointlessCommit:
294
error_dialog(_('No changes to commit'),
295
_('Try force commit if you want to commit anyway.'))
297
except errors.ConflictsInTree:
298
error_dialog(_('Conflicts in tree'),
299
_('You need to resolve the conflicts before committing.'))
301
except errors.StrictCommitFailed:
302
error_dialog(_('Strict commit failed'),
303
_('There are unknown files in the working tree.\nPlease add or delete them.'))
305
except errors.BoundBranchOutOfDate, errmsg:
306
error_dialog(_('Bound branch is out of date'),
309
except errors.BzrError, msg:
310
error_dialog(_('Unknown bzr error'), str(msg))
312
except Exception, msg:
313
error_dialog(_('Unknown error'), str(msg))
318
def close(self, widget=None):
319
self.window.destroy()