diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -989,6 +989,9 @@ class queue: # caching against the next repo.status call # mm, aa, dd, aa2, uu = repo.status(patchparent, tip)[:5] + changes = repo.changelog.read(tip) + man = repo.manifest.read(changes[0]) + aaa = aa[:] if opts.get('short'): filelist = mm + aa + dd else: @@ -1031,12 +1034,30 @@ class queue: opts=self.diffopts()) patchf.close() - changes = repo.changelog.read(tip) repo.dirstate.setparents(*cparents) - copies = [(f, repo.dirstate.copied(f)) for f in a] + copies = {} + for dst in a: + src = repo.dirstate.copied(dst) + if src is None: + continue + copies.setdefault(src, []).append(dst) repo.dirstate.update(a, 'a') - for dst, src in copies: - repo.dirstate.copy(src, dst) + # remember the copies between patchparent and tip + # this may be slow, so don't do it if we're not tracking copies + if self.diffopts().git: + for dst in aaa: + f = repo.file(dst) + src = f.renamed(man[dst]) + if src: + copies[src[0]] = copies.get(dst, []) + if dst in a: + copies[src[0]].append(dst) + # we can't copy a file created by the patch itself + if dst in copies: + del copies[dst] + for src, dsts in copies.iteritems(): + for dst in dsts: + repo.dirstate.copy(src, dst) repo.dirstate.update(r, 'r') # if the patch excludes a modified file, mark that file with mtime=0 # so status can see it. diff --git a/tests/test-mq b/tests/test-mq --- a/tests/test-mq +++ b/tests/test-mq @@ -227,6 +227,9 @@ hg up -C 1 hg qrefresh --git 2>&1 | grep -v 'saving bundle' cat .hg/patches/bar hg log -vC --template '{rev} {file_copies%filecopy}\n' -r . +hg qrefresh --git +cat .hg/patches/bar +hg log -vC --template '{rev} {file_copies%filecopy}\n' -r . echo hg up -C 1 @@ -238,3 +241,8 @@ hg mv baz bleh hg qrefresh --git 2>&1 | grep -v 'saving bundle' cat .hg/patches/bar hg log -vC --template '{rev} {file_copies%filecopy}\n' -r . +hg mv quux fred +hg mv bleh barney +hg qrefresh --git +cat .hg/patches/bar +hg log -vC --template '{rev} {file_copies%filecopy}\n' -r . diff --git a/tests/test-mq.out b/tests/test-mq.out --- a/tests/test-mq.out +++ b/tests/test-mq.out @@ -222,6 +222,16 @@ diff --git a/foo b/baz rename from foo rename to baz 2 baz (foo) +diff --git a/bar b/bar +new file mode 100644 +--- /dev/null ++++ b/bar +@@ -0,0 +1,1 @@ ++bar +diff --git a/foo b/baz +rename from foo +rename to baz +2 baz (foo) 1 files updated, 0 files merged, 2 files removed, 0 files unresolved 2 files updated, 0 files merged, 1 files removed, 0 files unresolved @@ -244,3 +254,13 @@ new file mode 100644 @@ -0,0 +1,1 @@ +bar 3 bleh (foo) +diff --git a/foo b/barney +rename from foo +rename to barney +diff --git a/fred b/fred +new file mode 100644 +--- /dev/null ++++ b/fred +@@ -0,0 +1,1 @@ ++bar +3 barney (foo)