Patchwork [stable] amend: check for directory renames for both merge parents (issue4516)

login
register
mail settings
Submitter Pierre-Yves David
Date March 2, 2015, 7:24 p.m.
Message ID <08f97fbae223ca1dec39.1425324290@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/7879/
State Accepted
Commit ac41aa4a66ab21210fc538e9fb51c405a341b69e
Headers show

Comments

Pierre-Yves David - March 2, 2015, 7:24 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1425322860 0
#      Mon Mar 02 19:01:00 2015 +0000
# Branch stable
# Node ID 08f97fbae223ca1dec392861829cc3f4f4651c32
# Parent  aae338f9da70ffcbf9e19ac247339e9caf50f210
amend: check for directory renames for both merge parents (issue4516)

Before this change, amending a merge would loose the rename information for file
adding in the second parents and implicitly renamed into a new directory.

In case of the merge, we also look for directory rename data from the second
parents. This seems to fix the bug and does not show other issue from the test
suite.
Augie Fackler - March 3, 2015, 4:29 p.m.
On Mon, Mar 02, 2015 at 07:24:50PM +0000, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1425322860 0
> #      Mon Mar 02 19:01:00 2015 +0000
> # Branch stable
> # Node ID 08f97fbae223ca1dec392861829cc3f4f4651c32
> # Parent  aae338f9da70ffcbf9e19ac247339e9caf50f210
> amend: check for directory renames for both merge parents (issue4516)

This appears to have been ninja-pushed as
http://selenic.com/repo/hg/rev/ac41aa4a66ab.

>
> Before this change, amending a merge would loose the rename information for file
> adding in the second parents and implicitly renamed into a new directory.
>
> In case of the merge, we also look for directory rename data from the second
> parents. This seems to fix the bug and does not show other issue from the test
> suite.
>
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -2279,10 +2279,12 @@ def amend(ui, repo, commitfunc, old, ext
>
>                  user = ctx.user()
>                  date = ctx.date()
>                  # Recompute copies (avoid recording a -> b -> a)
>                  copied = copies.pathcopies(base, ctx)
> +                if old.p2:
> +                    copied.update(copies.pathcopies(old.p2(), ctx))
>
>                  # Prune files which were reverted by the updates: if old
>                  # introduced file X and our intermediate commit, node,
>                  # renamed that file, then those two files are the same and
>                  # we can discard X from our list of files. Likewise if X
> diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t
> --- a/tests/test-commit-amend.t
> +++ b/tests/test-commit-amend.t
> @@ -1055,5 +1055,68 @@ which was not far enough back in this ca
>  Before the fix, the copy information was lost.
>    $ hg status --copies --rev 0
>    A a2
>      a0
>    R a0
> +  $ cd ..
> +
> +Check that amend properly preserve rename from directory rename (issue-4516)
> +
> +If a parent of the merge renames a full directory, any files added to the old
> +directory in the other parent will be renamed to the new directory. For some
> +reason, the rename metadata was when amending such merge. This test ensure we
> +do not regress. We have a dedicated repo because it needs a setup with renamed
> +directory)
> +
> +  $ hg init issue4516
> +  $ cd issue4516
> +  $ mkdir olddirname
> +  $ echo line1 > olddirname/commonfile.py
> +  $ hg add olddirname/commonfile.py
> +  $ hg ci -m first
> +
> +  $ hg branch newdirname
> +  marked working directory as branch newdirname
> +  (branches are permanent and global, did you want a bookmark?)
> +  $ hg mv olddirname newdirname
> +  moving olddirname/commonfile.py to newdirname/commonfile.py (glob)
> +  $ hg ci -m rename
> +
> +  $ hg update default
> +  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
> +  $ echo line1 > olddirname/newfile.py
> +  $ hg add olddirname/newfile.py
> +  $ hg ci -m log
> +
> +  $ hg up newdirname
> +  1 files updated, 0 files merged, 2 files removed, 0 files unresolved
> +  $ # create newdirname/newfile.py
> +  $ hg merge default
> +  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
> +  (branch merge, don't forget to commit)
> +  $ hg ci -m add
> +  $
> +  $ hg debugrename newdirname/newfile.py
> +  newdirname/newfile.py renamed from olddirname/newfile.py:690b295714aed510803d3020da9c70fca8336def
> +  $ hg status -C --change .
> +  A newdirname/newfile.py
> +  $ hg status -C --rev 1
> +  A newdirname/newfile.py
> +  $ hg status -C --rev 2
> +  A newdirname/commonfile.py
> +    olddirname/commonfile.py
> +  A newdirname/newfile.py
> +    olddirname/newfile.py
> +  R olddirname/commonfile.py
> +  R olddirname/newfile.py
> +  $ hg debugindex newdirname/newfile.py
> +     rev    offset  length   base linkrev nodeid       p1           p2
> +       0         0      88      0       3 34a4d536c0c0 000000000000 000000000000
> +
> +  $ echo a >> newdirname/commonfile.py
> +  $ hg ci --amend -m bug
> +  $ hg debugrename newdirname/newfile.py
> +  newdirname/newfile.py renamed from olddirname/newfile.py:690b295714aed510803d3020da9c70fca8336def
> +  $ hg debugindex newdirname/newfile.py
> +     rev    offset  length   base linkrev nodeid       p1           p2
> +       0         0      88      0       3 34a4d536c0c0 000000000000 000000000000
> +
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2279,10 +2279,12 @@  def amend(ui, repo, commitfunc, old, ext
 
                 user = ctx.user()
                 date = ctx.date()
                 # Recompute copies (avoid recording a -> b -> a)
                 copied = copies.pathcopies(base, ctx)
+                if old.p2:
+                    copied.update(copies.pathcopies(old.p2(), ctx))
 
                 # Prune files which were reverted by the updates: if old
                 # introduced file X and our intermediate commit, node,
                 # renamed that file, then those two files are the same and
                 # we can discard X from our list of files. Likewise if X
diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t
--- a/tests/test-commit-amend.t
+++ b/tests/test-commit-amend.t
@@ -1055,5 +1055,68 @@  which was not far enough back in this ca
 Before the fix, the copy information was lost.
   $ hg status --copies --rev 0
   A a2
     a0
   R a0
+  $ cd ..
+
+Check that amend properly preserve rename from directory rename (issue-4516)
+
+If a parent of the merge renames a full directory, any files added to the old
+directory in the other parent will be renamed to the new directory. For some
+reason, the rename metadata was when amending such merge. This test ensure we
+do not regress. We have a dedicated repo because it needs a setup with renamed
+directory)
+
+  $ hg init issue4516
+  $ cd issue4516
+  $ mkdir olddirname
+  $ echo line1 > olddirname/commonfile.py
+  $ hg add olddirname/commonfile.py
+  $ hg ci -m first
+
+  $ hg branch newdirname
+  marked working directory as branch newdirname
+  (branches are permanent and global, did you want a bookmark?)
+  $ hg mv olddirname newdirname
+  moving olddirname/commonfile.py to newdirname/commonfile.py (glob)
+  $ hg ci -m rename
+
+  $ hg update default
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo line1 > olddirname/newfile.py
+  $ hg add olddirname/newfile.py
+  $ hg ci -m log
+
+  $ hg up newdirname
+  1 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ # create newdirname/newfile.py
+  $ hg merge default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg ci -m add
+  $ 
+  $ hg debugrename newdirname/newfile.py
+  newdirname/newfile.py renamed from olddirname/newfile.py:690b295714aed510803d3020da9c70fca8336def
+  $ hg status -C --change .
+  A newdirname/newfile.py
+  $ hg status -C --rev 1
+  A newdirname/newfile.py
+  $ hg status -C --rev 2
+  A newdirname/commonfile.py
+    olddirname/commonfile.py
+  A newdirname/newfile.py
+    olddirname/newfile.py
+  R olddirname/commonfile.py
+  R olddirname/newfile.py
+  $ hg debugindex newdirname/newfile.py
+     rev    offset  length   base linkrev nodeid       p1           p2
+       0         0      88      0       3 34a4d536c0c0 000000000000 000000000000
+
+  $ echo a >> newdirname/commonfile.py
+  $ hg ci --amend -m bug
+  $ hg debugrename newdirname/newfile.py
+  newdirname/newfile.py renamed from olddirname/newfile.py:690b295714aed510803d3020da9c70fca8336def
+  $ hg debugindex newdirname/newfile.py
+     rev    offset  length   base linkrev nodeid       p1           p2
+       0         0      88      0       3 34a4d536c0c0 000000000000 000000000000
+