Mercurial > hg-stable
changeset 17663:c6de8c696644
histedit: extract bookmark logic in a dedicated function
This lighten the main function and will help to see future changes to this
bookmark logic.
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Wed, 26 Sep 2012 14:19:19 +0200 |
parents | 4f2390e3f4b0 |
children | 4eb13b619785 |
files | hgext/histedit.py |
diffstat | 1 files changed, 36 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/histedit.py Wed Sep 26 12:57:23 2012 +0200 +++ b/hgext/histedit.py Wed Sep 26 14:19:19 2012 +0200 @@ -602,38 +602,8 @@ if not keep: if replacemap: - ui.note(_('histedit: Should update metadata for the following ' - 'changes:\n')) - - def copybms(old, new): - if old in tmpnodes or old in created: - # can't have any metadata we'd want to update - return - while new in replacemap: - new = replacemap[new] - ui.note(_('histedit: %s to %s\n') % (node.short(old), - node.short(new))) - octx = repo[old] - marks = octx.bookmarks() - if marks: - ui.note(_('histedit: moving bookmarks %s\n') % - ', '.join(marks)) - for mark in marks: - repo._bookmarks[mark] = new - bookmarks.write(repo) - - # We assume that bookmarks on the tip should remain - # tipmost, but bookmarks on non-tip changesets should go - # to their most reasonable successor. As a result, find - # the old tip and new tip and copy those bookmarks first, - # then do the rest of the bookmark copies. - oldtip = sorted(replacemap.keys(), key=repo.changelog.rev)[-1] - newtip = sorted(replacemap.values(), key=repo.changelog.rev)[-1] - copybms(oldtip, newtip) - - for old, new in sorted(replacemap.iteritems()): - copybms(old, new) - # TODO update mq state + movebookmarks(ui, repo, replacemap, tmpnodes, created) + # TODO update mq state ui.debug('should strip replaced nodes %s\n' % ', '.join([node.short(n) for n in replaced])) @@ -743,3 +713,37 @@ raise util.Abort(_('unknown action "%s"') % action) parsed.append([action, ha]) return parsed + +def movebookmarks(ui, repo, replacemap, tmpnodes, created): + """Move bookmark from old to newly created node""" + ui.note(_('histedit: Should update metadata for the following ' + 'changes:\n')) + + def copybms(old, new): + if old in tmpnodes or old in created: + # can't have any metadata we'd want to update + return + while new in replacemap: + new = replacemap[new] + ui.note(_('histedit: %s to %s\n') % (node.short(old), + node.short(new))) + octx = repo[old] + marks = octx.bookmarks() + if marks: + ui.note(_('histedit: moving bookmarks %s\n') % + ', '.join(marks)) + for mark in marks: + repo._bookmarks[mark] = new + bookmarks.write(repo) + + # We assume that bookmarks on the tip should remain + # tipmost, but bookmarks on non-tip changesets should go + # to their most reasonable successor. As a result, find + # the old tip and new tip and copy those bookmarks first, + # then do the rest of the bookmark copies. + oldtip = sorted(replacemap.keys(), key=repo.changelog.rev)[-1] + newtip = sorted(replacemap.values(), key=repo.changelog.rev)[-1] + copybms(oldtip, newtip) + + for old, new in sorted(replacemap.iteritems()): + copybms(old, new)