Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0.3, 2.0.4, and 2.0.5

hgtk bookmarks: use hg-1.8 APIs, remove old hglib methods

Changeset afee5a1d1d09

Parent f0de3d1b37d2

by Steve Borho

Changes to 2 files · Browse files at afee5a1d1d09 Showing diff from parent f0de3d1b37d2 Diff from another changeset...

 
10
11
12
13
14
 
15
16
17
 
20
21
22
23
24
25
26
27
28
29
30
31
 
50
51
52
53
54
55
56
57
 
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
 
 
 
 
 
 
 
 
 
 
96
97
98
99
100
101
 
102
103
104
105
106
107
108
109
110
111
 
120
121
122
123
124
125
126
127
 
 
 
 
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
 
155
156
157
158
159
160
161
162
163
 
164
165
166
 
176
177
178
179
180
181
182
183
 
190
191
192
193
 
194
195
196
 
215
216
217
218
219
220
221
222
223
224
 
245
246
247
248
249
250
251
252
253
254
 
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
 
 
346
347
348
349
350
351
 
352
353
354
 
 
355
356
357
358
359
360
 
361
362
363
 
 
364
365
366
367
368
369
 
370
371
372
 
 
373
374
375
376
377
378
379
380
381
382
383
 
 
10
11
12
 
 
13
14
15
16
 
19
20
21
 
22
23
24
25
 
26
27
28
 
47
48
49
 
 
50
51
52
 
67
68
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
71
72
73
74
75
76
77
78
79
80
81
82
83
 
 
84
85
86
 
 
87
88
 
89
90
91
 
100
101
102
 
 
 
 
 
103
104
105
106
107
108
109
110
111
 
 
 
 
 
 
 
 
 
 
 
 
112
113
114
 
122
123
124
 
 
 
125
126
 
127
128
129
130
 
140
141
142
 
 
143
144
145
 
152
153
154
 
155
156
157
158
 
177
178
179
 
 
 
 
180
181
182
 
203
204
205
 
 
 
 
206
207
208
 
269
270
271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
 
273
274
275
 
 
 
 
 
276
277
278
 
279
280
281
 
 
 
 
 
282
283
284
 
285
286
287
 
 
 
 
 
288
289
290
 
291
292
293
294
 
 
 
 
 
 
 
 
 
