changeset 8050:087cc65bebff

convert/mtn: record changes from directory renames (issue1587) Bug report and initial path by Pavel Volkovitskiy <int@mtx.ru>
author Patrick Mezard <pmezard@gmail.com>
date Sat, 11 Apr 2009 23:12:42 +0200
parents 99e5f97c9a97
children 718c8f01feb2 976170068286
files hgext/convert/monotone.py tests/test-convert-mtn tests/test-convert-mtn.out
diffstat 3 files changed, 59 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/monotone.py	Sat Apr 04 20:39:46 2009 -0500
+++ b/hgext/convert/monotone.py	Sat Apr 11 23:12:42 2009 +0200
@@ -111,12 +111,10 @@
     def mtnrenamefiles(self, files, fromdir, todir):
         renamed = {}
         for tofile in files:
-            suffix = tofile.lstrip(todir)
-            if todir + suffix == tofile:
-                renamed[tofile] = (fromdir + suffix).lstrip("/")
+            if tofile.startswith(todir + '/'):
+                renamed[tofile] = fromdir + tofile[len(todir):]
         return renamed
 
-
     # implement the converter_source interface:
 
     def getheads(self):
@@ -157,6 +155,7 @@
                     for tofile, fromfile in renamed.items():
                         self.ui.debug (_("copying file in renamed dir from '%s' to '%s'") % (fromfile, tofile), '\n')
                         files[tofile] = rev
+                        copies[tofile] = fromfile
                     for fromfile in renamed.values():
                         files[fromfile] = rev
         return (files.items(), copies)
--- a/tests/test-convert-mtn	Sat Apr 04 20:39:46 2009 -0500
+++ b/tests/test-convert-mtn	Sat Apr 11 23:12:42 2009 +0200
@@ -55,7 +55,16 @@
 mtn drop dir/b
 mtn mv bin bin2
 mtn ci -m 'update2 "with" quotes'
-# Test directory move
+echo '% test directory move'
+mkdir -p dir1/subdir1
+mkdir -p dir1/subdir2_other
+echo file1 > dir1/subdir1/file1
+echo file2 > dir1/subdir2_other/file1
+mtn add dir1/subdir1/file1 dir1/subdir2_other/file1
+mtn ci -m createdir1
+mtn rename dir1/subdir1 dir1/subdir2
+mtn ci -m movedir1
+echo '% test subdirectory move'
 mtn mv dir dir2
 mtn ci -m movedir
 # Test directory removal with empty directory
@@ -85,5 +94,13 @@
 echo % contents
 cat dir2/a
 test -d dir2/dir && echo 'removed dir2/dir is still there!'
+
+echo % file move
+hg log -v -C -r 1 | grep copies
+echo % check directory move
+hg manifest -r 4
+test -d dir1/subdir2 || echo 'new dir1/subdir2 does not exist!'
+test -d dir1/subdir1 && echo 'renamed dir1/subdir1 is still there!'
+hg log -v -C -r 4 | grep copies
 exit 0
 
--- a/tests/test-convert-mtn.out	Sat Apr 04 20:39:46 2009 -0500
+++ b/tests/test-convert-mtn.out	Sat Apr 11 23:12:42 2009 +0200
@@ -26,32 +26,51 @@
 mtn: renaming bin to bin2 in workspace manifest
 mtn: beginning commit on branch 'com.selenic.test'
 mtn: committed revision 6c6977a6ef609ec80e40779f89dbd2772c96de62
+% test directory move
+mtn: adding dir1 to workspace manifest
+mtn: adding dir1/subdir1 to workspace manifest
+mtn: adding dir1/subdir1/file1 to workspace manifest
+mtn: adding dir1/subdir2_other to workspace manifest
+mtn: adding dir1/subdir2_other/file1 to workspace manifest
+mtn: beginning commit on branch 'com.selenic.test'
+mtn: committed revision e066b1feb2b7a7110450c2c18b5b4462011427d1
+mtn: skipping dir1, already accounted for in workspace
+mtn: renaming dir1/subdir1 to dir1/subdir2 in workspace manifest
+mtn: beginning commit on branch 'com.selenic.test'
+mtn: committed revision 2ad2409d25bb8d2583b57a3d4c0fa1df62aa1f79
+% test subdirectory move
 mtn: renaming dir to dir2 in workspace manifest
 mtn: beginning commit on branch 'com.selenic.test'
-mtn: committed revision 5de5abe7c15eae70cf3acdda23c9c319ea50c1af
+mtn: committed revision a85290b81fc4a8fbce4dc4d956404109842b406e
 mtn: beginning commit on branch 'com.selenic.test'
-mtn: committed revision 27a423be1e406595cc57f50f42a8790fa0a93d8e
+mtn: committed revision 7e3c8746060117104f16ff2d9212cf0f810cbff0
 mtn: dropping dir2/dir/subdir/f from workspace manifest
 mtn: dropping dir2/dir/subdir from workspace manifest
 mtn: dropping dir2/dir/emptydir from workspace manifest
 mtn: dropping dir2/dir from workspace manifest
 mtn: beginning commit on branch 'com.selenic.test'
-mtn: committed revision ba57ba5ac63178529d37fa8a2a1a012fc0e42047
+mtn: committed revision a97e0433d041a6d253c5dc27e080d544e55d9c19
 % convert incrementally
 assuming destination repo.mtn-hg
 scanning source...
 sorting...
 converting...
-3 update2 "with" quotes
+5 update2 "with" quotes
+4 createdir1
+3 movedir1
 2 movedir
 1 emptydir
 0 dropdirectory
-3 files updated, 0 files merged, 0 files removed, 0 files unresolved
-@  5 "dropdirectory" files: dir2/dir/subdir/f
+5 files updated, 0 files merged, 0 files removed, 0 files unresolved
+@  7 "dropdirectory" files: dir2/dir/subdir/f
+|
+o  6 "emptydir" files: dir2/dir/subdir/f
 |
-o  4 "emptydir" files: dir2/dir/subdir/f
+o  5 "movedir" files: dir/a dir2/a
 |
-o  3 "movedir" files: dir/a dir2/a
+o  4 "movedir1" files: dir1/subdir1/file1 dir1/subdir2/file1
+|
+o  3 "createdir1" files: dir1/subdir1/file1 dir1/subdir2_other/file1
 |
 o  2 "update2 "with" quotes" files: bin bin2 dir/b e
 |
@@ -61,8 +80,19 @@
 
 % manifest
 bin2
+dir1/subdir2/file1
+dir1/subdir2_other/file1
 dir2/a
 e
 % contents
 a
 a
+% file move
+copies:      dir/a (a)
+% check directory move
+bin2
+dir/a
+dir1/subdir2/file1
+dir1/subdir2_other/file1
+e
+copies:      dir1/subdir2/file1 (dir1/subdir1/file1)