Patchwork [1,of,5] scmutil: make cleanupnodes handle filtered node

login
register
mail settings
Submitter Jun Wu
Date June 26, 2017, 10:35 p.m.
Message ID <99027f9f17140c037882.1498516528@x1c>
Download mbox | patch
Permalink /patch/21752/
State Changes Requested
Headers show

Comments

Jun Wu - June 26, 2017, 10:35 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1498514917 25200
#      Mon Jun 26 15:08:37 2017 -0700
# Node ID 99027f9f17140c037882ebc037ef7125989eaca4
# Parent  bb46f1aba2c07467171472188efa8ce43ef081c9
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 99027f9f1714
scmutil: make cleanupnodes handle filtered node

In some valid usecases, the "mapping" received by scmutil.cleanupnodes have
filtered nodes. Use unfiltered repo to access them correctly.

The added test case will fail with the old cleanupnodes code.

This is important to migrate histedit to use the cleanupnodes API.
via Mercurial-devel - June 28, 2017, 6:22 a.m.
On Mon, Jun 26, 2017 at 3:35 PM, Jun Wu <quark@fb.com> wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1498514917 25200
> #      Mon Jun 26 15:08:37 2017 -0700
> # Node ID 99027f9f17140c037882ebc037ef7125989eaca4
> # Parent  bb46f1aba2c07467171472188efa8ce43ef081c9
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 99027f9f1714
> scmutil: make cleanupnodes handle filtered node
>
> In some valid usecases, the "mapping" received by scmutil.cleanupnodes have
> filtered nodes. Use unfiltered repo to access them correctly.
>
> The added test case will fail with the old cleanupnodes code.
>
> This is important to migrate histedit to use the cleanupnodes API.
>
> diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
> --- a/mercurial/scmutil.py
> +++ b/mercurial/scmutil.py
> @@ -617,7 +617,10 @@ def cleanupnodes(repo, mapping, operatio
>              # some obsstore logic.
>              # NOTE: the filtering and sorting might belong to createmarkers.
> -            isobs = repo.obsstore.successors.__contains__
> -            sortfunc = lambda ns: repo.changelog.rev(ns[0])
> -            rels = [(repo[n], (repo[m] for m in s))
> +            # Unfiltered repo is needed since nodes in mapping might be hidden.
> +            unfi = repo.unfiltered()
> +            isobs = unfi.obsstore.successors.__contains__
> +            torev = unfi.changelog.rev
> +            sortfunc = lambda ns: torev(ns[0])
> +            rels = [(unfi[n], (unfi[m] for m in s))
>                      for n, s in sorted(mapping.items(), key=sortfunc)
>                      if s or not isobs(n)]
> diff --git a/tests/test-obsolete-divergent.t b/tests/test-obsolete-divergent.t
> --- a/tests/test-obsolete-divergent.t
> +++ b/tests/test-obsolete-divergent.t
> @@ -11,4 +11,6 @@ Enable obsolete
>    > [experimental]
>    > evolution=createmarkers
> +  > [extensions]
> +  > drawdag=$TESTDIR/drawdag.py
>    > [alias]
>    > debugobsolete = debugobsolete -d '0 0'
> @@ -436,2 +438,50 @@ successors-set. (report [A,B] not [A] +
>
>    $ cd ..
> +
> +Use scmutil.cleanupnodes API to create divergence
> +
> +  $ hg init cleanupnodes
> +  $ cd cleanupnodes
> +  $ hg debugdrawdag <<'EOS'
> +  >   B1  B3 B4
> +  >   |     \|
> +  >   A      Z
> +  > EOS
> +
> +  $ hg update -q B1
> +  $ echo 3 >> B
> +  $ hg commit --amend -m B2
> +  $ cat > $TESTTMP/scmutilcleanup.py <<EOF
> +  > from mercurial import registrar, scmutil
> +  > cmdtable = {}
> +  > command = registrar.command(cmdtable)
> +  > @command('cleanup')
> +  > def cleanup(ui, repo):
> +  >     def node(expr):
> +  >         unfi = repo.unfiltered()
> +  >         rev = unfi.revs(expr).first()
> +  >         return unfi.changelog.node(rev)
> +  >     with repo.wlock():
> +  >         with repo.lock():
> +  >             with repo.transaction('delayedstrip'):

We're on Python 2.7 now, so you can combine these three into a single
with-block.

> +  >                 # intentionally call cleanupnodes twice to let it handle

Twice? It looks like it's once.

> +  >                 mapping = {node('desc(B1)'): [node('desc(B3)')],
> +  >                            node('desc(B3)'): [node('desc(B4)')]}
> +  >                 scmutil.cleanupnodes(repo, mapping, 'test')
> +  > EOF
> +
> +  $ rm .hg/localtags
> +  $ hg cleanup --config extensions.t=$TESTTMP/scmutilcleanup.py
> +  $ hg log -G -T '{rev}:{node|short} {desc} {troubles}' -r 'sort(all(), topo)'
> +  @  5:1a2a9b5b0030 B2 divergent
> +  |
> +  | o  4:70d5a63ca112 B4 divergent
> +  | |
> +  | o  1:48b9aae0607f Z
> +  |
> +  o  0:426bada5c675 A
> +
> +  $ hg debugobsolete
> +  a178212c3433c4e77b573f6011e29affb8aefa33 1a2a9b5b0030632400aa78e00388c20f99d3ec44 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
> +  a178212c3433c4e77b573f6011e29affb8aefa33 ad6478fb94ecec98b86daae98722865d494ac561 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
> +  ad6478fb94ecec98b86daae98722865d494ac561 70d5a63ca112acb3764bc1d7320ca90ea688d671 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Jun Wu - June 28, 2017, 3:10 p.m.
Excerpts from Martin von Zweigbergk's message of 2017-06-27 23:22:28 -0700:
> > +  >     with repo.wlock():
> > +  >         with repo.lock():
> > +  >             with repo.transaction('delayedstrip'):
> 
> We're on Python 2.7 now, so you can combine these three into a single
> with-block.

Good idea.

> > +  >                 # intentionally call cleanupnodes twice to let it handle
> 
> Twice? It looks like it's once.

Sorry. The comment should be removed.

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -617,7 +617,10 @@  def cleanupnodes(repo, mapping, operatio
             # some obsstore logic.
             # NOTE: the filtering and sorting might belong to createmarkers.
-            isobs = repo.obsstore.successors.__contains__
-            sortfunc = lambda ns: repo.changelog.rev(ns[0])
-            rels = [(repo[n], (repo[m] for m in s))
+            # Unfiltered repo is needed since nodes in mapping might be hidden.
+            unfi = repo.unfiltered()
+            isobs = unfi.obsstore.successors.__contains__
+            torev = unfi.changelog.rev
+            sortfunc = lambda ns: torev(ns[0])
+            rels = [(unfi[n], (unfi[m] for m in s))
                     for n, s in sorted(mapping.items(), key=sortfunc)
                     if s or not isobs(n)]
diff --git a/tests/test-obsolete-divergent.t b/tests/test-obsolete-divergent.t
--- a/tests/test-obsolete-divergent.t
+++ b/tests/test-obsolete-divergent.t
@@ -11,4 +11,6 @@  Enable obsolete
   > [experimental]
   > evolution=createmarkers
+  > [extensions]
+  > drawdag=$TESTDIR/drawdag.py
   > [alias]
   > debugobsolete = debugobsolete -d '0 0'
@@ -436,2 +438,50 @@  successors-set. (report [A,B] not [A] + 
 
   $ cd ..
+
+Use scmutil.cleanupnodes API to create divergence
+
+  $ hg init cleanupnodes
+  $ cd cleanupnodes
+  $ hg debugdrawdag <<'EOS'
+  >   B1  B3 B4
+  >   |     \|
+  >   A      Z
+  > EOS
+
+  $ hg update -q B1
+  $ echo 3 >> B
+  $ hg commit --amend -m B2
+  $ cat > $TESTTMP/scmutilcleanup.py <<EOF
+  > from mercurial import registrar, scmutil
+  > cmdtable = {}
+  > command = registrar.command(cmdtable)
+  > @command('cleanup')
+  > def cleanup(ui, repo):
+  >     def node(expr):
+  >         unfi = repo.unfiltered()
+  >         rev = unfi.revs(expr).first()
+  >         return unfi.changelog.node(rev)
+  >     with repo.wlock():
+  >         with repo.lock():
+  >             with repo.transaction('delayedstrip'):
+  >                 # intentionally call cleanupnodes twice to let it handle
+  >                 mapping = {node('desc(B1)'): [node('desc(B3)')],
+  >                            node('desc(B3)'): [node('desc(B4)')]}
+  >                 scmutil.cleanupnodes(repo, mapping, 'test')
+  > EOF
+
+  $ rm .hg/localtags
+  $ hg cleanup --config extensions.t=$TESTTMP/scmutilcleanup.py
+  $ hg log -G -T '{rev}:{node|short} {desc} {troubles}' -r 'sort(all(), topo)'
+  @  5:1a2a9b5b0030 B2 divergent
+  |
+  | o  4:70d5a63ca112 B4 divergent
+  | |
+  | o  1:48b9aae0607f Z
+  |
+  o  0:426bada5c675 A
+  
+  $ hg debugobsolete
+  a178212c3433c4e77b573f6011e29affb8aefa33 1a2a9b5b0030632400aa78e00388c20f99d3ec44 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
+  a178212c3433c4e77b573f6011e29affb8aefa33 ad6478fb94ecec98b86daae98722865d494ac561 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
+  ad6478fb94ecec98b86daae98722865d494ac561 70d5a63ca112acb3764bc1d7320ca90ea688d671 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}