changeset 16553:9224cc2e99cc stable

amend: fix copy records handling (issue3410) Messing with the dirstate before the intermediate commit seems error prone. Instead, commit and recompute the copies with copies.pathcopies(), then use that with commitctx(). Since copies.pathcopies() does not support file replacement very well, the whole .renamed() condition in samefile() is removed and the "file replacement caused by differing copy source" effect is discarded. Test shamelessly stolen from Idan Kamara <idankk86@gmail.com>
author Patrick Mezard <patrick@mezard.eu>
date Mon, 30 Apr 2012 20:45:45 +0200
parents 90ca344a7c55
children ae2664ee0223
files mercurial/cmdutil.py tests/test-commit-amend.t
diffstat 2 files changed, 25 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Mon Apr 30 20:36:29 2012 +0200
+++ b/mercurial/cmdutil.py	Mon Apr 30 20:45:45 2012 +0200
@@ -1296,9 +1296,6 @@
 
     wlock = repo.wlock()
     try:
-        # Fix up dirstate for copies and renames
-        duplicatecopies(repo, None, base.node())
-
         # First, do a regular commit to record all changes in the working
         # directory (if there are any)
         node = commit(ui, repo, commitfunc, pats, opts)
@@ -1326,6 +1323,8 @@
             date = ctx.date()
             message = ctx.description()
             extra = ctx.extra()
+            # Recompute copies (avoid recording a -> b -> a)
+            copied = copies.pathcopies(base, ctx)
 
             # Prune files which were reverted by the updates: if old introduced
             # file X and our intermediate commit, node, renamed that file, then
@@ -1339,8 +1338,7 @@
                     if f in base.manifest():
                         b = base.filectx(f)
                         return (a.data() == b.data()
-                                and a.flags() == b.flags()
-                                and a.renamed() == b.renamed())
+                                and a.flags() == b.flags())
                     else:
                         return False
                 else:
@@ -1349,7 +1347,13 @@
 
             def filectxfn(repo, ctx_, path):
                 try:
-                    return ctx.filectx(path)
+                    fctx = ctx[path]
+                    flags = fctx.flags()
+                    mctx = context.memfilectx(fctx.path(), fctx.data(),
+                                              islink='l' in flags,
+                                              isexec='x' in flags,
+                                              copied=copied.get(path))
+                    return mctx
                 except KeyError:
                     raise IOError()
         else:
--- a/tests/test-commit-amend.t	Mon Apr 30 20:36:29 2012 +0200
+++ b/tests/test-commit-amend.t	Mon Apr 30 20:45:45 2012 +0200
@@ -293,11 +293,23 @@
   $ hg cp a f
   $ mv f.orig f
   $ hg ci --amend -m replacef
-  saved backup bundle to $TESTTMP/.hg/strip-backup/0ce2c92dc50d-amend-backup.hg
+  saved backup bundle to $TESTTMP/.hg/strip-backup/20a7413547f9-amend-backup.hg
   $ hg st --change . --copies
-  M f
   $ hg log -r . --template "{file_copies}\n"
-  f (a)
+  
+
+Move added file (issue3410):
+
+  $ echo g >> g
+  $ hg ci -Am g
+  adding g
+  $ hg mv g h
+  $ hg ci --amend
+  saved backup bundle to $TESTTMP/.hg/strip-backup/5daa77a5d616-amend-backup.hg
+  $ hg st --change . --copies h
+  A h
+  $ hg log -r . --template "{file_copies}\n"
+  
 
 Can't rollback an amend: