# HG changeset patch # User Patrick Mezard # Date 2009-04-11 21:12:42 # Node ID 087cc65bebffbd07838c4f303f5799cbd0b0b72b # Parent 99e5f97c9a9782ba0a6f8ea2bdb3c55e8c5814fa convert/mtn: record changes from directory renames (issue1587) Bug report and initial path by Pavel Volkovitskiy diff --git a/hgext/convert/monotone.py b/hgext/convert/monotone.py --- a/hgext/convert/monotone.py +++ b/hgext/convert/monotone.py @@ -111,12 +111,10 @@ class monotone_source(converter_source, 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 @@ class monotone_source(converter_source, 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) diff --git a/tests/test-convert-mtn b/tests/test-convert-mtn --- a/tests/test-convert-mtn +++ b/tests/test-convert-mtn @@ -55,7 +55,16 @@ mtn add e 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 @@ hg manifest 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 diff --git a/tests/test-convert-mtn.out b/tests/test-convert-mtn.out --- a/tests/test-convert-mtn.out +++ b/tests/test-convert-mtn.out @@ -26,32 +26,51 @@ mtn: dropping dir/b from workspace manif 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 @@ o 0 "initialize" files: a bin c dir/b % 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)