Avoid calling heads() twice on every hg commit.
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Sun, 23 Mar 2008 21:03:24 -0300
changeset 6369 53912d30ac40
parent 6368 2c370f08c486
child 6370 6440e25a1ba3
Avoid calling heads() twice on every hg commit. In an extreme case (merging two revisions with very low revision numbers) this could be slower than the previous code, but it should be much faster in the usual cases (parents are near the tip). It also avoids some races in some uninteresting cases (e.g. two concurrent hg commits).
mercurial/commands.py
--- a/mercurial/commands.py	Sun Mar 23 23:08:18 2008 +0100
+++ b/mercurial/commands.py	Sun Mar 23 21:03:24 2008 -0300
@@ -548,9 +548,18 @@
         return repo.commit(files, message, opts['user'], opts['date'], match,
                            force_editor=opts.get('force_editor'))
 
-    heads = repo.changelog.heads()
-    cmdutil.commit(ui, repo, commitfunc, pats, opts)
-    if len(repo.changelog.heads()) > len(heads):
+    node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
+    if not node:
+        return
+    cl = repo.changelog
+    rev = cl.rev(node)
+    parents = cl.parentrevs(rev)
+    if rev - 1 in parents:
+        # one of the parents was the old tip
+        return
+    if (parents == (nullrev, nullrev) or
+        len(cl.heads(cl.node(parents[0]))) > 1 and
+        (parents[1] == nullrev or len(cl.heads(cl.node(parents[1]))) > 1)):
         ui.status(_('created new head\n'))
 
 def copy(ui, repo, *pats, **opts):