# HG changeset patch # User Patrick Mezard # Date 2012-04-30 18:45:45 # Node ID 9224cc2e99ccc19458ae873aaed7ba55fed1b1e7 # Parent 90ca344a7c550f062843dad4afa662dc873fba9c 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 diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -1296,9 +1296,6 @@ def amend(ui, repo, commitfunc, old, ext 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 @@ def amend(ui, repo, commitfunc, old, ext 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 @@ def amend(ui, repo, commitfunc, old, ext 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 amend(ui, repo, commitfunc, old, ext 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: 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 @@ -293,11 +293,23 @@ Follow copies/renames: $ 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: