[PATCH 2 of 2 STABLE] import: handle git renames and --similarity (issue3187)
Patrick Mezard
patrick at mezard.eu
Thu Feb 16 12:06:05 UTC 2012
# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1329393822 -3600
# Branch stable
# Node ID 7055b1fe6c23d2f7710b8b56a18384fcc71fb562
# Parent bf3f2bbe11bc76124b9d8fa98ed71ed2ed41d60b
import: handle git renames and --similarity (issue3187)
There is no reason to discard copy sources from the set of files considered by
addremove(). It was done to handle the case where a first patch would create
'a' and a second one would move 'a' to 'b'. If these patches were applied with
--no-commit, 'a' would first be marked as added, then unlinked and dropped from
the dirstate but still passed to addremove(). A better fix is thus to exclude
removed files which ends being dropped from the dirstate instead of removed.
Reported by Jason Harris <jason at jasonfharris.com>
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -475,9 +475,15 @@
addremoved = set(self.changed)
for src, dst in self.copied:
scmutil.dirstatecopy(self.ui, self.repo, wctx, src, dst)
- addremoved.discard(src)
- if (not self.similarity) and self.removed:
+ if self.removed:
wctx.forget(sorted(self.removed))
+ for f in self.removed:
+ if f not in self.repo.dirstate:
+ # File was deleted and no longer belongs to the
+ # dirstate, it was probably marked added then
+ # deleted, and should not be considered by
+ # addremove().
+ addremoved.discard(f)
if addremoved:
cwd = self.repo.getcwd()
if cwd:
diff --git a/tests/test-import-git.t b/tests/test-import-git.t
--- a/tests/test-import-git.t
+++ b/tests/test-import-git.t
@@ -401,6 +401,23 @@
A b
a
R a
+
+Renames, similarity and git diff
+
+ $ hg revert -aC
+ undeleting a
+ forgetting b
+ $ rm b
+ $ hg import --similarity 90 --no-commit - <<EOF
+ > diff --git a/a b/b
+ > rename from a
+ > rename to b
+ > EOF
+ applying patch from stdin
+ $ hg st --copies
+ A b
+ a
+ R a
$ cd ..
Pure copy with existing destination
diff --git a/tests/test-import.t b/tests/test-import.t
--- a/tests/test-import.t
+++ b/tests/test-import.t
@@ -659,7 +659,6 @@
applying ../rename.diff
patching file a
patching file b
- removing a
adding b
recording removal of a as rename to b (88% similar)
applied to working directory
@@ -675,7 +674,6 @@
applying ../rename.diff
patching file a
patching file b
- removing a
adding b
applied to working directory
$ hg st -C
More information about the Mercurial-devel
mailing list