stablesort: introduce a mergepoint based method focused on head
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sat, 25 Nov 2017 15:14:50 -0500
changeset 3255 bb3f8c8c1232
parent 3254 00e20077bccf
child 3256 c82a2632327e
stablesort: introduce a mergepoint based method focused on head The things we needs for stable range is head centric. So we simplify the issue by focussing on head.
hgext3rd/evolve/stablesort.py
tests/test-stablesort-criss-cross.t
tests/test-stablesort.t
--- a/hgext3rd/evolve/stablesort.py	Sat Nov 25 04:09:17 2017 -0500
+++ b/hgext3rd/evolve/stablesort.py	Sat Nov 25 15:14:50 2017 -0500
@@ -44,7 +44,8 @@
     'debugstablesort',
     [
         ('r', 'rev', [], 'heads to start from'),
-        ('', 'method', 'branchpoint', "method used for sorting, one of: 'branchpoint'"),
+        ('', 'method', 'branchpoint', "method used for sorting, one of: "
+         "branchpoint, basic-mergepoint and basic-headstart"),
     ] + commands.formatteropts,
     _(''))
 def debugstablesort(ui, repo, **opts):
@@ -227,7 +228,18 @@
     assert len(result) == len(resultset)
     return result
 
+def stablesort_mergepoint_head_basic(repo, revs):
+    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()
+    return stablesort_mergepoint_bounded(repo, head, repo.revs('::%d', head))
+
 _methodmap = {
     'branchpoint': stablesort_branchpoint,
     'basic-mergepoint': stablesort_mergepoint_multirevs,
+    'basic-headstart': stablesort_mergepoint_head_basic,
 }
--- a/tests/test-stablesort-criss-cross.t	Sat Nov 25 04:09:17 2017 -0500
+++ b/tests/test-stablesort-criss-cross.t	Sat Nov 25 15:14:50 2017 -0500
@@ -9,7 +9,7 @@
   > [ui]
   > logtemplate = "{rev} {node|short} {desc} {tags}\n"
   > [alias]
