changeset 8100:233f11b544f5

Merge with crew-stable
author Patrick Mezard <pmezard@gmail.com>
date Tue, 21 Apr 2009 14:25:36 +0200
parents 6a6ce1df98d2 (current diff) 3cdf4872941a (diff)
children 18710802cd49
files hgext/convert/monotone.py
diffstat 3 files changed, 54 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/monotone.py	Tue Apr 21 09:56:07 2009 +0100
+++ b/hgext/convert/monotone.py	Tue Apr 21 14:25:36 2009 +0200
@@ -114,13 +114,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):
@@ -133,15 +126,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.
@@ -156,16 +151,27 @@
                     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 directory "
-                                         "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 directory "
+                                 "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):
--- a/tests/test-convert-mtn	Tue Apr 21 09:56:07 2009 +0100
+++ b/tests/test-convert-mtn	Tue Apr 21 14:25:36 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
 
--- a/tests/test-convert-mtn.out	Tue Apr 21 09:56:07 2009 +0100
+++ b/tests/test-convert-mtn.out	Tue Apr 21 14:25:36 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