copies: sort old names by depth
authorMatt Mackall <mpm@selenic.com>
Sat, 29 Mar 2008 12:39:47 -0500
changeset 6424 d8f44384c3ee
parent 6423 fb374b1b3911
child 6425 2d9328a2f81f
copies: sort old names by depth
mercurial/copies.py
tests/test-diff-copy-depth
tests/test-diff-copy-depth.out
--- a/mercurial/copies.py	Sat Mar 29 12:39:47 2008 -0500
+++ b/mercurial/copies.py	Sat Mar 29 12:39:47 2008 -0500
@@ -35,22 +35,23 @@
     old = {}
     seen = {}
     orig = fctx.path()
-    visit = [fctx]
+    visit = [(fctx, 0)]
     while visit:
-        fc = visit.pop()
+        fc, depth = visit.pop()
         s = str(fc)
         if s in seen:
             continue
         seen[s] = 1
         if fc.path() != orig and fc.path() not in old:
-            old[fc.path()] = 1
+            old[fc.path()] = (depth, fc.path()) # remember depth
         if fc.rev() < limit and fc.rev() is not None:
             continue
-        visit += fc.parents()
+        visit += [(p, depth - 1) for p in fc.parents()]
 
-    old = old.keys()
+    # return old names sorted by depth
+    old = old.values()
     old.sort()
-    return old
+    return [o[1] for o in old]
 
 def copies(repo, c1, c2, ca):
     """
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-diff-copy-depth	Sat Mar 29 12:39:47 2008 -0500
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+for i in aaa zzz; do
+    hg init t
+    cd t
+
+    echo "-- With $i"
+
+    touch file
+    hg add file
+    hg ci -m "Add"
+
+    hg cp file $i
+    hg ci -m "a -> $i"
+
+    hg cp $i other-file
+    echo "different" >> $i
+    hg ci -m "$i -> other-file"
+
+    hg cp other-file somename
+
+    echo "Status":
+    hg st -C
+    echo
+    echo "Diff:"
+    hg diff -g
+    echo
+
+    cd ..
+    rm -rf t
+done
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-diff-copy-depth.out	Sat Mar 29 12:39:47 2008 -0500
@@ -0,0 +1,20 @@
+-- With aaa
+Status:
+A somename
+  other-file
+
+Diff:
+diff --git a/other-file b/somename
+copy from other-file
+copy to somename
+
+-- With zzz
+Status:
+A somename
+  other-file
+
+Diff:
+diff --git a/other-file b/somename
+copy from other-file
+copy to somename
+