295
@@ -10,8 +10,7 @@
 import gtk  import traceback   -from mercurial import ui, util -from hgext import bookmarks +from mercurial import ui, util, commands    from tortoisehg.util.i18n import _  from tortoisehg.util import hglib, i18n, settings @@ -20,12 +19,10 @@
   TYPE_ADDREMOVE = 1  TYPE_RENAME = 2 -TYPE_CURRENT = 3    RESPONSE_ADD = 1  RESPONSE_REMOVE = 2  RESPONSE_RENAME = 3 -RESPONSE_CURRENT = 4  RESPONSE_MOVE = 5    class BookmarkDialog(gtk.Dialog): @@ -50,8 +47,6 @@
  self.add_button(_('Remove'), RESPONSE_REMOVE)   elif type == TYPE_RENAME:   self.add_button(_('Rename'), RESPONSE_RENAME) - elif type == TYPE_CURRENT: - self.add_button(_('Set Current'), RESPONSE_CURRENT)   else:   raise _('unexpected type: %s') % type   self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE) @@ -72,40 +67,25 @@
  table.add_row(label, self._bookmarklistbox, padding=False)     ## add entry - if type == TYPE_CURRENT: - entry = None - else: - entry = gtk.Entry() - if type == TYPE_ADDREMOVE: - self._rev_input = entry - entry.set_width_chars(12) - entry.set_text(rev) - label = _('Revision:') - elif type == TYPE_RENAME: - self._name_input = entry - label = _('New Name:') - table.add_row(label, entry, padding=False) - - # Option to make new bookmark the active one - trackcurrent = self.repo.ui.configbool('bookmarks', 'track.current') - if type == TYPE_ADDREMOVE and trackcurrent: - check = gtk.CheckButton(_('Make new/moved bookmark current')) - self.opt_newcurrent = check - check.set_sensitive(hglib.is_rev_current(self.repo, rev)) - table.add_row(None, check) + entry = gtk.Entry() + if type == TYPE_ADDREMOVE: + self._rev_input = entry + entry.set_width_chars(12) + entry.set_text(rev) + label = _('Revision:') + elif type == TYPE_RENAME: + self._name_input = entry + label = _('New Name:') + table.add_row(label, entry, padding=False)     # signal handlers   self.connect('response', self.dialog_response)   self._bookmark_input.connect('activate', self.entry_activated, type) - if entry: - entry.connect('activate', self.entry_activated, type) + entry.connect('activate', self.entry_activated, type)   if type == TYPE_ADDREMOVE:   self._bookmark_input.connect('changed', self.bookmark_changed) - if trackcurrent: - self._rev_input.connect('changed', self.rev_changed)     # prepare to show - self.load_settings()   if type == TYPE_ADDREMOVE:   self.set_add_move_button_sensitivity()   self._refresh(clear=False) @@ -120,28 +100,15 @@
  self._bookmarkslist.clear()     # add bookmarks to drop-down list - bookmarks = hglib.get_repo_bookmarks(self.repo) - bookmarks.sort() - for bookmarkname in bookmarks: - if bookmarkname != 'tip': - self._bookmarkslist.append([bookmarkname]) + marks = self.repo._bookmarks.keys() + marks.sort() + for mark in marks: + self._bookmarkslist.append([mark])     # clear bookmark name input   if clear:   self._bookmark_input.set_text('')   - def load_settings(self): - if hasattr(self, 'opt_newcurrent'): - newcurrent = self.settings.get_value('newcurrent', False) - self.opt_newcurrent.set_active(newcurrent) - - def store_settings(self): - if hasattr(self, 'opt_newcurrent'): - newcurrent = self.opt_newcurrent.get_active() - self.settings.set_value('newcurrent', newcurrent) - - self.settings.write() -   def dialog_response(self, dialog, response_id):   # Add button   if response_id == RESPONSE_ADD: @@ -155,12 +122,9 @@
  # Rename button   elif response_id == RESPONSE_RENAME:   self._do_rename_bookmark() - # Set Current button - elif response_id == RESPONSE_CURRENT: - self._do_current_bookmark()   # Close button or closed by the user   elif response_id in (gtk.RESPONSE_CLOSE, gtk.RESPONSE_DELETE_EVENT): - self.store_settings() + self.settings.write()   self.destroy()   return # close dialog   else: @@ -176,8 +140,6 @@
  self.response(RESPONSE_MOVE)   elif type == TYPE_RENAME:   self.response(RESPONSE_RENAME) - elif type == TYPE_CURRENT: - self.response(RESPONSE_CURRENT)   else:   raise _('unexpected type: %s') % type   @@ -190,7 +152,7 @@
    def set_add_move_button_sensitivity(self):   mark = self._bookmark_input.get_text() - if mark in hglib.get_repo_bookmarks(self.repo): + if mark in self.repo._bookmarks:   self._button_add.set_sensitive(False)   self._button_move.set_sensitive(True)   else: @@ -215,10 +177,6 @@
  self._add_hg_bookmark(name, rev)   dialog.info_dialog(self, _('Bookmarking completed'),   _('Bookmark "%s" has been added') % name) - if (hasattr(self, 'opt_newcurrent') and - self.opt_newcurrent.get_property('sensitive') and - self.opt_newcurrent.get_active()): - self._current_hg_bookmark(name)   self._refresh()   except util.Abort, inst:   dialog.error_dialog(self, _('Error in bookmarking'), str(inst)) @@ -245,10 +203,6 @@
  self._move_hg_bookmark(name, rev)   dialog.info_dialog(self, _('Bookmarking completed'),   _('Bookmark "%s" has been moved') % name) - if (hasattr(self, 'opt_newcurrent') and - self.opt_newcurrent.get_property('sensitive') and - self.opt_newcurrent.get_active()): - self._current_hg_bookmark(name)   self._refresh()   except util.Abort, inst:   dialog.error_dialog(self, _('Error in bookmarking'), str(inst)) @@ -315,69 +269,27 @@
  traceback.format_exc())   return False   - def _do_current_bookmark(self): - # gather input data - name = self._bookmark_input.get_text() - - # verify input - if name == '': - dialog.error_dialog(self, _('Bookmark input is empty'), - _('Please enter bookmark name')) - self._bookmark_input.grab_focus() - return False - - # set current bookmark - try: - self._current_hg_bookmark(name) - dialog.info_dialog(self, _('Bookmarking completed'), - _('Bookmark "%s" has been made current') % - name) - self._refresh() - except util.Abort, inst: - dialog.error_dialog(self, _('Error in bookmarking'), str(inst)) - return False - except: - dialog.error_dialog(self, _('Error in bookmarking'), - traceback.format_exc()) - return False -   def _add_hg_bookmark(self, name, revision): - if name in hglib.get_repo_bookmarks(self.repo): + repo = self.repo + if name in repo._bookmarks:   raise util.Abort(_('a bookmark named "%s" already exists') % name) - - bookmarks.bookmark(ui=ui.ui(), - repo=self.repo, - rev=revision, - mark=name) + commands.bookmark(repo.ui, repo, name, revision, True)     def _move_hg_bookmark(self, name, revision): - if name not in hglib.get_repo_bookmarks(self.repo): + repo = self.repo + if name not in repo._bookmarks:   raise util.Abort(_('No bookmark named "%s" exists') % name) - bookmarks.bookmark(ui=ui.ui(), - repo=self.repo, - rev=revision, - mark=name, - force=True) + commands.bookmark(repo.ui, repo, name, revision, True)     def _remove_hg_bookmark(self, name): - if not name in hglib.get_repo_bookmarks(self.repo): + repo = self.repo + if not name in repo._bookmarks:   raise util.Abort(_("Bookmark '%s' does not exist") % name) - - bookmarks.bookmark(ui=ui.ui(), - repo=self.repo, - mark=name, - delete=True) + commands.bookmark(repo.ui, repo, name, None, True, True)     def _rename_hg_bookmark(self, name, new_name): - if new_name in hglib.get_repo_bookmarks(self.repo): + repo = self.repo + if new_name in repo._bookmarks:   raise util.Abort(_('a bookmark named "%s" already exists') %   new_name) - bookmarks.bookmark(ui=ui.ui(), - repo=self.repo, - mark=new_name, - rename=name) - - def _current_hg_bookmark(self, name): - if name not in hglib.get_repo_bookmarks(self.repo): - raise util.Abort(_('No bookmark named "%s" exists') % name) - bookmarks.setcurrent(self.repo, name) + commands.bookmark(repo.ui, repo, new_name, None, True, False, name)
 
