Patchwork [1,of,2,v4] commands: make --rev and --index compatible in debugobsolete

login
register
mail settings
Submitter Pierre-Yves David
Date April 11, 2016, 5:26 a.m.
Message ID <570B357C.2030603@ens-lyon.org>
Download mbox | patch
Permalink /patch/14513/
State Accepted
Commit 5a398627db92172d1caad3a1e3b98f8bcfd270b2
Headers show

Comments

Pierre-Yves David - April 11, 2016, 5:26 a.m.
On 04/04/2016 03:27 AM, Kostia Balytskyi wrote:
> # HG changeset patch
> # User Kostia Balytskyi <ikostia@fb.com>
> # Date 1459760710 25200
> #      Mon Apr 04 02:05:10 2016 -0700
> # Node ID 64295f5fe12dab428a69cfcf7a27a66735f17d7a
> # Parent  1490e850cffc0103fd42714cf1245a55bcbdc4a6
> commands: make --rev and --index compatible in debugobsolete

Pushed patch 1 after some minor fixes. Thanks. Sorry for the delay.

> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -3108,7 +3108,23 @@ def debugobsolete(ui, repo, precursor=No
>           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

note: you could use `isrelvant = markerset.__contains__` directly.

> +
> +        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)
>   
> diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
> --- a/tests/test-obsolete.t
> +++ b/tests/test-obsolete.t
> @@ -1083,4 +1083,19 @@ Test ability to pull changeset with loca
>     |
>     @  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 && hg ci --amend -m aa

I've extended this && on there own line to help readability of the test 
and future diff on the test

> +  adding a
> +  $ echo b > b && hg ci -Am b && hg ci --amend -m bb
> +  adding b
> +  $ echo c > c && hg ci -Am c && hg ci --amend -m cc
> +  adding c
> +  $ echo d > d && hg ci -Am d && hg ci --amend -m dd
> +  adding d
> +  $ hg debugobsolete --index --rev "3+7"
> +  1 6fdef60fcbabbd3d50e9b9cbc2a240724b91a5e1 d27fb9b066076fd921277a4b9e8b9cb48c95bc6a 0 \(.*\) {'user': 'test'} (re)
> +  3 4715cf767440ed891755448016c2b8cf70760c30 7ae79c5d60f049c7b0dd02f5f25b9d60aaf7b36d 0 \(.*\) {'user': 'test'} (re)
> +  $ cd ..

Fun fact, the previous check about --index and --rev incompatibility had 
not been removed, so testing this gave me.

    $ cd ..

I removed the check and the test pass as intended.

Cheers,

Patch

--- /home/marmoute/mercurial-testing/tests/test-obsolete.t
+++ /home/marmoute/mercurial-testing/tests/test-obsolete.t.err
@@ -1104,8 +1104,9 @@ 
    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)
+  abort: cannot use --index with --rev
+  (call 'hg debugobsolete --index' without other arguments)
+  [255]
    $ cd ..