Patchwork [7,of,7] debugobsolete: add a --rev argument

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 21, 2014, 3:20 a.m.
Message ID <72b948916c3e04870926.1408591257@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5544/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 21, 2014, 3:20 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1408515764 25200
#      Tue Aug 19 23:22:44 2014 -0700
# Node ID 72b948916c3e04870926c72d3bd214a8d0cdbcb9
# Parent  fcc1638e9db4378096dd39499bfc8ff15166a994
debugobsolete: add a --rev argument

This argument can be used to list markers relevant to a set of revision. We
adds a test for this option and the relevant computatio in the same move.
Augie Fackler - Aug. 23, 2014, 7:07 p.m.
On Wed, Aug 20, 2014 at 08:20:57PM -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1408515764 25200
> #      Tue Aug 19 23:22:44 2014 -0700
> # Node ID 72b948916c3e04870926c72d3bd214a8d0cdbcb9
> # Parent  fcc1638e9db4378096dd39499bfc8ff15166a994
> debugobsolete: add a --rev argument

Series looks good, queued.

>
> This argument can be used to list markers relevant to a set of revision. We
> adds a test for this option and the relevant computatio in the same move.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -2309,10 +2309,11 @@ def debuglabelcomplete(ui, repo, *args):
>
>  @command('debugobsolete',
>          [('', 'flags', 0, _('markers flag')),
>           ('', 'record-parents', False,
>            _('record parent information for the precursor')),
> +         ('r', 'rev', [], _('display markers relevant to REV')),
>          ] + commitopts2,
>           _('[OBSOLETED [REPLACEMENT] [REPL... ]'))
>  def debugobsolete(ui, repo, precursor=None, *successors, **opts):
>      """create arbitrary obsolete marker
>
> @@ -2330,10 +2331,12 @@ def debugobsolete(ui, repo, precursor=No
>          except TypeError:
>              raise util.Abort('changeset references must be full hexadecimal '
>                               'node identifiers')
>
>      if precursor is not None:
> +        if opts['rev']:
> +            raise util.Abort('cannot select revision when creating marker')
>          metadata = {}
>          metadata['user'] = opts['user'] or ui.username()
>          succs = tuple(parsenodeid(succ) for succ in successors)
>          l = repo.lock()
>          try:
> @@ -2362,11 +2365,19 @@ def debugobsolete(ui, repo, precursor=No
>              finally:
>                  tr.release()
>          finally:
>              l.release()
>      else:
> -        for m in obsolete.getmarkers(repo):
> +        if opts['rev']:
> +            revs = scmutil.revrange(repo, opts['rev'])
> +            nodes = [repo[r].node() for r in revs]
> +            markers = list(obsolete.getmarkers(repo, nodes=nodes))
> +            markers.sort(key=lambda x: x._data)
> +        else:
> +            markers = obsolete.getmarkers(repo)
> +
> +        for m in markers:
>              cmdutil.showmarker(ui, m)
>
>  @command('debugpathcomplete',
>           [('f', 'full', None, _('complete an entire path')),
>            ('n', 'normal', None, _('show only normal files')),
> diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
> --- a/mercurial/obsolete.py
> +++ b/mercurial/obsolete.py
> @@ -491,15 +491,29 @@ def pushmarker(repo, key, old, new):
>          finally:
>              tr.release()
>      finally:
>          lock.release()
>
> -def getmarkers(repo):
> -    """returns markers known in a repository"""
> -    for markerdata in repo.obsstore:
> +def getmarkers(repo, nodes=None):
> +    """returns markers known in a repository
> +
> +    If <nodes> is specified, only markers "relevant" to those nodes are are
> +    returned"""
> +    if nodes is None:
> +        rawmarkers = repo.obsstore
> +    else:
> +        rawmarkers = repo.obsstore.relevantmarkers(nodes)
> +
> +    for markerdata in rawmarkers:
>          yield marker(repo, markerdata)
>
> +def relevantmarkers(repo, node):
> +    """all obsolete markers relevant to some revisions"""
> +    for markerdata in repo.obsstore.relevantmarkers(node):
> +        yield marker(repo, markerdata)
> +
> +
>  def precursormarkers(ctx):
>      """obsolete marker marking this changeset as a successors"""
>      for data in ctx._repo.obsstore.precursors.get(ctx.node(), ()):
>          yield marker(ctx._repo, data)
>
> diff --git a/tests/test-completion.t b/tests/test-completion.t
> --- a/tests/test-completion.t
> +++ b/tests/test-completion.t
> @@ -242,11 +242,11 @@ Show all commands + options
>    debugindex: changelog, manifest, format
>    debugindexdot:
>    debuginstall:
>    debugknown:
>    debuglabelcomplete:
> -  debugobsolete: flags, record-parents, date, user
> +  debugobsolete: flags, record-parents, rev, date, user
>    debugpathcomplete: full, normal, added, removed
>    debugpushkey:
>    debugpvec:
>    debugrebuilddirstate: rev
>    debugrename: rev
> diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
> --- a/tests/test-obsolete.t
> +++ b/tests/test-obsolete.t
> @@ -511,10 +511,76 @@ Do not warn about new head when the new
>    adding changesets
>    adding manifests
>    adding file changes
>    added 1 changesets with 1 changes to 1 files (+1 heads)
>
> +test relevance computation
> +---------------------------------------
> +
> +Checking simple case of "marker relevance".
> +
> +
> +Reminder of the repo situation
> +
> +  $ hg log --hidden --graph
> +  @  6:3de5eca88c00 (draft) [tip ] add obsolete_e
> +  |
> +  | x  5:cda648ca50f5 (draft) [ ] add original_e
> +  | |
> +  | x  4:94b33453f93b (draft) [ ] add original_d
> +  |/
> +  o  3:6f9641995072 (draft) [ ] add n3w_3_c
> +  |
> +  | o  2:245bde4270cd (public) [ ] add original_c
> +  |/
> +  o  1:7c3bad9141dc (public) [ ] add b
> +  |
> +  o  0:1f0dee641bb7 (public) [ ] add a
> +
> +
> +List of all markers
> +
> +  $ hg debugobsolete
> +  2448244824482448244824482448244824482448 1339133913391339133913391339133913391339 0 (Thu Jan 01 00:22:19 1970 +0000) {'user': 'test'}
> +  245bde4270cd1072a27757984f9cda8ba26f08ca cdbce2fbb16313928851e97e0d85413f3f7eb77f C (Thu Jan 01 00:00:44 1970 -0000) {'user': 'test'}
> +  cdbce2fbb16313928851e97e0d85413f3f7eb77f ca819180edb99ed25ceafb3e9584ac287e240b00 0 (Thu Jan 01 00:22:17 1970 +0000) {'user': 'test'}
> +  ca819180edb99ed25ceafb3e9584ac287e240b00 1337133713371337133713371337133713371337 0 (Thu Jan 01 00:22:18 1970 +0000) {'user': 'test'}
> +  1337133713371337133713371337133713371337 5601fb93a350734d935195fee37f4054c529ff39 0 (Thu Jan 01 00:22:19 1970 +0000) {'user': 'test'}
> +  5601fb93a350734d935195fee37f4054c529ff39 6f96419950729f3671185b847352890f074f7557 1 (Thu Jan 01 00:22:18 1970 +0000) {'user': 'test'}
> +  94b33453f93bdb8d457ef9b770851a618bf413e1 0 {6f96419950729f3671185b847352890f074f7557} (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
> +  cda648ca50f50482b7055c0b0c4c117bba6733d9 3de5eca88c00aa039da7399a220f4a5221faa585 0 (*) {'user': 'test'} (glob)
> +
> +List for changesets with no chain
> +
> +  $ hg debugobsolete --hidden --rev ::2
> +
> +List for a changeset that included a on marker chain
> +
> +  $ hg debugobsolete --hidden --rev 6
> +  cda648ca50f50482b7055c0b0c4c117bba6733d9 3de5eca88c00aa039da7399a220f4a5221faa585 0 (*) {'user': 'test'} (glob)
> +
> +List for a changeset with a longer chain, (including a pruned children)
> +
> +  $ hg debugobsolete --hidden --rev 3
> +  1337133713371337133713371337133713371337 5601fb93a350734d935195fee37f4054c529ff39 0 (Thu Jan 01 00:22:19 1970 +0000) {'user': 'test'}
> +  245bde4270cd1072a27757984f9cda8ba26f08ca cdbce2fbb16313928851e97e0d85413f3f7eb77f C (Thu Jan 01 00:00:44 1970 -0000) {'user': 'test'}
> +  5601fb93a350734d935195fee37f4054c529ff39 6f96419950729f3671185b847352890f074f7557 1 (Thu Jan 01 00:22:18 1970 +0000) {'user': 'test'}
> +  94b33453f93bdb8d457ef9b770851a618bf413e1 0 {6f96419950729f3671185b847352890f074f7557} (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
> +  ca819180edb99ed25ceafb3e9584ac287e240b00 1337133713371337133713371337133713371337 0 (Thu Jan 01 00:22:18 1970 +0000) {'user': 'test'}
> +  cdbce2fbb16313928851e97e0d85413f3f7eb77f ca819180edb99ed25ceafb3e9584ac287e240b00 0 (Thu Jan 01 00:22:17 1970 +0000) {'user': 'test'}
> +
> +List for both
> +
> +  $ hg debugobsolete --hidden --rev 3::6
> +  1337133713371337133713371337133713371337 5601fb93a350734d935195fee37f4054c529ff39 0 (Thu Jan 01 00:22:19 1970 +0000) {'user': 'test'}
> +  245bde4270cd1072a27757984f9cda8ba26f08ca cdbce2fbb16313928851e97e0d85413f3f7eb77f C (Thu Jan 01 00:00:44 1970 -0000) {'user': 'test'}
> +  5601fb93a350734d935195fee37f4054c529ff39 6f96419950729f3671185b847352890f074f7557 1 (Thu Jan 01 00:22:18 1970 +0000) {'user': 'test'}
> +  94b33453f93bdb8d457ef9b770851a618bf413e1 0 {6f96419950729f3671185b847352890f074f7557} (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
> +  ca819180edb99ed25ceafb3e9584ac287e240b00 1337133713371337133713371337133713371337 0 (Thu Jan 01 00:22:18 1970 +0000) {'user': 'test'}
> +  cda648ca50f50482b7055c0b0c4c117bba6733d9 3de5eca88c00aa039da7399a220f4a5221faa585 0 (*) {'user': 'test'} (glob)
> +  cdbce2fbb16313928851e97e0d85413f3f7eb77f ca819180edb99ed25ceafb3e9584ac287e240b00 0 (Thu Jan 01 00:22:17 1970 +0000) {'user': 'test'}
> +
>  #if serve
>
>  check hgweb does not explode
>  ====================================
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2309,10 +2309,11 @@  def debuglabelcomplete(ui, repo, *args):
 
 @command('debugobsolete',
         [('', 'flags', 0, _('markers flag')),
          ('', 'record-parents', False,
           _('record parent information for the precursor')),
+         ('r', 'rev', [], _('display markers relevant to REV')),
         ] + commitopts2,
          _('[OBSOLETED [REPLACEMENT] [REPL... ]'))
 def debugobsolete(ui, repo, precursor=None, *successors, **opts):
     """create arbitrary obsolete marker
 
