archive: always use portable path component separators with subrepos stable
authorMatt Harbison <matt_harbison@yahoo.com>
Mon, 04 May 2015 22:33:29 -0400
branchstable
changeset 24924 41cd8171e58f
parent 24920 b5eb01500696
child 24931 c5d4f9cc8da7
child 24933 5bc506ee87d2
archive: always use portable path component separators with subrepos The previous behavior when archiving a subrepo 's' on Windows was to internally name the file under it 's\file', due to the use of vfs.reljoin(). When printing the file list from the archive on Windows or Linux, the file was named 's\\file'. The archive extracted OK on Windows, but if the archive was brought to a Linux system, it created a file named 's\file' instead of a directory 's' containing 'file'. *.zip format achives seemed not to have the problem, but this was definitely an issue with *.tgz archives. Largefiles actually got this right, but a test is added to keep this from regressing. The subrepo-deep-nested-change.t test was repurposed to archive to a file, since there are several subsequent tests that archive to a directory. The output change is losing the filesystem prefix '../archive_lf' and not listing the directories 'sub1' and 'sub1/sub2'.
mercurial/subrepo.py
tests/test-subrepo-deep-nested-change.t
tests/test-subrepo-git.t
tests/test-subrepo-recursion.t
--- a/mercurial/subrepo.py	Wed Apr 22 15:53:03 2015 -0700
+++ b/mercurial/subrepo.py	Mon May 04 22:33:29 2015 -0400
@@ -517,7 +517,7 @@
             flags = self.fileflags(name)
             mode = 'x' in flags and 0755 or 0644
             symlink = 'l' in flags
-            archiver.addfile(self.wvfs.reljoin(prefix, self._path, name),
+            archiver.addfile(prefix + self._path + '/' + name,
                              mode, symlink, self.filedata(name))
             self.ui.progress(_('archiving (%s)') % relpath, i + 1,
                              unit=_('files'), total=total)
@@ -731,8 +731,7 @@
         for subpath in ctx.substate:
             s = subrepo(ctx, subpath)
             submatch = matchmod.narrowmatcher(subpath, match)
-            total += s.archive(
-                archiver, self.wvfs.reljoin(prefix, self._path), submatch)
+            total += s.archive(archiver, prefix + self._path + '/', submatch)
         return total
 
     @annotatesubrepoerror
@@ -1675,7 +1674,7 @@
                 data = info.linkname
             else:
                 data = tar.extractfile(info).read()
-            archiver.addfile(self.wvfs.reljoin(prefix, self._path, info.name),
+            archiver.addfile(prefix + self._path + '/' + info.name,
                              info.mode, info.issym(), data)
             total += 1
             self.ui.progress(_('archiving (%s)') % relpath, i + 1,
--- a/tests/test-subrepo-deep-nested-change.t	Wed Apr 22 15:53:03 2015 -0700
+++ b/tests/test-subrepo-deep-nested-change.t	Mon May 04 22:33:29 2015 -0400
@@ -309,21 +309,17 @@
 
 Exclude normal files from main and sub-sub repo
 
-  $ hg --config extensions.largefiles= archive -S -X '**.txt' ../archive_lf
-  $ find ../archive_lf | sort
-  ../archive_lf
-  ../archive_lf/.hgsub
-  ../archive_lf/.hgsubstate
-  ../archive_lf/large.bin
-  ../archive_lf/main
-  ../archive_lf/sub1
-  ../archive_lf/sub1/.hgsub
-  ../archive_lf/sub1/.hgsubstate
-  ../archive_lf/sub1/sub1
-  ../archive_lf/sub1/sub2
-  ../archive_lf/sub1/sub2/large.bin
-  ../archive_lf/sub1/sub2/sub2
-  $ rm -rf ../archive_lf
+  $ hg --config extensions.largefiles= archive -S -X '**.txt' ../archive_lf.tgz
+  $ tar -tzf ../archive_lf.tgz | sort
+  archive_lf/.hgsub
+  archive_lf/.hgsubstate
+  archive_lf/large.bin
+  archive_lf/main
+  archive_lf/sub1/.hgsub
+  archive_lf/sub1/.hgsubstate
+  archive_lf/sub1/sub1
+  archive_lf/sub1/sub2/large.bin
+  archive_lf/sub1/sub2/sub2
 
 Include normal files from within a largefiles subrepo
 
--- a/tests/test-subrepo-git.t	Wed Apr 22 15:53:03 2015 -0700
+++ b/tests/test-subrepo-git.t	Mon May 04 22:33:29 2015 -0400
@@ -325,6 +325,14 @@
   ../archive_x/s
   ../archive_x/s/g
 
+  $ hg -R ../tc archive -S ../archive.tgz 2>/dev/null
+  $ tar -tzf ../archive.tgz | sort
+  archive/.hg_archival.txt
+  archive/.hgsub
+  archive/.hgsubstate
+  archive/a
+  archive/s/g
+
 create nested repo
 
   $ cd ..
--- a/tests/test-subrepo-recursion.t	Wed Apr 22 15:53:03 2015 -0700
+++ b/tests/test-subrepo-recursion.t	Mon May 04 22:33:29 2015 -0400
@@ -434,6 +434,18 @@
   cloning subrepo foo/bar from $TESTTMP/repo/foo/bar (glob)
 #endif
 
+Archive + subrepos uses '/' for all component separators
+
+  $ tar -tzf ../archive.tar.gz | sort
+  archive/.hg_archival.txt
+  archive/.hgsub
+  archive/.hgsubstate
+  archive/foo/.hgsub
+  archive/foo/.hgsubstate
+  archive/foo/bar/z.txt
+  archive/foo/y.txt
+  archive/x.txt
+
 The newly cloned subrepos contain no working copy:
 
   $ hg -R foo summary