# HG changeset patch # User Pierre-Yves David # Date 1348661959 -7200 # Node ID c6de8c696644275331c46d758c5d88a9d530391b # Parent 4f2390e3f4b078f76dc2e9c97de459fd904b0fe7 histedit: extract bookmark logic in a dedicated function This lighten the main function and will help to see future changes to this bookmark logic. diff -r 4f2390e3f4b0 -r c6de8c696644 hgext/histedit.py --- 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)