Mercurial > hg
comparison mercurial/bookmarks.py @ 15621:013688350c7d
bookmarks: update and updatecurrentbookmark return status
This makes bookmarks.update() and bookmarks.updatecurrentbookmark() return
True or False to indicate whether the bookmark was updated or not. This allows
callers to e.g. abort if the update failed.
author | Kevin Bullock <kbullock@ringworld.org> |
---|---|
date | Wed, 16 Nov 2011 15:29:57 -0600 |
parents | 260a6449d83a |
children | 12dea4d998ec |
comparison
equal
deleted
inserted
replaced
15620:73faa2664909 | 15621:013688350c7d |
---|---|
126 wlock.release() | 126 wlock.release() |
127 repo._bookmarkcurrent = mark | 127 repo._bookmarkcurrent = mark |
128 | 128 |
129 def updatecurrentbookmark(repo, oldnode, curbranch): | 129 def updatecurrentbookmark(repo, oldnode, curbranch): |
130 try: | 130 try: |
131 update(repo, oldnode, repo.branchtags()[curbranch]) | 131 return update(repo, oldnode, repo.branchtags()[curbranch]) |
132 except KeyError: | 132 except KeyError: |
133 if curbranch == "default": # no default branch! | 133 if curbranch == "default": # no default branch! |
134 update(repo, oldnode, repo.lookup("tip")) | 134 return update(repo, oldnode, repo.lookup("tip")) |
135 else: | 135 else: |
136 raise util.Abort(_("branch %s not found") % curbranch) | 136 raise util.Abort(_("branch %s not found") % curbranch) |
137 | 137 |
138 def update(repo, parents, node): | 138 def update(repo, parents, node): |
139 marks = repo._bookmarks | 139 marks = repo._bookmarks |
145 if new in old.descendants(): | 145 if new in old.descendants(): |
146 marks[mark] = new.node() | 146 marks[mark] = new.node() |
147 update = True | 147 update = True |
148 if update: | 148 if update: |
149 repo._writebookmarks(marks) | 149 repo._writebookmarks(marks) |
150 return update | |
150 | 151 |
151 def listbookmarks(repo): | 152 def listbookmarks(repo): |
152 # We may try to list bookmarks on a repo type that does not | 153 # We may try to list bookmarks on a repo type that does not |
153 # support it (e.g., statichttprepository). | 154 # support it (e.g., statichttprepository). |
154 marks = getattr(repo, '_bookmarks', {}) | 155 marks = getattr(repo, '_bookmarks', {}) |