changeset 3700:4c158de5f245

qrefresh: fix handling of copies in the fast path
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Mon, 20 Nov 2006 19:32:43 -0200
parents 4bafcf7aeb32
children 05c8704a3743
files hgext/mq.py tests/test-mq tests/test-mq.out
diffstat 3 files changed, 53 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Mon Nov 20 19:32:42 2006 -0200
+++ b/hgext/mq.py	Mon Nov 20 19:32:43 2006 -0200
@@ -989,6 +989,9 @@
             # 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 @@
                        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.
--- a/tests/test-mq	Mon Nov 20 19:32:42 2006 -0200
+++ b/tests/test-mq	Mon Nov 20 19:32:43 2006 -0200
@@ -227,6 +227,9 @@
 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 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 .
--- a/tests/test-mq.out	Mon Nov 20 19:32:42 2006 -0200
+++ b/tests/test-mq.out	Mon Nov 20 19:32:43 2006 -0200
@@ -222,6 +222,16 @@
 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 @@
 @@ -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)