[PATCH 3 of 5 V2] rebase: replace revset with a manual computation

Durham Goode durham at fb.com
Wed Nov 13 15:31:04 CST 2013


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1384216660 28800
#      Mon Nov 11 16:37:40 2013 -0800
# Node ID e488be1508865f6451795b22bbd7340bbdc77234
# Parent  05ca3c1dac66f205bf65eaf8c6695dae4f4531f7
rebase: replace revset with a manual computation

Revsets are slow on large repos.  Replacing this revset with the manual
computation makes amend go from 6 seconds to 5.5 seconds on a large repo.

diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -7,7 +7,7 @@
 # GNU General Public License version 2 or any later version.
 
 from mercurial import changegroup
-from mercurial.node import short
+from mercurial.node import short, nullrev
 from mercurial.i18n import _
 import os
 import errno
@@ -91,11 +91,18 @@
     savebases = [cl.node(r) for r in saverevs]
     stripbases = [cl.node(r) for r in tostrip]
 
-    # For a set s, max(parents(s) - s) is the same as max(heads(::s - s)), but
-    # is much faster
-    newbmtarget = repo.revs('max(parents(%ld) - (%ld))', tostrip, tostrip)
-    if newbmtarget:
-        newbmtarget = repo[newbmtarget[0]].node()
+    # bookmarks should go to the max parent
+    # (could use a revset here, but it's slow on large repos)
+    maxparent = nullrev
+    cl = repo.changelog
+    for rev in tostrip:
+        for prev in cl.parentrevs(rev):
+            if prev > maxparent and not prev in tostrip:
+                maxparent = prev
+
+    newbmtarget = maxparent
+    if newbmtarget != nullrev:
+        newbmtarget = repo[newbmtarget].node()
     else:
         newbmtarget = '.'
 


More information about the Mercurial-devel mailing list