convert: fix svn file copy detection code
authorPatrick Mezard <pmezard@gmail.com>
Mon, 14 Apr 2008 22:31:34 +0200
changeset 6546 075b2c9aed37
parent 6545 a7492fb2107b
child 6547 732c2259fc05
child 6549 2af1b9de62b3
convert: fix svn file copy detection code
hgext/convert/subversion.py
tests/test-convert-svn-branches.out
tests/test-convert-svn-move
tests/test-convert-svn-move.out
--- a/hgext/convert/subversion.py	Mon Apr 14 22:31:34 2008 +0200
+++ b/hgext/convert/subversion.py	Mon Apr 14 22:31:34 2008 +0200
@@ -553,20 +553,19 @@
             kind = svn.ra.check_path(self.ra, entrypath, revnum)
             if kind == svn.core.svn_node_file:
                 entries.append(self.recode(entry))
-
-                if not ent.copyfrom_path:
+                if not ent.copyfrom_path or not parents:
                     continue
-                copyfrom_path = self.getrelpath(ent.copyfrom_path)
+                # Copy sources not in parent revisions cannot be represented,
+                # ignore their origin for now
+                pmodule, prevnum = self.revsplit(parents[0])[1:]
+                if ent.copyfrom_rev < prevnum:
+                    continue
+                copyfrom_path = self.getrelpath(ent.copyfrom_path, pmodule)
                 if not copyfrom_path:
                     continue
                 self.ui.debug("copied to %s from %s@%s\n" %
                               (entrypath, copyfrom_path, ent.copyfrom_rev))
-                # It's probably important for hg that the source
-                # exists in the revision's parent, not just the
-                # ent.copyfrom_rev
-                fromkind = svn.ra.check_path(self.ra, copyfrom_path, ent.copyfrom_rev)
-                if fromkind != 0:
-                    copies[self.recode(entry)] = self.recode(copyfrom_path)
+                copies[self.recode(entry)] = self.recode(copyfrom_path)
             elif kind == 0: # gone, but had better be a deleted *file*
                 self.ui.debug("gone from %s\n" % ent.copyfrom_rev)
 
--- a/tests/test-convert-svn-branches.out	Mon Apr 14 22:31:34 2008 +0200
+++ b/tests/test-convert-svn-branches.out	Mon Apr 14 22:31:34 2008 +0200
@@ -117,7 +117,7 @@
 | | |
 | o |  branch= 3 change a files: a
 | | |
-| | o  branch=old 2 branch trunk, remove c files:
+| | o  branch=old 2 branch trunk, remove c files: a b
 | |/
 | o  branch= 1 hello files: a b c
 |/
--- a/tests/test-convert-svn-move	Mon Apr 14 22:31:34 2008 +0200
+++ b/tests/test-convert-svn-move	Mon Apr 14 22:31:34 2008 +0200
@@ -58,6 +58,8 @@
 svn rm subproject/trunk/d2
 svn ci -m "changeb and rm d2"
 svn mv $svnurl/subproject/trunk/d1 $svnurl/subproject/branches/d1 -m moved1again
+echo % copy a file from a past revision
+svn copy -r 7 $svnurl/subproject/trunk/d2/d $svnurl/subproject/trunk -m copyfilefrompast
 echo % copy a directory from a past revision
 svn copy -r 7 $svnurl/subproject/trunk/d2 $svnurl/subproject/trunk -m copydirfrompast
 cd ..
--- a/tests/test-convert-svn-move.out	Mon Apr 14 22:31:34 2008 +0200
+++ b/tests/test-convert-svn-move.out	Mon Apr 14 22:31:34 2008 +0200
@@ -60,24 +60,30 @@
 Committed revision 8.
 
 Committed revision 9.
+% copy a file from a past revision
+
+Committed revision 10.
 % copy a directory from a past revision
 
-Committed revision 10.
+Committed revision 11.
 % convert trunk and branches
 initializing destination A-hg repository
 scanning source...
 sorting...
 converting...
-8 createtrunk
+9 createtrunk
+8 moved1
 7 moved1
-6 moved1
-5 moved2
+6 moved2
+5 changeb and rm d2
 4 changeb and rm d2
-3 changeb and rm d2
+3 moved1again
 2 moved1again
-1 moved1again
+1 copyfilefrompast
 0 copydirfrompast
-o  8 copydirfrompast files: d2/d
+o  9 copydirfrompast files: d2/d
+|
+o  8 copyfilefrompast files: d
 |
 o  7 moved1again files: d1/b d1/c
 |
@@ -95,5 +101,5 @@
 |
 o  0 createtrunk files:
 
-default                        8:
+default                        9:
 d1                             6: