Mercurial > hg
comparison hgext/bookmarks.py @ 7638:f83a2b1d1a71
bookmarks; clean up imports and function wrapping
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 12 Jan 2009 10:53:41 -0600 |
parents | 1d54e2f6c0b7 |
children | 2ad81e9b075b |
comparison
equal
deleted
inserted
replaced
7637:1d54e2f6c0b7 | 7638:f83a2b1d1a71 |
---|---|
23 | 23 |
24 This will cause bookmarks to track the bookmark that you are currently on, and | 24 This will cause bookmarks to track the bookmark that you are currently on, and |
25 just updates it. This is similar to git's approach of branching. | 25 just updates it. This is similar to git's approach of branching. |
26 ''' | 26 ''' |
27 | 27 |
28 from mercurial.commands import templateopts, hex, short | |
29 from mercurial import extensions | |
30 from mercurial.i18n import _ | 28 from mercurial.i18n import _ |
31 from mercurial import cmdutil, util, commands, changelog | 29 from mercurial.node import nullid, nullrev, hex, short |
32 from mercurial.node import nullid, nullrev | 30 from mercurial import util, commands, localrepo, repair, extensions |
33 import mercurial, mercurial.localrepo, mercurial.repair, os | 31 import os |
34 | 32 |
35 def parse(repo): | 33 def parse(repo): |
36 '''Parse .hg/bookmarks file and return a dictionary | 34 '''Parse .hg/bookmarks file and return a dictionary |
37 | 35 |
38 Bookmarks are stored as {HASH}\s{NAME}\n (localtags format) values | 36 Bookmarks are stored as {HASH}\s{NAME}\n (localtags format) values |
196 for p in parents: | 194 for p in parents: |
197 if p not in tostrip and p > srev: | 195 if p not in tostrip and p > srev: |
198 saveheads.append(p) | 196 saveheads.append(p) |
199 return [r for r in tostrip if r not in saveheads] | 197 return [r for r in tostrip if r not in saveheads] |
200 | 198 |
201 def strip(ui, repo, node, backup="all"): | 199 def strip(oldstrip, ui, repo, node, backup="all"): |
202 """Strip bookmarks if revisions are stripped using | 200 """Strip bookmarks if revisions are stripped using |
203 the mercurial.strip method. This usually happens during | 201 the mercurial.strip method. This usually happens during |
204 qpush and qpop""" | 202 qpush and qpop""" |
205 revisions = _revstostrip(repo.changelog, node) | 203 revisions = _revstostrip(repo.changelog, node) |
206 marks = parse(repo) | 204 marks = parse(repo) |
212 if len(update) > 0: | 210 if len(update) > 0: |
213 for m in update: | 211 for m in update: |
214 marks[m] = repo.changectx('.').node() | 212 marks[m] = repo.changectx('.').node() |
215 write(repo, marks) | 213 write(repo, marks) |
216 | 214 |
217 oldstrip = mercurial.repair.strip | |
218 mercurial.repair.strip = strip | |
219 | |
220 def reposetup(ui, repo): | 215 def reposetup(ui, repo): |
221 if not isinstance(repo, mercurial.localrepo.localrepository): | 216 if not isinstance(repo, localrepo.localrepository): |
222 return | 217 return |
223 | 218 |
224 # init a bookmark cache as otherwise we would get a infinite reading | 219 # init a bookmark cache as otherwise we would get a infinite reading |
225 # in lookup() | 220 # in lookup() |
226 repo._bookmarks = None | 221 repo._bookmarks = None |
291 tagscache.update(parse(repo)) | 286 tagscache.update(parse(repo)) |
292 return tagscache | 287 return tagscache |
293 | 288 |
294 repo.__class__ = bookmark_repo | 289 repo.__class__ = bookmark_repo |
295 | 290 |
291 def uisetup(ui): | |
292 extensions.wrapfunction(repair, "strip", strip) | |
293 if ui.configbool('bookmarks', 'track.current'): | |
294 extensions.wrapcommand(commands.table, 'update', updatecurbookmark) | |
295 | |
296 def updatecurbookmark(orig, ui, repo, *args, **opts): | 296 def updatecurbookmark(orig, ui, repo, *args, **opts): |
297 '''Set the current bookmark | 297 '''Set the current bookmark |
298 | 298 |
299 If the user updates to a bookmark we update the .hg/bookmarks.current | 299 If the user updates to a bookmark we update the .hg/bookmarks.current |
300 file. | 300 file. |
303 rev = opts['rev'] | 303 rev = opts['rev'] |
304 if not rev and len(args) > 0: | 304 if not rev and len(args) > 0: |
305 rev = args[0] | 305 rev = args[0] |
306 setcurrent(repo, rev) | 306 setcurrent(repo, rev) |
307 return res | 307 return res |
308 | |
309 def uisetup(ui): | |
310 'Replace push with a decorator to provide --non-bookmarked option' | |
311 if ui.configbool('bookmarks', 'track.current'): | |
312 extensions.wrapcommand(commands.table, 'update', updatecurbookmark) | |
313 | 308 |
314 cmdtable = { | 309 cmdtable = { |
315 "bookmarks": | 310 "bookmarks": |
316 (bookmark, | 311 (bookmark, |
317 [('f', 'force', False, _('force')), | 312 [('f', 'force', False, _('force')), |