Merge with crew-stable
authorPatrick Mezard <pmezard@gmail.com>
Sun, 04 Oct 2009 23:16:54 +0200
changeset 9541 53a95a744812
parent 9540 cad36e496640 (current diff)
parent 9527 b3c13e721593 (diff)
child 9542 5287de171d74
Merge with crew-stable
hgext/convert/darcs.py
--- a/hgext/convert/darcs.py	Sun Oct 04 12:18:43 2009 +0200
+++ b/hgext/convert/darcs.py	Sun Oct 04 23:16:54 2009 +0200
@@ -85,6 +85,17 @@
         self.checkexit(fp.close())
         return etree.getroot()
 
+    def manifest(self):
+        man = []
+        output, status = self.run('show', 'files', no_directories=True,
+                                  repodir=self.tmppath)
+        self.checkexit(status)
+        for line in output.split('\n'):
+            path = line[2:]
+            if path:
+                man.append(path)
+        return man
+
     def getheads(self):
         return self.parents[None]
 
@@ -107,18 +118,35 @@
             output, status = self.run('revert', all=True, repodir=self.tmppath)
             self.checkexit(status, output)
 
-    def getchanges(self, rev):
-        self.pull(rev)
+    def getchanges(self, rev):        
         copies = {}
         changes = []
+        man = None
         for elt in self.changes[rev].find('summary').getchildren():
             if elt.tag in ('add_directory', 'remove_directory'):
                 continue
             if elt.tag == 'move':
-                changes.append((elt.get('from'), rev))
-                copies[elt.get('from')] = elt.get('to')
+                if man is None:
+                    man = self.manifest()
+                source, dest = elt.get('from'), elt.get('to')
+                if source in man:
+                    # File move
+                    changes.append((source, rev))
+                    changes.append((dest, rev))
+                    copies[dest] = source
+                else:
+                    # Directory move, deduce file moves from manifest
+                    source = source + '/'
+                    for f in man:
+                        if not f.startswith(source):
+                            continue
+                        fdest = dest + '/' + f[len(source):]
+                        changes.append((f, rev))
+                        changes.append((fdest, rev))
+                        copies[fdest] = f
             else:
                 changes.append((elt.text.strip(), rev))
+        self.pull(rev)
         self.lastrev = rev
         return sorted(changes), copies
 
--- a/tests/test-convert-darcs	Sun Oct 04 12:18:43 2009 +0200
+++ b/tests/test-convert-darcs	Sun Oct 04 23:16:54 2009 +0200
@@ -43,7 +43,19 @@
 darcs pull -a ../darcs-clone
 sleep 1
 echo e > a
+echo f > f
+mkdir dir
+echo d > dir/d
+echo d > dir/d2
 darcs record -a -l -m p2
+
+echo % test file and directory move
+darcs mv f ff
+# Test remove + move
+darcs remove dir/d2
+rm dir/d2
+darcs mv dir dir2
+darcs record -a -l -m p3
 cd ..
 
 glog()
--- a/tests/test-convert-darcs.out	Sun Oct 04 12:18:43 2009 +0200
+++ b/tests/test-convert-darcs.out	Sun Oct 04 23:16:54 2009 +0200
@@ -10,15 +10,20 @@
 ./a
 Finished pulling and applying.
 Finished recording patch 'p2'
+% test file and directory move
+Finished recording patch 'p3'
 initializing destination darcs-repo-hg repository
 scanning source...
 sorting...
 converting...
-3 p0
-2 p1.2
-1 p1.1
-0 p2
-o  3 "p2" files: a
+4 p0
+3 p1.2
+2 p1.1
+1 p2
+0 p3
+o  4 "p3" files: dir/d dir/d2 dir2/d f ff
+|
+o  3 "p2" files: a dir/d dir/d2 f
 |
 o  2 "p1.1" files:
 |
@@ -28,3 +33,5 @@
 
 7225b30cdf38257d5cc7780772c051b6f33e6d6b 644   a
 1e88685f5ddec574a34c70af492f95b6debc8741 644   b
+d278f41640da5fc303a4cf9894af31c2983fc11d 644   dir2/d
+ef5c76581d78340f568d5f48d679bf307452cbc9 644   ff