[Python-checkins] pymigr: Add an experimental tool to dummy-merge useless heads, to make the
antoine.pitrou
python-checkins at python.org
Thu Feb 24 04:34:26 CET 2011
antoine.pitrou pushed cb91d06e83e9 to pymigr:
http://hg.python.org/pymigr/rev/cb91d06e83e9
changeset: 94:cb91d06e83e9
user: Antoine Pitrou <solipsis at pitrou.net>
date: Thu Feb 24 03:46:21 2011 +0100
summary:
Add an experimental tool to dummy-merge useless heads, to make the
topology much simpler for hg.
files:
closebranches.py
diff --git a/closebranches.py b/closebranches.py
new file mode 100755
--- /dev/null
+++ b/closebranches.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+"""
+Experimental tool to make "dummy merges" of obsolete heads (all heads except
+tips of named branches), to reduce the number of heads and make life easier for hg.
+"""
+
+from pprint import pprint
+import sys
+
+from mercurial import ui, hg, commands
+
+# see http://mercurial.selenic.com/wiki/TipsAndTricks#mergemineortheir
+
+head_tmpl = """\
+hg up %(branch)s
+hg -y merge -t internal:fail %(head_rev)s
+hg revert -a -r .
+hg resolve -am
+hg ci -m "(hg migration: dummy merge of %(svn_branch)r)"
+"""
+
+def walk(ui, repo):
+ # The heads in descending order ("latest" first)
+ heads = repo.heads()
+ # Latest head by branch
+ branch_tips = {}
+ for n in heads:
+ ctx = repo[n]
+ branch = ctx.branch()
+ if branch not in branch_tips:
+ branch_tips[branch] = n
+ print "branch tips:"
+ pprint(branch_tips)
+
+ # Then list those heads which are *not* branch-local tips
+ for n in heads:
+ ctx = repo[n]
+ branch = ctx.branch()
+ if n == branch_tips[branch]:
+ continue
+ extra = ctx.extra()
+ svn_rev = extra['convert_revision']
+ svn_branch = '/'.join(svn_rev.split('/')[-2:])
+ print "dummy merge of %s (%r)" % (ctx.hex(), svn_branch)
+ #print head_tmpl % dict(
+ #branch=branch, head_rev=ctx.hex(), svn_branch=svn_branch)
+ commands.update(ui, repo, rev=branch)
+ commands.merge(ui, repo, n, tool='internal:local')
+ commands.revert(ui, repo, all=True, rev=branch)
+ commands.resolve(ui, repo, all=True, mark=True)
+ commands.commit(ui, repo,
+ message="(hg migration: dummy merge of %r)" % svn_branch)
+
+
+if __name__ == '__main__':
+ if len(sys.argv) > 1:
+ repo_path = sys.argv[1]
+ else:
+ repo_path = '.'
+ ui = ui.ui()
+ # Allow merges to proceed without asking questions
+ ui.setconfig('ui', 'interactive', False)
+ repo = hg.repository(ui, repo_path)
+ walk(ui, repo)
--
Repository URL: http://hg.python.org/pymigr
More information about the Python-checkins
mailing list