D4329: dagop: port revlogdag.linearize() to standalone function

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Sat Aug 18 04:07:42 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG0a934ee94f09: dagop: port revlogdag.linearize() to standalone function (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4329?vs=10423&id=10450

REVISION DETAIL
  https://phab.mercurial-scm.org/D4329

AFFECTED FILES
  mercurial/changegroup.py
  mercurial/dagop.py

CHANGE DETAILS

diff --git a/mercurial/dagop.py b/mercurial/dagop.py
--- a/mercurial/dagop.py
+++ b/mercurial/dagop.py
@@ -738,3 +738,40 @@
     headrevs.discard(node.nullrev)
 
     return headrevs
+
+def linearize(revs, parentsfn):
+    """Linearize and topologically sort a list of revisions.
+
+    The linearization process tires to create long runs of revs where a child
+    rev comes immediately after its first parent. This is done by visiting the
+    heads of the revs in inverse topological order, and for each visited rev,
+    visiting its second parent, then its first parent, then adding the rev
+    itself to the output list.
+
+    Returns a list of revision numbers.
+    """
+    visit = list(sorted(headrevs(revs, parentsfn), reverse=True))
+    finished = set()
+    result = []
+
+    while visit:
+        rev = visit.pop()
+        if rev < 0:
+            rev = -rev - 1
+
+            if rev not in finished:
+                result.append(rev)
+                finished.add(rev)
+
+        else:
+            visit.append(-rev - 1)
+
+            for prev in parentsfn(rev):
+                if prev == node.nullrev or prev not in revs or prev in finished:
+                    continue
+
+                visit.append(prev)
+
+    assert len(result) == len(revs)
+
+    return result
diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -24,7 +24,7 @@
 )
 
 from . import (
-    dagutil,
+    dagop,
     error,
     match as matchmod,
     mdiff,
@@ -587,8 +587,8 @@
     # for generaldelta revlogs, we linearize the revs; this will both be
     # much quicker and generate a much smaller bundle
     if (store._generaldelta and reorder is None) or reorder:
-        dag = dagutil.revlogdag(store)
-        return dag.linearize(set(store.rev(n) for n in nodes))
+        revs = set(store.rev(n) for n in nodes)
+        return dagop.linearize(revs, store.parentrevs)
     else:
         return sorted([store.rev(n) for n in nodes])
 



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list