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
37
31
from dialog import error_dialog
32
from guifiles import GLADEFILENAME
40
36
""" Display Commit dialog and perform the needed actions. """
41
def __init__(self, gladefile, wt, wtpath):
42
""" Initialize the Commit dialog. """
43
self.gladefile = gladefile
44
self.glade = gtk.glade.XML(self.gladefile, 'window_commit', 'olive-gtk')
37
def __init__(self, wt, wtpath, standalone=False):
38
""" Initialize the Commit dialog.
39
@param wt: bzr working tree object
40
@param wtpath: path to working tree root
41
@param standalone: when used in gcommit command as standalone window
42
this argument should be True
44
self.glade = gtk.glade.XML(GLADEFILENAME, 'window_commit', 'olive-gtk')
47
47
self.wtpath = wtpath
49
self.standalone = standalone
49
51
# Get some important widgets
50
52
self.window = self.glade.get_widget('window_commit')
51
53
self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
52
54
self.textview = self.glade.get_widget('textview_commit')
53
55
self.file_view = self.glade.get_widget('treeview_commit_select')
56
self.pending_label = self.glade.get_widget('label_commit_pending')
57
self.pending_view = self.glade.get_widget('treeview_commit_pending')
55
59
file_id = self.wt.path2id(wtpath)
63
67
self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
64
if version_info < (0, 9):
65
self.delta = compare_trees(self.old_tree, self.wt)
67
self.delta = self.wt.changes_from(self.old_tree)
68
self.delta = self.wt.changes_from(self.old_tree)
71
self.pending = self._pending_merges(self.wt)
69
73
# Dictionary for signal_autoconnect
70
74
dic = { "on_button_commit_commit_clicked": self.commit,
71
75
"on_button_commit_cancel_clicked": self.close }
78
dic["on_button_commit_cancel_clicked"] = self.quit
79
self.window.connect("delete_event", gtk.main_quit)
73
81
# Connect the signals to the handlers
74
82
self.glade.signal_autoconnect(dic)
76
84
# Create the file list
77
85
self._create_file_view()
86
# Create the pending merges
87
self._create_pending_merges()
80
90
""" Display the Push dialog. """
82
92
error_dialog(_('Directory is not a branch'),
83
_('You can perform this action only in a branch.'))
93
_('You can perform this action only in a branch.'))
86
96
if self.wt.branch.get_bound_location() is not None:
87
97
# we have a checkout, so the local commit checkbox must appear
88
98
self.checkbutton_local.show()
101
# There are pending merges, file selection not supported
102
self.file_view.set_sensitive(False)
105
self.pending_view.set_sensitive(False)
90
107
self.textview.modify_font(pango.FontDescription("Monospace"))
91
108
self.window.show()
94
111
def _create_file_view(self):
95
self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,
112
self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN, # [0] checkbox
113
gobject.TYPE_STRING, # [1] path to display
114
gobject.TYPE_STRING, # [2] changes type
115
gobject.TYPE_STRING) # [3] real path
98
116
self.file_view.set_model(self.file_store)
99
117
crt = gtk.CellRendererToggle()
100
118
crt.set_property("activatable", True)
107
125
gtk.CellRendererText(), text=2))
109
127
for path, id, kind in self.delta.added:
110
self.file_store.append([ True, path, _('added') ])
128
marker = osutils.kind_marker(kind)
129
self.file_store.append([ True, path+marker, _('added'), path ])
112
131
for path, id, kind in self.delta.removed:
113
self.file_store.append([ True, path, _('removed') ])
132
marker = osutils.kind_marker(kind)
133
self.file_store.append([ True, path+marker, _('removed'), path ])
115
135
for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
116
self.file_store.append([ True, oldpath, _('renamed') ])
136
marker = osutils.kind_marker(kind)
137
if text_modified or meta_modified:
138
changes = _('renamed and modified')
140
changes = _('renamed')
141
self.file_store.append([ True,
142
oldpath+marker + ' => ' + newpath+marker,
118
147
for path, id, kind, text_modified, meta_modified in self.delta.modified:
119
self.file_store.append([ True, path, _('modified') ])
148
marker = osutils.kind_marker(kind)
149
self.file_store.append([ True, path+marker, _('modified'), path ])
151
def _create_pending_merges(self):
152
liststore = gtk.ListStore(gobject.TYPE_STRING,
155
self.pending_view.set_model(liststore)
157
self.pending_view.append_column(gtk.TreeViewColumn(_('Date'),
158
gtk.CellRendererText(), text=0))
159
self.pending_view.append_column(gtk.TreeViewColumn(_('Committer'),
160
gtk.CellRendererText(), text=1))
161
self.pending_view.append_column(gtk.TreeViewColumn(_('Summary'),
162
gtk.CellRendererText(), text=2))
167
for item in self.pending:
168
liststore.append([ item['date'],
121
172
def _get_specific_files(self):
123
174
it = self.file_store.get_iter_first()
125
176
if self.file_store.get_value(it, 0):
126
ret.append(self.file_store.get_value(it, 1))
177
# get real path from hidden column 3
178
ret.append(self.file_store.get_value(it, 3))
127
179
it = self.file_store.iter_next(it)
130
# end of bzr-gtk code
132
183
def _toggle_commit(self, cell, path, model):
133
184
model[path][0] = not model[path][0]
187
def _pending_merges(self, wt):
188
""" Return a list of pending merges or None if there are none of them. """
189
parents = wt.get_parent_ids()
194
from bzrlib.osutils import format_date
196
pending = parents[1:]
198
last_revision = parents[0]
200
if last_revision is not None:
202
ignore = set(branch.repository.get_ancestry(last_revision))
203
except errors.NoSuchRevision:
204
# the last revision is a ghost : assume everything is new
206
ignore = set([None, last_revision])
211
for merge in pending:
214
m_revision = branch.repository.get_revision(merge)
217
rev['committer'] = re.sub('<.*@.*>', '', m_revision.committer).strip(' ')
218
rev['summary'] = m_revision.get_summary()
219
rev['date'] = format_date(m_revision.timestamp,
220
m_revision.timezone or 0,
221
'original', date_fmt="%Y-%m-%d",
226
inner_merges = branch.repository.get_ancestry(merge)
227
assert inner_merges[0] is None
229
inner_merges.reverse()
230
for mmerge in inner_merges:
233
mm_revision = branch.repository.get_revision(mmerge)
236
rev['committer'] = re.sub('<.*@.*>', '', mm_revision.committer).strip(' ')
237
rev['summary'] = mm_revision.get_summary()
238
rev['date'] = format_date(mm_revision.timestamp,
239
mm_revision.timezone or 0,
240
'original', date_fmt="%Y-%m-%d",
246
except errors.NoSuchRevision:
247
print "DEBUG: NoSuchRevision:", merge
136
251
def commit(self, widget):
137
252
textbuffer = self.textview.get_buffer()
138
253
start, end = textbuffer.get_bounds()
139
message = textbuffer.get_text(start, end)
254
message = textbuffer.get_text(start, end).decode('utf-8')
141
256
checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
142
257
checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
144
specific_files = self._get_specific_files()
260
specific_files = self._get_specific_files()
262
specific_files = None
147
265
self.wt.commit(message,
151
269
specific_files=specific_files)
152
270
except errors.NotBranchError:
153
271
error_dialog(_('Directory is not a branch'),
154
_('You can perform this action only in a branch.'))
272
_('You can perform this action only in a branch.'))
156
274
except errors.LocalRequiresBoundBranch:
157
275
error_dialog(_('Directory is not a checkout'),
158
_('You can perform local commit only on checkouts.'))
276
_('You can perform local commit only on checkouts.'))
160
278
except errors.PointlessCommit:
161
279
error_dialog(_('No changes to commit'),
162
_('Try force commit if you want to commit anyway.'))
280
_('Try force commit if you want to commit anyway.'))
164
282
except errors.ConflictsInTree:
165
283
error_dialog(_('Conflicts in tree'),
166
_('You need to resolve the conflicts before committing.'))
284
_('You need to resolve the conflicts before committing.'))
168
286
except errors.StrictCommitFailed:
169
287
error_dialog(_('Strict commit failed'),
170
_('There are unknown files in the working tree.\nPlease add or delete them.'))
288
_('There are unknown files in the working tree.\nPlease add or delete them.'))
172
290
except errors.BoundBranchOutOfDate, errmsg:
173
291
error_dialog(_('Bound branch is out of date'),
176
294
except errors.BzrError, msg:
177
295
error_dialog(_('Unknown bzr error'), str(msg))