changeset 9527:b3c13e721593

convert/darcs: handle directory renaming
author Patrick Mezard <pmezard@gmail.com>
date Sun, 04 Oct 2009 23:06:14 +0200
parents 457a30ed8ffb
children 314fc589b313 53a95a744812
files hgext/convert/darcs.py tests/test-convert-darcs tests/test-convert-darcs.out
diffstat 3 files changed, 42 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/darcs.py	Sun Oct 04 22:23:11 2009 +0200
+++ b/hgext/convert/darcs.py	Sun Oct 04 23:06:14 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,19 +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))
-                changes.append((elt.get('to'), rev))
-                copies[elt.get('to')] = elt.get('from')
+                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 22:23:11 2009 +0200
+++ b/tests/test-convert-darcs	Sun Oct 04 23:06:14 2009 +0200
@@ -44,10 +44,17 @@
 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 ..
 
--- a/tests/test-convert-darcs.out	Sun Oct 04 22:23:11 2009 +0200
+++ b/tests/test-convert-darcs.out	Sun Oct 04 23:06:14 2009 +0200
@@ -21,9 +21,9 @@
 2 p1.1
 1 p2
 0 p3
-o  4 "p3" files: f ff
+o  4 "p3" files: dir/d dir/d2 dir2/d f ff
 |
-o  3 "p2" files: a f
+o  3 "p2" files: a dir/d dir/d2 f
 |
 o  2 "p1.1" files:
 |
@@ -33,4 +33,5 @@
 
 7225b30cdf38257d5cc7780772c051b6f33e6d6b 644   a
 1e88685f5ddec574a34c70af492f95b6debc8741 644   b
+d278f41640da5fc303a4cf9894af31c2983fc11d 644   dir2/d
 ef5c76581d78340f568d5f48d679bf307452cbc9 644   ff