Patchwork [STABLE] archive: always use portable path component separators with subrepos

login
register
mail settings
Submitter Matt Harbison
Date May 5, 2015, 3:52 a.m.
Message ID <a5badc8a9ff5b5a94ff1.1430797960@Envy>
Download mbox | patch
Permalink /patch/8891/
State Accepted
Headers show

Comments

Matt Harbison - May 5, 2015, 3:52 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1430793209 14400
#      Mon May 04 22:33:29 2015 -0400
# Branch stable
# Node ID a5badc8a9ff5b5a94ff11d4ee1b18899c6bebda5
# Parent  a4ee6f774f14b68e8dc887745699ba6a2ae28355
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'.
Augie Fackler - May 5, 2015, 1:59 p.m.
On Mon, May 04, 2015 at 11:52:40PM -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1430793209 14400
> #      Mon May 04 22:33:29 2015 -0400
> # Branch stable
> # Node ID a5badc8a9ff5b5a94ff11d4ee1b18899c6bebda5
> # Parent  a4ee6f774f14b68e8dc887745699ba6a2ae28355
> archive: always use portable path component separators with subrepos

queued for stable, thanks

>
> 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'.
>
> diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
> --- a/mercurial/subrepo.py
> +++ b/mercurial/subrepo.py
> @@ -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,
> diff --git a/tests/test-subrepo-deep-nested-change.t b/tests/test-subrepo-deep-nested-change.t
> --- a/tests/test-subrepo-deep-nested-change.t
> +++ b/tests/test-subrepo-deep-nested-change.t
> @@ -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
>
> diff --git a/tests/test-subrepo-git.t b/tests/test-subrepo-git.t
> --- a/tests/test-subrepo-git.t
> +++ b/tests/test-subrepo-git.t
> @@ -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 ..
> diff --git a/tests/test-subrepo-recursion.t b/tests/test-subrepo-recursion.t
> --- a/tests/test-subrepo-recursion.t
> +++ b/tests/test-subrepo-recursion.t
> @@ -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
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -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,
diff --git a/tests/test-subrepo-deep-nested-change.t b/tests/test-subrepo-deep-nested-change.t
--- a/tests/test-subrepo-deep-nested-change.t
+++ b/tests/test-subrepo-deep-nested-change.t
@@ -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
 
diff --git a/tests/test-subrepo-git.t b/tests/test-subrepo-git.t
--- a/tests/test-subrepo-git.t
+++ b/tests/test-subrepo-git.t
@@ -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 ..
diff --git a/tests/test-subrepo-recursion.t b/tests/test-subrepo-recursion.t
--- a/tests/test-subrepo-recursion.t
+++ b/tests/test-subrepo-recursion.t
@@ -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