changeset 3263:07678f7a4481

stablesort: introduce a cache object The object is not caching anything yet, but the API are getting into place.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 25 Nov 2017 18:31:37 -0500
parents 774f69d74ec2
children 383ec26247b3
files hgext3rd/evolve/stablesort.py tests/test-stablesort-criss-cross.t tests/test-stablesort.t
diffstat 3 files changed, 22 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/stablesort.py	Sat Nov 25 16:05:09 2017 -0500
+++ b/hgext3rd/evolve/stablesort.py	Sat Nov 25 18:31:37 2017 -0500
@@ -291,9 +291,29 @@
 
     return bottom + mid + top
 
+def stablesort_mergepoint_head_cached(repo, revs, limit=None):
+    heads = repo.revs('heads(%ld)', revs)
+    if not heads:
+        return []
+    elif 2 < len(heads):
+        raise error.Abort('cannot use head based merging, %d heads found'
+                          % len(heads))
+    head = heads.first()
+    cache = stablesortcache()
+    return cache.get(repo, head, limit=limit)
+
+class stablesortcache(object):
+
+    def get(self, repo, rev, limit=None):
+        revs = stablesort_mergepoint_head(repo, rev)
+        if limit is None:
+            return revs
+        return revs[-limit:]
+
 _methodmap = {
     'branchpoint': stablesort_branchpoint,
     'basic-mergepoint': stablesort_mergepoint_multirevs,
     'basic-headstart': stablesort_mergepoint_head_basic,
     'headstart': stablesort_mergepoint_head_debug,
+    'headcached': stablesort_mergepoint_head_cached,
 }
--- a/tests/test-stablesort-criss-cross.t	Sat Nov 25 16:05:09 2017 -0500
+++ b/tests/test-stablesort-criss-cross.t	Sat Nov 25 18:31:37 2017 -0500
@@ -9,7 +9,7 @@
   > [ui]
   > logtemplate = "{rev} {node|short} {desc} {tags}\n"
   > [alias]
-  > showsort = debugstablesort --template="{node|short}\n" --method headstart
+  > showsort = debugstablesort --template="{node|short}\n" --method headcached
   > EOF
 
   $ checktopo () {
--- a/tests/test-stablesort.t	Sat Nov 25 16:05:09 2017 -0500
+++ b/tests/test-stablesort.t	Sat Nov 25 18:31:37 2017 -0500
@@ -10,7 +10,7 @@
   > logtemplate = "{rev} {node|short} {desc} {tags}\n"
   > [alias]
   > showsort = debugstablesort --template="{node|short}\n" --method basic-mergepoint
-  > showsorthead = debugstablesort --template="{node|short}\n" --method headstart
+  > showsorthead = debugstablesort --template="{node|short}\n" --method headcached
   > EOF