##// END OF EJS Templates
bookmarks: more git-like branches...
David Soria Parra -
r7481:5f681a14 default
parent child Browse files
Show More
@@ -14,6 +14,15 b' bookmark is forwarded to the new changes'
14
14
15 It is possible to use bookmark names in every revision lookup (e.g. hg
15 It is possible to use bookmark names in every revision lookup (e.g. hg
16 merge, hg update).
16 merge, hg update).
17
18 The bookmark extension offers the possiblity to have a more git-like experience
19 by adding the following configuration option to your .hgrc:
20
21 [bookmarks]
22 track.current = True
23
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.
17 '''
26 '''
18
27
19 from mercurial.commands import templateopts, hex, short
28 from mercurial.commands import templateopts, hex, short
@@ -56,10 +65,47 b' def write(repo, refs):'
56 if os.path.exists(repo.join('bookmarks')):
65 if os.path.exists(repo.join('bookmarks')):
57 util.copyfile(repo.join('bookmarks'), repo.join('undo.bookmarks'))
66 util.copyfile(repo.join('bookmarks'), repo.join('undo.bookmarks'))
58 file = repo.opener('bookmarks', 'w+')
67 file = repo.opener('bookmarks', 'w+')
68 if current(repo) not in refs:
69 setcurrent(repo, None)
59 for refspec, node in refs.items():
70 for refspec, node in refs.items():
60 file.write("%s %s\n" % (hex(node), refspec))
71 file.write("%s %s\n" % (hex(node), refspec))
61 file.close()
72 file.close()
62
73
74 def current(repo):
75 '''Get the current bookmark
76
77 If we use gittishsh branches we have a current bookmark that
78 we are on. This function returns the name of the bookmark. It
79 is stored in .hg/bookmarks.current
80 '''
81 if repo._bookmarkcurrent:
82 return repo._bookmarkcurrent
83 mark = None
84 if os.path.exists(repo.join('bookmarks.current')):
85 file = repo.opener('bookmarks.current')
86 mark = file.readline()
87 if mark == '':
88 mark = None
89 file.close()
90 repo._bookmarkcurrent = mark
91 return mark
92
93 def setcurrent(repo, mark):
94 '''Set the name of the bookmark that we are currently on
95
96 Set the name of the bookmark that we are on (hg update <bookmark>).
97 The name is recoreded in .hg/bookmarks.current
98 '''
99 if repo._bookmarkcurrent == mark:
100 return
101 refs = parse(repo)
102 if mark not in refs:
103 mark = ''
104 file = repo.opener('bookmarks.current', 'w+')
105 file.write(mark)
106 file.close()
107 repo._bookmarkcurrent = mark
108
63 def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, rename=None):
109 def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, rename=None):
64 '''mercurial bookmarks
110 '''mercurial bookmarks
65
111
@@ -122,7 +168,11 b' def bookmark(ui, repo, mark=None, rev=No'
122 ui.status("no bookmarks set\n")
168 ui.status("no bookmarks set\n")
123 else:
169 else:
124 for bmark, n in marks.iteritems():
170 for bmark, n in marks.iteritems():
125 prefix = (n == cur) and '*' or ' '
171 if ui.configbool('bookmarks', 'track.current'):
172 prefix = (bmark == current(repo) and n == cur) and '*' or ' '
173 else:
174 prefix = (n == cur) and '*' or ' '
175
126 ui.write(" %s %-25s %d:%s\n" % (
176 ui.write(" %s %-25s %d:%s\n" % (
127 prefix, bmark, repo.changelog.rev(n), hexfn(n)))
177 prefix, bmark, repo.changelog.rev(n), hexfn(n)))
128 return
178 return
@@ -167,6 +217,7 b' def reposetup(ui, repo):'
167 # init a bookmark cache as otherwise we would get a infinite reading
217 # init a bookmark cache as otherwise we would get a infinite reading
168 # in lookup()
218 # in lookup()
169 repo._bookmarks = None
219 repo._bookmarks = None
220 repo._bookmarkcurrent = None
170
221
171 class bookmark_repo(repo.__class__):
222 class bookmark_repo(repo.__class__):
172 def rollback(self):
223 def rollback(self):
@@ -193,9 +244,14 b' def reposetup(ui, repo):'
193 marks = parse(repo)
244 marks = parse(repo)
194 update = False
245 update = False
195 for mark, n in marks.items():
246 for mark, n in marks.items():
196 if n in parents:
247 if ui.configbool('bookmarks', 'track.current'):
197 marks[mark] = node
248 if mark == current(repo) and n in parents:
198 update = True
249 marks[mark] = node
250 update = True
251 else:
252 if n in parents:
253 marks[mark] = node
254 update = True
199 if update:
255 if update:
200 write(repo, marks)
256 write(repo, marks)
201 return node
257 return node
@@ -243,10 +299,25 b' def pushnonbookmarked(orig, ui, repo, *a'
243
299
244 orig(ui, repo, *args, **opts)
300 orig(ui, repo, *args, **opts)
245
301
302 def updatecurbookmark(orig, ui, repo, *args, **opts):
303 '''Set the current bookmark
304
305 If the user updates to a bookmark we update the .hg/bookmarks.current
306 file.
307 '''
308 res = orig(ui, repo, *args, **opts)
309 rev = opts['rev']
310 if not rev and len(args) > 0:
311 rev = args[0]
312 setcurrent(repo, rev)
313 return res
314
246 def uisetup(ui):
315 def uisetup(ui):
247 'Replace push with a decorator to provide --non-bookmarked option'
316 'Replace push with a decorator to provide --non-bookmarked option'
248 entry = extensions.wrapcommand(commands.table, 'push', pushnonbookmarked)
317 entry = extensions.wrapcommand(commands.table, 'push', pushnonbookmarked)
249 entry[1].append(('', 'non-bookmarked', None, _("push all heads that are not bookmarked")))
318 entry[1].append(('', 'non-bookmarked', None, _("push all heads that are not bookmarked")))
319 if ui.configbool('bookmarks', 'track.current'):
320 extensions.wrapcommand(commands.table, 'update', updatecurbookmark)
250
321
251 cmdtable = {
322 cmdtable = {
252 "bookmarks":
323 "bookmarks":
General Comments 0
You need to be logged in to leave comments. Login now