-  > showsort = debugstablesort --template="{node|short}\n" --method basic-mergepoint
+  > showsort = debugstablesort --template="{node|short}\n" --method basic-headstart
   > EOF
 
   $ checktopo () {
--- a/tests/test-stablesort.t	Sat Nov 25 04:09:17 2017 -0500
+++ b/tests/test-stablesort.t	Sat Nov 25 15:14:50 2017 -0500
@@ -10,6 +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 basic-headstart
   > EOF
 
 
@@ -124,6 +125,51 @@
   dcbb326fdec2
   e46a4836065c
   ff43616e5d0f
+  $ hg showsorthead --rev 1d8d22637c2d
+  1ea73414a91b
+  66f7d451a68b
+  fa942426a6fd
+  2b6d669947cd
+  43227190fef8
+  4c748ffd1a46
+  f0f3ef9a6cd5
+  1d8d22637c2d
+  $ hg showsorthead --rev b4594d867745
+  1ea73414a91b
+  66f7d451a68b
+  fa942426a6fd
+  2b6d669947cd
+  bab5d5bf48bd
+  b4594d867745
+  $ hg showsorthead --rev e46a4836065c
+  1ea73414a91b
+  66f7d451a68b
+  fa942426a6fd
+  2b6d669947cd
+  bab5d5bf48bd
+  e46a4836065c
+  $ hg showsorthead --rev ff43616e5d0f
+  1ea73414a91b
+  66f7d451a68b
+  fa942426a6fd
+  2b6d669947cd
+  e7d9710d9fc6
+  d62d843c9a01
+  ff43616e5d0f
+  $ hg showsorthead --rev dcbb326fdec2
+  1ea73414a91b
+  66f7d451a68b
+  fa942426a6fd
+  2b6d669947cd
+  e7d9710d9fc6
+  d62d843c9a01
+  dcbb326fdec2
+  $ hg showsorthead --rev 2702dd0c91e7
+  1ea73414a91b
+  fa942426a6fd
+  4c748ffd1a46
+  f0f3ef9a6cd5
+  2702dd0c91e7
 
 Verify the topological order
 ----------------------------
@@ -430,6 +476,7 @@
 
   $ for x in $repos; do
   >     hg -R repo_$x showsort --rev '1d8d22637c2d' > ${x}.1d8d22637c2d.order;
+  >     hg -R repo_$x showsorthead --rev '1d8d22637c2d' > ${x}.1d8d22637c2d.orderhead;
   > done
 
   $ python "$RUNTESTDIR/md5sum.py" *.1d8d22637c2d.order
@@ -437,11 +484,17 @@
   77dc20a6f86db9103df8edaae9ad2754  B.1d8d22637c2d.order
   77dc20a6f86db9103df8edaae9ad2754  C.1d8d22637c2d.order
   77dc20a6f86db9103df8edaae9ad2754  D.1d8d22637c2d.order
+  $ python "$RUNTESTDIR/md5sum.py" *.1d8d22637c2d.orderhead
+  77dc20a6f86db9103df8edaae9ad2754  A.1d8d22637c2d.orderhead
+  77dc20a6f86db9103df8edaae9ad2754  B.1d8d22637c2d.orderhead
+  77dc20a6f86db9103df8edaae9ad2754  C.1d8d22637c2d.orderhead
+  77dc20a6f86db9103df8edaae9ad2754  D.1d8d22637c2d.orderhead
 
 changeset that are not heads
 
   $ for x in $repos; do
   >     hg -R repo_$x showsort --rev 'e7d9710d9fc6+43227190fef8' > ${x}.non-heads.order;
+  >     hg -R repo_$x showsorthead --rev 'e7d9710d9fc6+43227190fef8' > ${x}.non-heads.orderhead;
   > done
 
   $ python "$RUNTESTDIR/md5sum.py" *.non-heads.order
@@ -449,6 +502,11 @@
   94e0ea8cdade135dabde4ec5e9954329  B.non-heads.order
   94e0ea8cdade135dabde4ec5e9954329  C.non-heads.order
   94e0ea8cdade135dabde4ec5e9954329  D.non-heads.order
+  $ python "$RUNTESTDIR/md5sum.py" *.non-heads.orderhead
+  1e5ce05b507a058c5dac3d7de9ae8feb  A.non-heads.orderhead
+  1e5ce05b507a058c5dac3d7de9ae8feb  B.non-heads.orderhead
+  1e5ce05b507a058c5dac3d7de9ae8feb  C.non-heads.orderhead
+  1e5ce05b507a058c5dac3d7de9ae8feb  D.non-heads.orderhead
 
 Check with different subset
 
@@ -517,6 +575,8 @@
 
   $ for x in E F G; do
   >     hg -R repo_$x showsort --rev 'e7d9710d9fc6+43227190fef8' > ${x}.non-heads.order;
+  >     hg -R repo_$x showsort --rev 'e7d9710d9fc6' > ${x}.non-head-A.orderhead;
+  >     hg -R repo_$x showsort --rev '43227190fef8' > ${x}.non-head-B.orderhead;
   > done
 
   $ python "$RUNTESTDIR/md5sum.py" *.non-heads.order
@@ -527,6 +587,14 @@
   94e0ea8cdade135dabde4ec5e9954329  E.non-heads.order
   94e0ea8cdade135dabde4ec5e9954329  F.non-heads.order
   94e0ea8cdade135dabde4ec5e9954329  G.non-heads.order
+  $ python "$RUNTESTDIR/md5sum.py" *.non-head-A.orderhead
+  1e5ce05b507a058c5dac3d7de9ae8feb  E.non-head-A.orderhead
+  1e5ce05b507a058c5dac3d7de9ae8feb  F.non-head-A.orderhead
+  1e5ce05b507a058c5dac3d7de9ae8feb  G.non-head-A.orderhead
+  $ python "$RUNTESTDIR/md5sum.py" *.non-head-B.orderhead
+  4b07febabfee9528aedcea156a7d7071  E.non-head-B.orderhead
+  4b07febabfee9528aedcea156a7d7071  F.non-head-B.orderhead
+  4b07febabfee9528aedcea156a7d7071  G.non-head-B.orderhead
 
 Multiple recursions
 ===================
@@ -631,6 +699,38 @@
   a66b68853635
   013b27f11536
   4bbfc6078919
+  $ hg showsorthead --rev '160a7a0adbf4'
+  1ea73414a91b
+  66f7d451a68b
+  01241442b3c2
+  2dc09a01254d
+  abf57d94268b
+  529dfc5bb875
+  e7bd5218ca15
+  6ee532b68cfa
+  001194dd78d5
+  3a367db1fabc
+  a2f58e9c1e56
+  5f18015f9110
+  9fff0871d230
+  4dbf739dd63f
+  d64d500024d1
+  0496f0a6a143
+  1c645e73dbc6
+  160a7a0adbf4
+  $ hg showsorthead --rev '4bbfc6078919'
+  1ea73414a91b
+  66f7d451a68b
+  01241442b3c2
+  2dc09a01254d
+  abf57d94268b
+  529dfc5bb875
+  e7bd5218ca15
+  6ee532b68cfa
+  001194dd78d5
+  a66b68853635
+  013b27f11536
+  4bbfc6078919
   $ checktopo 'all()'
   === checking 1ea73414a91b ===
   === checking 66f7d451a68b ===
@@ -654,6 +754,8 @@
   === checking 013b27f11536 ===
   === checking 4bbfc6078919 ===
   $ hg showsort --rev 'all()' > ../multiple.source.order
+  $ hg showsorthead --rev '160a7a0adbf4' > ../160a7a0adbf4.source.orderhead
+  $ hg showsorthead --rev '4bbfc6078919' > ../4bbfc6078919.multiple.source.orderhead
   $ hg log -r tip
   20 160a7a0adbf4 r20 tip
   $ cd ..
@@ -673,9 +775,17 @@
   > done;
   $ hg pull --quiet
   $ hg showsort --rev 'all()' > ../multiple.random.order
+  $ hg showsorthead --rev '160a7a0adbf4' > ../160a7a0adbf4.random.orderhead
+  $ hg showsorthead --rev '4bbfc6078919' > ../4bbfc6078919.multiple.random.orderhead
   $ python "$RUNTESTDIR/md5sum.py" ../multiple.*.order
   a6547220a9f004c975e365d9561639dd  ../multiple.random.order
   a6547220a9f004c975e365d9561639dd  ../multiple.source.order
+  $ python "$RUNTESTDIR/md5sum.py" ../160a7a0adbf4.*.orderhead
+  48d8911f53869b32e29da26c56e95119  ../160a7a0adbf4.random.orderhead
+  48d8911f53869b32e29da26c56e95119  ../160a7a0adbf4.source.orderhead
+  $ python "$RUNTESTDIR/md5sum.py" ../4bbfc6078919.*.orderhead
+  3732305a333d59ec50b91db0f5ab696e  ../4bbfc6078919.multiple.random.orderhead
+  3732305a333d59ec50b91db0f5ab696e  ../4bbfc6078919.multiple.source.orderhead
   $ hg showsort --rev 'all()'
   1ea73414a91b
   66f7d451a68b
@@ -698,6 +808,38 @@
   a66b68853635
   013b27f11536
   4bbfc6078919
+  $ hg showsorthead --rev '160a7a0adbf4'
+  1ea73414a91b
+  66f7d451a68b
+  01241442b3c2
+  2dc09a01254d
+  abf57d94268b
+  529dfc5bb875
+  e7bd5218ca15
+  6ee532b68cfa
+  001194dd78d5
+  3a367db1fabc
+  a2f58e9c1e56
+  5f18015f9110
+  9fff0871d230
+  4dbf739dd63f
+  d64d500024d1
+  0496f0a6a143
+  1c645e73dbc6
+  160a7a0adbf4
+  $ hg showsorthead --rev '4bbfc6078919'
+  1ea73414a91b
+  66f7d451a68b
+  01241442b3c2
+  2dc09a01254d
+  abf57d94268b
+  529dfc5bb875
+  e7bd5218ca15
+  6ee532b68cfa
+  001194dd78d5
+  a66b68853635
+  013b27f11536
+  4bbfc6078919
   $ cd ..
 
 
@@ -750,3 +892,9 @@
   0dedbcd995b6
   ed776db7ed63
   7f2454f6b04f
+  $ hg showsorthead --rev '.'
+  d20a80d4def3
+  47da0f2c25e2
+  0dedbcd995b6
+  ed776db7ed63
+  7f2454f6b04f