changeset 3256:c82a2632327e

stablesort: add a --limit argument This will be useful when using stable sort within stable range.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 25 Nov 2017 17:37:37 -0500
parents bb3f8c8c1232
children 064738ae1588
files hgext3rd/evolve/stablesort.py tests/test-stablesort-criss-cross.t tests/test-stablesort.t
diffstat 3 files changed, 179 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/stablesort.py	Sat Nov 25 15:14:50 2017 -0500
+++ b/hgext3rd/evolve/stablesort.py	Sat Nov 25 17:37:37 2017 -0500
@@ -46,6 +46,7 @@
         ('r', 'rev', [], 'heads to start from'),
         ('', 'method', 'branchpoint', "method used for sorting, one of: "
          "branchpoint, basic-mergepoint and basic-headstart"),
+        ('l', 'limit', '', 'number of revision display (default to all)')
     ] + commands.formatteropts,
     _(''))
 def debugstablesort(ui, repo, **opts):
@@ -61,7 +62,10 @@
                           hint='pick one of: %s' % valid_method)
 
     displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True)
-    for r in sorting(repo, revs):
+    kwargs = {}
+    if opts['limit']:
+        kwargs['limit'] = int(opts['limit'])
+    for r in sorting(repo, revs, **kwargs):
         ctx = repo[r]
         displayer.show(ctx)
         displayer.flush(ctx)
@@ -228,7 +232,7 @@
     assert len(result) == len(resultset)
     return result
 
-def stablesort_mergepoint_head_basic(repo, revs):
+def stablesort_mergepoint_head_basic(repo, revs, limit=None):
     heads = repo.revs('heads(%ld)', revs)
     if not heads:
         return []
@@ -236,7 +240,10 @@
         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))
