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

login
register
mail settings
Submitter Durham Goode
Date Nov. 13, 2013, 9:31 p.m.
Message ID <e488be1508865f645179.1384378264@dev350.prn1.facebook.com>
Download mbox | patch
Permalink /patch/2939/
State Superseded
Headers show

Comments

Durham Goode - Nov. 13, 2013, 9:31 p.m.
# HG changeset patch
# User Durham Goode <durham@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.

Patch

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 = '.'