commands: make --rev and --index compatible in debugobsolete
authorKostia Balytskyi <ikostia@fb.com>
Mon, 04 Apr 2016 02:05:10 -0700
changeset 28845 5a398627db92
parent 28844 99a2bdad0fda
child 28846 18f2fc517098
commands: make --rev and --index compatible in debugobsolete
mercurial/commands.py
tests/test-obsolete.t
--- a/mercurial/commands.py	Sun Apr 03 19:38:57 2016 +0900
+++ b/mercurial/commands.py	Mon Apr 04 02:05:10 2016 -0700
@@ -3122,9 +3122,6 @@
         finally:
             l.release()
     else:
-        if opts.get('rev') and opts.get('index'):
-            hint = _("call 'hg debugobsolete --index' without other arguments")
-            raise error.Abort(_("cannot use --index with --rev"), hint=hint)
         if opts['rev']:
             revs = scmutil.revrange(repo, opts['rev'])
             nodes = [repo[r].node() for r in revs]
@@ -3133,7 +3130,23 @@
         else:
             markers = obsolete.getmarkers(repo)
 
-        for i, m in enumerate(markers):
+        markerstoiter = markers
+        isrelevant = lambda m: True
+        if opts.get('rev') and opts.get('index'):
+            markerstoiter = obsolete.getmarkers(repo)
+            markerset = set(markers)
+            isrelevant = lambda m: m in markerset
+
+        for i, m in enumerate(markerstoiter):
+            if not isrelevant(m):
+                # marker can be irrelevant when we're iterating over a set
+                # of markers (markerstoiter) which is bigger than the set
+                # of markers we want to display (markers)
+                # this can happen if both --index and --rev options are
+                # provided and thus we need to iterate over all of the markers
+                # to get the correct indices, but only display the ones that
+                # are relevant to --rev value
+                continue
             ind = i if opts.get('index') else None
             cmdutil.showmarker(ui, m, index=ind)
 
--- a/tests/test-obsolete.t	Sun Apr 03 19:38:57 2016 +0900
+++ b/tests/test-obsolete.t	Mon Apr 04 02:05:10 2016 -0700
@@ -1083,6 +1083,30 @@
   |
   @  0:a78f55e5508c (draft) [ ] 0
   
+Test that 'hg debugobsolete --index --rev' can show indices of obsmarkers when
+only a subset of those are displayed (because of --rev option)
+  $ hg init doindexrev
+  $ cd doindexrev
+  $ echo a > a
+  $ hg ci -Am a
+  adding a
+  $ hg ci --amend -m aa
+  $ echo b > b
+  $ hg ci -Am b
+  adding b
+  $ hg ci --amend -m bb
+  $ echo c > c
+  $ hg ci -Am c
+  adding c
+  $ hg ci --amend -m cc
+  $ echo d > d
+  $ hg ci -Am d
+  adding d
+  $ hg ci --amend -m dd
+  $ hg debugobsolete --index --rev "3+7"
+  1 6fdef60fcbabbd3d50e9b9cbc2a240724b91a5e1 d27fb9b066076fd921277a4b9e8b9cb48c95bc6a 0 \(.*\) {'user': 'test'} (re)
+  3 4715cf767440ed891755448016c2b8cf70760c30 7ae79c5d60f049c7b0dd02f5f25b9d60aaf7b36d 0 \(.*\) {'user': 'test'} (re)
+  $ cd ..
   $ cd ..
 
 Test the --delete option of debugobsolete command