# HG changeset patch # User Pierre-Yves David # Date 1511652697 18000 # Node ID 07678f7a4481acea6bfd08400abfd4fa70760c54 # Parent 774f69d74ec29509a7a07d5ef6fc86e6c38af4a0 stablesort: introduce a cache object The object is not caching anything yet, but the API are getting into place. diff -r 774f69d74ec2 -r 07678f7a4481 hgext3rd/evolve/stablesort.py --- 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, } diff -r 774f69d74ec2 -r 07678f7a4481 tests/test-stablesort-criss-cross.t --- 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 () { diff -r 774f69d74ec2 -r 07678f7a4481 tests/test-stablesort.t --- 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