+    revs = stablesort_mergepoint_bounded(repo, head, repo.revs('::%d', head))
+    if limit is None:
+        return revs
+    return revs[-limit:]
 
 _methodmap = {
     'branchpoint': stablesort_branchpoint,
--- a/tests/test-stablesort-criss-cross.t	Sat Nov 25 15:14:50 2017 -0500
+++ b/tests/test-stablesort-criss-cross.t	Sat Nov 25 17:37:37 2017 -0500
@@ -690,6 +690,118 @@
   === checking 8ae32c3ed670 ===
   === checking 84d6ec6a8e21 ===
   === checking 01f771406cab ===
+  $ hg showsort --rev 'Cfinal' --limit 72
+  c3c7fa726f88
+  97d19fc5236f
+  4f5078f7da8a
+  2bd677d0f13a
+  3bdb00d5c818
+  b9c3aa92fba5
+  f3441cd3e664
+  0c3f2ba59eb7
+  2ea3fbf151b5
+  47c836a1f13e
+  722d1b8b8942
+  17b6e6bac221
+  5ce588c2b7c5
+  f2bdd828a3aa
+  a457569c5306
+  ad46a4a0fc10
+  4b39f229a0ce
+  d94da36be176
+  eed373b0090d
+  2472d042ec95
+  673f5499c8c2
+  900dd066a072
+  97ac964e34b7
+  0d153e3ad632
+  c37e7cd9f2bd
+  9a67238ad1c4
+  d99e0f7dad5b
+  e4cfd6264623
+  fac9e582edd1
+  89a0fe204177
+  b3cf98c3d587
+  041e1188f5f1
+  0484d39906c8
+  5eec91b12a58
+  c84da74cf586
+  3871506da61e
+  bf6593f7e073
+  1da228afcf06
+  4f3b41956174
+  bfcfd9a61e84
+  d6c9e2d27f14
+  37ad3ab0cddf
+  c7d3029bf731
+  1f4a19f83a29
+  43fc0b77ff07
+  31d7b43cc321
+  c713eae2d31f
+  76151e8066e1
+  c7c1497fc270
+  e7135b665740
+  82238c0bc950
+  dbde319d43a3
+  8b79544bb56d
+  721ba7c5f4ff
+  01e29e20ea3f
+  32b41ca704e1
+  88714f4125cb
+  d928b4e8a515
+  88eace5ce682
+  698970a2480b
+  29141354a762
+  b33fd5ad4c0c
+  cd345198cf12
+  28be96b80dc1
+  0bab31f71a21
+  40553f55397e
+  e3e6738c56ce
+  790cdfecd168
+  469c700e9ed8
+  8ae32c3ed670
+  84d6ec6a8e21
+  01f771406cab
+  $ hg showsort --rev 'Cfinal' --limit 33
+  bfcfd9a61e84
+  d6c9e2d27f14
+  37ad3ab0cddf
+  c7d3029bf731
+  1f4a19f83a29
+  43fc0b77ff07
+  31d7b43cc321
+  c713eae2d31f
+  76151e8066e1
+  c7c1497fc270
+  e7135b665740
+  82238c0bc950
+  dbde319d43a3
+  8b79544bb56d
+  721ba7c5f4ff
+  01e29e20ea3f
+  32b41ca704e1
+  88714f4125cb
+  d928b4e8a515
+  88eace5ce682
+  698970a2480b
+  29141354a762
+  b33fd5ad4c0c
+  cd345198cf12
+  28be96b80dc1
+  0bab31f71a21
+  40553f55397e
+  e3e6738c56ce
+  790cdfecd168
+  469c700e9ed8
+  8ae32c3ed670
+  84d6ec6a8e21
+  01f771406cab
+  $ hg showsort --rev 'Cfinal' --limit 4
+  469c700e9ed8
+  8ae32c3ed670
+  84d6ec6a8e21
+  01f771406cab
 
 Test stability of this mess
 ---------------------------
--- a/tests/test-stablesort.t	Sat Nov 25 15:14:50 2017 -0500
+++ b/tests/test-stablesort.t	Sat Nov 25 17:37:37 2017 -0500
@@ -134,6 +134,11 @@
   4c748ffd1a46
   f0f3ef9a6cd5
   1d8d22637c2d
+  $ hg showsorthead --rev 1d8d22637c2d --l 4
+  43227190fef8
+  4c748ffd1a46
+  f0f3ef9a6cd5
+  1d8d22637c2d
   $ hg showsorthead --rev b4594d867745
   1ea73414a91b
   66f7d451a68b
@@ -141,6 +146,10 @@
   2b6d669947cd
   bab5d5bf48bd
   b4594d867745
+  $ hg showsorthead --rev b4594d867745 --limit 3
+  2b6d669947cd
+  bab5d5bf48bd
+  b4594d867745
   $ hg showsorthead --rev e46a4836065c
   1ea73414a91b
   66f7d451a68b
@@ -148,6 +157,9 @@
   2b6d669947cd
   bab5d5bf48bd
   e46a4836065c
+  $ hg showsorthead --rev e46a4836065c --limit 2
+  bab5d5bf48bd
+  e46a4836065c
   $ hg showsorthead --rev ff43616e5d0f
   1ea73414a91b
   66f7d451a68b
@@ -156,6 +168,13 @@
   e7d9710d9fc6
   d62d843c9a01
   ff43616e5d0f
+  $ hg showsorthead --rev ff43616e5d0f --limit 6
+  66f7d451a68b
+  fa942426a6fd
+  2b6d669947cd
+  e7d9710d9fc6
+  d62d843c9a01
+  ff43616e5d0f
   $ hg showsorthead --rev dcbb326fdec2
   1ea73414a91b
   66f7d451a68b
@@ -164,12 +183,20 @@
   e7d9710d9fc6
   d62d843c9a01
   dcbb326fdec2
+  $ hg showsorthead --rev dcbb326fdec2 --limit 4
+  2b6d669947cd
+  e7d9710d9fc6
+  d62d843c9a01
+  dcbb326fdec2
   $ hg showsorthead --rev 2702dd0c91e7
   1ea73414a91b
   fa942426a6fd
   4c748ffd1a46
   f0f3ef9a6cd5
   2702dd0c91e7
+  $ hg showsorthead --rev 2702dd0c91e7 --limit 2
+  f0f3ef9a6cd5
+  2702dd0c91e7
 
 Verify the topological order
 ----------------------------
@@ -477,6 +504,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;
+  >     hg -R repo_$x showsorthead --rev '1d8d22637c2d' --limit 4 > ${x}.1d8d22637c2d.orderhead-4;
   > done
 
   $ python "$RUNTESTDIR/md5sum.py" *.1d8d22637c2d.order
@@ -489,12 +517,18 @@
   77dc20a6f86db9103df8edaae9ad2754  B.1d8d22637c2d.orderhead
   77dc20a6f86db9103df8edaae9ad2754  C.1d8d22637c2d.orderhead
   77dc20a6f86db9103df8edaae9ad2754  D.1d8d22637c2d.orderhead
+  $ python "$RUNTESTDIR/md5sum.py" *.1d8d22637c2d.orderhead-4
+  ea12ffc0007e1b4b911d09dd478881f3  A.1d8d22637c2d.orderhead-4
+  ea12ffc0007e1b4b911d09dd478881f3  B.1d8d22637c2d.orderhead-4
+  ea12ffc0007e1b4b911d09dd478881f3  C.1d8d22637c2d.orderhead-4
+  ea12ffc0007e1b4b911d09dd478881f3  D.1d8d22637c2d.orderhead-4
 
 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;
+  >     hg -R repo_$x showsorthead --rev 'e7d9710d9fc6+43227190fef8' --limit 6 > ${x}.non-heads.orderhead-6;
   > done
 
   $ python "$RUNTESTDIR/md5sum.py" *.non-heads.order
@@ -718,6 +752,14 @@
   0496f0a6a143
   1c645e73dbc6
   160a7a0adbf4
+  $ hg showsorthead --rev '160a7a0adbf4' --limit 7
+  5f18015f9110
+  9fff0871d230
+  4dbf739dd63f
+  d64d500024d1
+  0496f0a6a143
+  1c645e73dbc6
+  160a7a0adbf4
   $ hg showsorthead --rev '4bbfc6078919'
   1ea73414a91b
   66f7d451a68b
@@ -731,6 +773,17 @@
   a66b68853635
   013b27f11536
   4bbfc6078919
+  $ hg showsorthead --rev '4bbfc6078919' --limit 10
+  01241442b3c2
+  2dc09a01254d
+  abf57d94268b
+  529dfc5bb875
+  e7bd5218ca15
+  6ee532b68cfa
+  001194dd78d5
+  a66b68853635
+  013b27f11536
+  4bbfc6078919
   $ checktopo 'all()'
   === checking 1ea73414a91b ===
   === checking 66f7d451a68b ===
@@ -755,7 +808,7 @@
   === 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 showsorthead --rev '4bbfc6078919' > ../4bbfc6078919.source.orderhead
   $ hg log -r tip
   20 160a7a0adbf4 r20 tip
   $ cd ..
@@ -776,7 +829,7 @@
   $ 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
+  $ hg showsorthead --rev '4bbfc6078919' > ../4bbfc6078919.random.orderhead
   $ python "$RUNTESTDIR/md5sum.py" ../multiple.*.order
   a6547220a9f004c975e365d9561639dd  ../multiple.random.order
   a6547220a9f004c975e365d9561639dd  ../multiple.source.order
@@ -784,8 +837,8 @@
   48d8911f53869b32e29da26c56e95119  ../160a7a0adbf4.random.orderhead
   48d8911f53869b32e29da26c56e95119  ../160a7a0adbf4.source.orderhead
   $ python "$RUNTESTDIR/md5sum.py" ../4bbfc6078919.*.orderhead
-  3732305a333d59ec50b91db0f5ab696e  ../4bbfc6078919.multiple.random.orderhead
-  3732305a333d59ec50b91db0f5ab696e  ../4bbfc6078919.multiple.source.orderhead
+  3732305a333d59ec50b91db0f5ab696e  ../4bbfc6078919.random.orderhead
+  3732305a333d59ec50b91db0f5ab696e  ../4bbfc6078919.source.orderhead
   $ hg showsort --rev 'all()'
   1ea73414a91b
   66f7d451a68b