187
188
189
 
 
 
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
 
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
 
506
507
508
509
510
511
512
 
513
514
515
 
516
517
518
 
528
529
530
531
 
532
533
534
535
536
 
537
538
539
 
540
541
542
 
187
188
189
190
191
192
193
194
195
196
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
199
200
 
434
435
436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
437
438
439
440
 
441
442
443
444
445
446
447
 
448
449
450
 
451
452
453
454
 
464
465
466
 
467
468
469
470
471
 
472
473
474
 
475
476
477
478
@@ -187,25 +187,14 @@
   def invalidaterepo(repo):   repo.dirstate.invalidate() + for attr in ('_bookmarks', '_bookmarkcurrent'): + if attr in repo.__dict__: + delattr(repo, attr)   if isinstance(repo, bundlerepo.bundlerepository):   # Work around a bug in hg-1.3. repo.invalidate() breaks   # overlay bundlerepos   return   repo.invalidate() - # way _bookmarks / _bookmarkcurrent cached changed - # from 1.4 to 1.5... - for cachedAttr in ('_bookmarks', '_bookmarkcurrent'): - # Check if it's a property or normal value... - if is_descriptor(repo, cachedAttr): - # The very act of calling hasattr would - # re-cache the property, so just assume it's - # already cached, and catch the error if it wasn't. - try: - delattr(repo, cachedAttr) - except AttributeError: - pass - elif hasattr(repo, cachedAttr): - setattr(repo, cachedAttr, None)   if 'mq' in repo.__dict__: #do not create if it does not exist   repo.mq.invalidate()   @@ -445,74 +434,21 @@
  return_path = path_aux   return return_path   -def get_repo_bookmarks(repo, values=False): - """ - Will return the bookmarks for the given repo if the - bookmarks extension is loaded. - - By default, returns a list of bookmark names; if - values is True, returns a dict mapping names to - nodes. - - If the extension is not loaded, returns an empty - list/dict. - """ - try: - bookmarks = extensions.find('bookmarks') - except KeyError: - return values and {} or [] - if bookmarks: - # Bookmarks changed from 1.4 to 1.5... - if hasattr(bookmarks, 'parse'): - marks = bookmarks.parse(repo) - elif hasattr(repo, '_bookmarks'): - marks = repo._bookmarks - else: - marks = {} - else: - marks = {} - - if values: - return marks - else: - return marks.keys() - -def get_repo_bookmarkcurrent(repo): - """ - Will return the current bookmark for the given repo - if the bookmarks extension is loaded, and the - track.current option is on. - - If the extension is not loaded, or track.current - is not set, returns None - """ - try: - bookmarks = extensions.find('bookmarks') - except KeyError: - return None - if bookmarks and repo.ui.configbool('bookmarks', 'track.current'): - # Bookmarks changed from 1.4 to 1.5... - if hasattr(bookmarks, 'current'): - return bookmarks.current(repo) - elif hasattr(repo, '_bookmarkcurrent'): - return repo._bookmarkcurrent - return None -  def is_rev_current(repo, rev):   '''   Returns True if the revision indicated by 'rev' is the current   working directory parent. - +   If rev is '' or None, it is assumed to mean 'tip'.   '''   if rev in ('', None):   rev = 'tip'   rev = repo.lookup(rev)   parents = repo.parents() - +   if len(parents) > 1:   return False - +   return rev == parents[0].node()    def is_descriptor(obj, attr): @@ -528,15 +464,15 @@
  if attr in cls.__dict__:   return hasattr(cls.__dict__[attr], '__get__')   return None - +  def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False,   opts=None):   '''   export changesets as hg patches. - +   Mercurial moved patch.export to cmdutil.export after version 1.5   (change e764f24a45ee in mercurial). - ''' + '''     try:   return cmdutil.export(repo, revs, template, fp, switch_parent, opts)