@@ -2330,10 +2331,12 @@  def debugobsolete(ui, repo, precursor=No
         except TypeError:
             raise util.Abort('changeset references must be full hexadecimal '
                              'node identifiers')
 
     if precursor is not None:
+        if opts['rev']:
+            raise util.Abort('cannot select revision when creating marker')
         metadata = {}
         metadata['user'] = opts['user'] or ui.username()
         succs = tuple(parsenodeid(succ) for succ in successors)
         l = repo.lock()
         try:
@@ -2362,11 +2365,19 @@  def debugobsolete(ui, repo, precursor=No
             finally:
                 tr.release()
         finally:
             l.release()
     else:
-        for m in obsolete.getmarkers(repo):
+        if opts['rev']:
+            revs = scmutil.revrange(repo, opts['rev'])
+            nodes = [repo[r].node() for r in revs]
+            markers = list(obsolete.getmarkers(repo, nodes=nodes))
+            markers.sort(key=lambda x: x._data)
+        else:
+            markers = obsolete.getmarkers(repo)
+
+        for m in markers:
             cmdutil.showmarker(ui, m)
 
 @command('debugpathcomplete',
          [('f', 'full', None, _('complete an entire path')),
           ('n', 'normal', None, _('show only normal files')),
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -491,15 +491,29 @@  def pushmarker(repo, key, old, new):
         finally:
             tr.release()
     finally:
         lock.release()
 
-def getmarkers(repo):
-    """returns markers known in a repository"""
-    for markerdata in repo.obsstore:
+def getmarkers(repo, nodes=None):
+    """returns markers known in a repository
+
+    If <nodes> is specified, only markers "relevant" to those nodes are are
+    returned"""
+    if nodes is None:
+        rawmarkers = repo.obsstore
+    else:
+        rawmarkers = repo.obsstore.relevantmarkers(nodes)
+
+    for markerdata in rawmarkers:
         yield marker(repo, markerdata)
 
+def relevantmarkers(repo, node):
+    """all obsolete markers relevant to some revisions"""
+    for markerdata in repo.obsstore.relevantmarkers(node):
+        yield marker(repo, markerdata)
+
+
 def precursormarkers(ctx):
     """obsolete marker marking this changeset as a successors"""
     for data in ctx._repo.obsstore.precursors.get(ctx.node(), ()):
         yield marker(ctx._repo, data)
 
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -242,11 +242,11 @@  Show all commands + options
   debugindex: changelog, manifest, format
   debugindexdot: 
   debuginstall: 
   debugknown: 
   debuglabelcomplete: 
-  debugobsolete: flags, record-parents, date, user
+  debugobsolete: flags, record-parents, rev, date, user
   debugpathcomplete: full, normal, added, removed
   debugpushkey: 
   debugpvec: 
   debugrebuilddirstate: rev
   debugrename: rev
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -511,10 +511,76 @@  Do not warn about new head when the new 
   adding changesets
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files (+1 heads)
 
+test relevance computation
+---------------------------------------
+
+Checking simple case of "marker relevance".
+
+
+Reminder of the repo situation
+
+  $ hg log --hidden --graph
+  @  6:3de5eca88c00 (draft) [tip ] add obsolete_e
+  |
+  | x  5:cda648ca50f5 (draft) [ ] add original_e
+  | |
+  | x  4:94b33453f93b (draft) [ ] add original_d
+  |/
+  o  3:6f9641995072 (draft) [ ] add n3w_3_c
+  |
+  | o  2:245bde4270cd (public) [ ] add original_c
+  |/
+  o  1:7c3bad9141dc (public) [ ] add b
+  |
+  o  0:1f0dee641bb7 (public) [ ] add a
+  
+
+List of all markers
+
+  $ hg debugobsolete
+  2448244824482448244824482448244824482448 1339133913391339133913391339133913391339 0 (Thu Jan 01 00:22:19 1970 +0000) {'user': 'test'}
+  245bde4270cd1072a27757984f9cda8ba26f08ca cdbce2fbb16313928851e97e0d85413f3f7eb77f C (Thu Jan 01 00:00:44 1970 -0000) {'user': 'test'}
+  cdbce2fbb16313928851e97e0d85413f3f7eb77f ca819180edb99ed25ceafb3e9584ac287e240b00 0 (Thu Jan 01 00:22:17 1970 +0000) {'user': 'test'}
+  ca819180edb99ed25ceafb3e9584ac287e240b00 1337133713371337133713371337133713371337 0 (Thu Jan 01 00:22:18 1970 +0000) {'user': 'test'}
+  1337133713371337133713371337133713371337 5601fb93a350734d935195fee37f4054c529ff39 0 (Thu Jan 01 00:22:19 1970 +0000) {'user': 'test'}
+  5601fb93a350734d935195fee37f4054c529ff39 6f96419950729f3671185b847352890f074f7557 1 (Thu Jan 01 00:22:18 1970 +0000) {'user': 'test'}
+  94b33453f93bdb8d457ef9b770851a618bf413e1 0 {6f96419950729f3671185b847352890f074f7557} (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
+  cda648ca50f50482b7055c0b0c4c117bba6733d9 3de5eca88c00aa039da7399a220f4a5221faa585 0 (*) {'user': 'test'} (glob)
+
+List for changesets with no chain
+
+  $ hg debugobsolete --hidden --rev ::2
+
+List for a changeset that included a on marker chain
+
+  $ hg debugobsolete --hidden --rev 6
+  cda648ca50f50482b7055c0b0c4c117bba6733d9 3de5eca88c00aa039da7399a220f4a5221faa585 0 (*) {'user': 'test'} (glob)
+
+List for a changeset with a longer chain, (including a pruned children)
+
+  $ hg debugobsolete --hidden --rev 3
+  1337133713371337133713371337133713371337 5601fb93a350734d935195fee37f4054c529ff39 0 (Thu Jan 01 00:22:19 1970 +0000) {'user': 'test'}
+  245bde4270cd1072a27757984f9cda8ba26f08ca cdbce2fbb16313928851e97e0d85413f3f7eb77f C (Thu Jan 01 00:00:44 1970 -0000) {'user': 'test'}
+  5601fb93a350734d935195fee37f4054c529ff39 6f96419950729f3671185b847352890f074f7557 1 (Thu Jan 01 00:22:18 1970 +0000) {'user': 'test'}
+  94b33453f93bdb8d457ef9b770851a618bf413e1 0 {6f96419950729f3671185b847352890f074f7557} (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
+  ca819180edb99ed25ceafb3e9584ac287e240b00 1337133713371337133713371337133713371337 0 (Thu Jan 01 00:22:18 1970 +0000) {'user': 'test'}
+  cdbce2fbb16313928851e97e0d85413f3f7eb77f ca819180edb99ed25ceafb3e9584ac287e240b00 0 (Thu Jan 01 00:22:17 1970 +0000) {'user': 'test'}
+
+List for both
+
+  $ hg debugobsolete --hidden --rev 3::6
+  1337133713371337133713371337133713371337 5601fb93a350734d935195fee37f4054c529ff39 0 (Thu Jan 01 00:22:19 1970 +0000) {'user': 'test'}
+  245bde4270cd1072a27757984f9cda8ba26f08ca cdbce2fbb16313928851e97e0d85413f3f7eb77f C (Thu Jan 01 00:00:44 1970 -0000) {'user': 'test'}
+  5601fb93a350734d935195fee37f4054c529ff39 6f96419950729f3671185b847352890f074f7557 1 (Thu Jan 01 00:22:18 1970 +0000) {'user': 'test'}
+  94b33453f93bdb8d457ef9b770851a618bf413e1 0 {6f96419950729f3671185b847352890f074f7557} (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
+  ca819180edb99ed25ceafb3e9584ac287e240b00 1337133713371337133713371337133713371337 0 (Thu Jan 01 00:22:18 1970 +0000) {'user': 'test'}
+  cda648ca50f50482b7055c0b0c4c117bba6733d9 3de5eca88c00aa039da7399a220f4a5221faa585 0 (*) {'user': 'test'} (glob)
+  cdbce2fbb16313928851e97e0d85413f3f7eb77f ca819180edb99ed25ceafb3e9584ac287e240b00 0 (Thu Jan 01 00:22:17 1970 +0000) {'user': 'test'}
+
 #if serve
 
 check hgweb does not explode
 ====================================