Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.5, 0.6, and 0.7

commit: add tool button to undo last commit

Changeset 4fc47282ede8

Parent a1ec75c32e81

by TK Soh

Changes to 3 files · Browse files at 4fc47282ede8 Showing diff from parent a1ec75c32e81 Diff from another changeset...

Change 1 of 5 Show Entire File hggtk/​commit.py Stacked
 
39
40
41
 
 
 
 
42
43
44
 
88
89
90
 
 
 
 
91
92
93
 
187
188
189
 
190
191
192
193
194
 
 
 
 
 
 
195
196
197
 
244
245
246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
248
249
 
298
299
300
 
301
302
 
 
 
 
 
 
 
303
304
305
 
39
40
41
42
43
44
45
46
47
48
 
92
93
94
95
96
97
98
99
100
101
 
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
 
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
 
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
@@ -39,6 +39,10 @@
    ### Overrides of base class methods ###   + def init(self): + GStatus.init(self) + self._last_commit_id = None +   def parse_opts(self):   GStatus.parse_opts(self)   @@ -88,6 +92,10 @@
    def get_tbbuttons(self):   tbbuttons = GStatus.get_tbbuttons(self) + tbbuttons.insert(2, gtk.SeparatorToolItem()) + self._undo_button = self.make_toolbutton(gtk.STOCK_UNDO, '_Undo', + self._undo_clicked, tip='undo recent commit') + tbbuttons.insert(2, self._undo_button)   tbbuttons.insert(2, self.make_toolbutton(gtk.STOCK_OK, '_Commit',   self._commit_clicked, tip='commit'))   return tbbuttons @@ -187,11 +195,18 @@
  def reload_status(self):   success = GStatus.reload_status(self)   self._check_merge() + self._check_undo()   return success       ### End of overridable methods ###   + def _check_undo(self): + can_undo = os.path.exists(self.repo.sjoin("undo")) and \ + self._last_commit_id is not None + self._undo_button.set_sensitive(can_undo) + +   def _check_merge(self):   # disable the checkboxes on the filelist if repo in merging state   merged = len(self.repo.workingctx().parents()) > 1 @@ -244,6 +259,28 @@
  return True     + def _undo_clicked(self, toolbutton, data=None): + response = Confirm('Undo commit', [], self, 'Undo last commit').run() + if response != gtk.RESPONSE_YES: + return + + tip = self._get_tip_rev(True) + if not tip == self._last_commit_id: + Prompt('Undo commit', + 'Unable to undo!\n\n' + 'Tip revision differs from last commit.', + self).run() + return + + try: + self.repo.rollback() + self._last_commit_id = None + self.reload_status() + except: + Prompt('Undo commit', 'Errors during rollback!', + self).run() + +   def _should_addremove(self, files):   if self.test_opt('addremove'):   return True @@ -298,8 +335,16 @@
  self.text.set_buffer(gtk.TextBuffer())   self._update_recent_messages(self.opts['message'])   shell_notify([self.cwd] + files) + self._last_commit_id = self._get_tip_rev(True)   self.reload_status()   + def _get_tip_rev(self, refresh=False): + if refresh: + self.repo.invalidate() + cl = self.repo.changelog + tip = cl.node(nullrev + cl.count()) + return hex(tip) +  def launch(root='', files=[], cwd='', main=True):   u = ui.ui()   u.updateopts(debug=False, traceback=False)
Change 1 of 1 Show Entire File hggtk/​gdialog.py Stacked
 
101
102
103
 
104
105
106
 
 
 
107
108
109
 
101
102
103
104
105
106
107
108
109
110
111
112
113
@@ -101,9 +101,13 @@
  self.tmproot = None   self.toolbuttons = {}   self.settings = Settings(self.__class__.__name__) + self.init()     ### Following methods are meant to be overridden by subclasses ###   + def init(self): + pass +   def parse_opts(self):   pass  
Change 1 of 1 Show Entire File hggtk/​status.py Stacked
 
44
45
46
 
 
 
47
48
49
 
44
45
46
47
48
49
50
51
52
@@ -44,6 +44,9 @@
    ### Following methods are meant to be overridden by subclasses ###   + def init(self): + GDialog.init(self) +   def auto_check(self):   if self.test_opt('check'):   for entry in self.model : entry[0] = True