# HG changeset patch # User Patrick Mezard # Date 1240316249 -7200 # Node ID 3cdf4872941a9ebcbb91b5c3157b6c0ac4d7ad54 # Parent 6c3b8132078edf1b03bf95fe73cb1ccd2c08b47f convert/mtn: handle new files in moved directories (issue1619) Reported and investigated by Paul Aurich diff -r 6c3b8132078e -r 3cdf4872941a hgext/convert/monotone.py --- a/hgext/convert/monotone.py Sat Mar 28 12:24:53 2009 -0400 +++ b/hgext/convert/monotone.py Tue Apr 21 14:17:29 2009 +0200 @@ -108,13 +108,6 @@ certs[name] = value return certs - def mtnrenamefiles(self, files, fromdir, todir): - renamed = {} - for tofile in files: - if tofile.startswith(todir + '/'): - renamed[tofile] = fromdir + tofile[len(todir):] - return renamed - # implement the converter_source interface: def getheads(self): @@ -127,15 +120,17 @@ #revision = self.mtncmd("get_revision %s" % rev).split("\n\n") revision = self.mtnrun("get_revision", rev).split("\n\n") files = {} + addedfiles = {} + renameddirs = [] copies = {} for e in revision: m = self.add_file_re.match(e) if m: files[m.group(1)] = rev + addedfiles[m.group(1)] = rev m = self.patch_re.match(e) if m: files[m.group(1)] = rev - # Delete/rename is handled later when the convert engine # discovers an IOError exception from getfile, # but only if we add the "from" file to the list of changes. @@ -150,14 +145,26 @@ copies[toname] = fromname files[toname] = rev files[fromname] = rev - if self.mtnisdir(toname, rev): - renamed = self.mtnrenamefiles(self.files, fromname, toname) - 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 + elif self.mtnisdir(toname, rev): + renameddirs.append((fromname, toname)) + + # Directory renames can be handled only once we have recorded + # all new files + for fromdir, todir in renameddirs: + renamed = {} + for tofile in self.files: + if tofile in addedfiles: + continue + if tofile.startswith(todir + '/'): + renamed[tofile] = fromdir + tofile[len(todir):] + 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) def getmode(self, name, rev): diff -r 6c3b8132078e -r 3cdf4872941a tests/test-convert-mtn --- a/tests/test-convert-mtn Sat Mar 28 12:24:53 2009 -0400 +++ b/tests/test-convert-mtn Tue Apr 21 14:17:29 2009 +0200 @@ -33,9 +33,10 @@ echo a > a mkdir dir echo b > dir/b +echo d > dir/d python -c 'file("bin", "wb").write("a\\x00b")' echo c > c -mtn add a dir/b c bin +mtn add a dir/b dir/d c bin mtn ci -m initialize echo % update monotone working directory mtn mv a dir/a @@ -66,6 +67,9 @@ mtn ci -m movedir1 echo '% test subdirectory move' mtn mv dir dir2 +echo newfile > dir2/newfile +mtn drop dir2/d +mtn add dir2/newfile mtn ci -m movedir # Test directory removal with empty directory mkdir dir2/dir @@ -102,5 +106,7 @@ 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 +echo % check file remove with directory move +hg manifest -r 5 exit 0 diff -r 6c3b8132078e -r 3cdf4872941a tests/test-convert-mtn.out --- a/tests/test-convert-mtn.out Sat Mar 28 12:24:53 2009 -0400 +++ b/tests/test-convert-mtn.out Tue Apr 21 14:17:29 2009 +0200 @@ -5,14 +5,15 @@ mtn: adding c to workspace manifest mtn: adding dir to workspace manifest mtn: adding dir/b to workspace manifest +mtn: adding dir/d to workspace manifest mtn: beginning commit on branch 'com.selenic.test' -mtn: committed revision 803ef0bf815e35b951dbd4310acd1e45e675016e +mtn: committed revision 0f6e5e4f2e7d2a8ef312408f57618abf026afd90 % update monotone working directory mtn: skipping dir, already accounted for in workspace mtn: renaming a to dir/a in workspace manifest mtn: dropping c from workspace manifest mtn: beginning commit on branch 'com.selenic.test' -mtn: committed revision 4daf60753d6fe21a06ce5f716303fe55fd6d3a56 +mtn: committed revision 51d0a982464573a2a2cf5ee2c9219c652aaebeff % convert once assuming destination repo.mtn-hg initializing destination repo.mtn-hg repository @@ -25,7 +26,7 @@ mtn: dropping dir/b from workspace manifest mtn: renaming bin to bin2 in workspace manifest mtn: beginning commit on branch 'com.selenic.test' -mtn: committed revision 6c6977a6ef609ec80e40779f89dbd2772c96de62 +mtn: committed revision ebe58335d85d8cb176b6d0a12be04f5314b998da % test directory move mtn: adding dir1 to workspace manifest mtn: adding dir1/subdir1 to workspace manifest @@ -33,23 +34,25 @@ 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: committed revision a8d62bc04fee4d2936d28e98bbcc81686dd74306 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 +mtn: committed revision 2c3d241bbbfe538b1b51d910f5676407e3f4d3a6 % test subdirectory move mtn: renaming dir to dir2 in workspace manifest +mtn: dropping dir2/d from workspace manifest +mtn: adding dir2/newfile to workspace manifest mtn: beginning commit on branch 'com.selenic.test' -mtn: committed revision a85290b81fc4a8fbce4dc4d956404109842b406e +mtn: committed revision fdb5a02dae8bfce3a79b3393680af471016e1b4c mtn: beginning commit on branch 'com.selenic.test' -mtn: committed revision 7e3c8746060117104f16ff2d9212cf0f810cbff0 +mtn: committed revision 8bbf76d717001d24964e4604739fdcd0f539fc88 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 a97e0433d041a6d253c5dc27e080d544e55d9c19 +mtn: committed revision 2323d4bc324e6c82628dc04d47a9fd32ad24e322 % convert incrementally assuming destination repo.mtn-hg scanning source... @@ -61,12 +64,12 @@ 2 movedir 1 emptydir 0 dropdirectory -5 files updated, 0 files merged, 0 files removed, 0 files unresolved +6 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 5 "movedir" files: dir/a dir2/a +o 5 "movedir" files: dir/a dir/d dir2/a dir2/newfile | o 4 "movedir1" files: dir1/subdir1/file1 dir1/subdir2/file1 | @@ -76,13 +79,14 @@ | o 1 "update1" files: a bin c dir/a dir/b | -o 0 "initialize" files: a bin c dir/b +o 0 "initialize" files: a bin c dir/b dir/d % manifest bin2 dir1/subdir2/file1 dir1/subdir2_other/file1 dir2/a +dir2/newfile e % contents a @@ -92,7 +96,15 @@ % check directory move bin2 dir/a +dir/d dir1/subdir2/file1 dir1/subdir2_other/file1 e copies: dir1/subdir2/file1 (dir1/subdir1/file1) +% check file remove with directory move +bin2 +dir1/subdir2/file1 +dir1/subdir2_other/file1 +dir2/a +dir2/newfile +e