archive: drop the leading '.' path component from the prefix (
issue4634)
Unix utilities like tar will happily prefix the files it packs with './', but
annoyingly, Windows Explorer will not show these packed files when it opens the
archive. Since there doesn't seem to be a point in including './' in the path
names, just drop it. The default 'hg archive' prefix is the basename of the
archive, so specifying '.' allows for that default to be disabled completely.
--- a/mercurial/archival.py Thu May 07 13:47:45 2015 -0500
+++ b/mercurial/archival.py Tue May 05 20:52:38 2015 -0400
@@ -37,6 +37,10 @@
prefix = util.pconvert(lpfx)
if not prefix.endswith('/'):
prefix += '/'
+ # Drop the leading '.' path component if present, so Windows can read the
+ # zip files (issue4634)
+ if prefix.startswith('./'):
+ prefix = prefix[2:]
if prefix.startswith('../') or os.path.isabs(lpfx) or '/../' in prefix:
raise util.Abort(_('archive prefix contains illegal components'))
return prefix
--- a/tests/test-subrepo-deep-nested-change.t Thu May 07 13:47:45 2015 -0500
+++ b/tests/test-subrepo-deep-nested-change.t Tue May 05 20:52:38 2015 -0400
@@ -309,17 +309,17 @@
Exclude normal files from main and sub-sub repo
- $ hg --config extensions.largefiles= archive -S -X '**.txt' ../archive_lf.tgz
+ $ hg --config extensions.largefiles= archive -S -X '**.txt' -p '.' ../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
+ .hgsub
+ .hgsubstate
+ large.bin
+ main
+ sub1/.hgsub
+ sub1/.hgsubstate
+ sub1/sub1
+ sub1/sub2/large.bin
+ sub1/sub2/sub2
Include normal files from within a largefiles subrepo
--- a/tests/test-subrepo-git.t Thu May 07 13:47:45 2015 -0500
+++ b/tests/test-subrepo-git.t Tue May 05 20:52:38 2015 -0400
@@ -325,13 +325,13 @@
../archive_x/s
../archive_x/s/g
- $ hg -R ../tc archive -S ../archive.tgz 2>/dev/null
+ $ hg -R ../tc archive -S ../archive.tgz --prefix '.' 2>/dev/null
$ tar -tzf ../archive.tgz | sort
- archive/.hg_archival.txt
- archive/.hgsub
- archive/.hgsubstate
- archive/a
- archive/s/g
+ .hg_archival.txt
+ .hgsub
+ .hgsubstate
+ a
+ s/g
create nested repo
--- a/tests/test-subrepo-recursion.t Thu May 07 13:47:45 2015 -0500
+++ b/tests/test-subrepo-recursion.t Tue May 05 20:52:38 2015 -0400
@@ -312,7 +312,7 @@
Test archiving to zip file (unzip output is unstable):
- $ hg archive --subrepos ../archive.zip
+ $ hg archive --subrepos --prefix '.' ../archive.zip
\r (no-eol) (esc)
archiving [ ] 0/3\r (no-eol) (esc)
archiving [ ] 0/3\r (no-eol) (esc)
@@ -339,6 +339,20 @@
archiving (foo/bar) [================================>] 1/1\r (no-eol) (glob) (esc)
archiving (foo/bar) [================================>] 1/1\r (no-eol) (glob) (esc)
\r (no-eol) (esc)
+ $ unzip -l ../archive.zip
+ Archive: ../archive.zip
+ Length Date Time Name
+ --------- ---------- ----- ----
+ 172 01-01-1980 00:00 .hg_archival.txt
+ 10 01-01-1980 00:00 .hgsub
+ 45 01-01-1980 00:00 .hgsubstate
+ 3 01-01-1980 00:00 x.txt
+ 10 01-01-1980 00:00 foo/.hgsub
+ 45 01-01-1980 00:00 foo/.hgsubstate
+ 9 01-01-1980 00:00 foo/y.txt
+ 9 01-01-1980 00:00 foo/bar/z.txt
+ --------- -------
+ 303 8 files
Test archiving a revision that references a subrepo that is not yet
cloned:
@@ -363,7 +377,7 @@
$ cd ../empty
#if hardlink
- $ hg archive --subrepos -r tip ../archive.tar.gz
+ $ hg archive --subrepos -r tip --prefix './' ../archive.tar.gz
\r (no-eol) (esc)
archiving [ ] 0/3\r (no-eol) (esc)
archiving [ ] 0/3\r (no-eol) (esc)
@@ -413,7 +427,7 @@
#else
Note there's a slight output glitch on non-hardlink systems: the last
"linking" progress topic never gets closed, leading to slight output corruption on that platform.
- $ hg archive --subrepos -r tip ../archive.tar.gz
+ $ hg archive --subrepos -r tip --prefix './' ../archive.tar.gz
\r (no-eol) (esc)
archiving [ ] 0/3\r (no-eol) (esc)
archiving [ ] 0/3\r (no-eol) (esc)
@@ -437,14 +451,14 @@
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
+ .hg_archival.txt
+ .hgsub
+ .hgsubstate
+ foo/.hgsub
+ foo/.hgsubstate
+ foo/bar/z.txt
+ foo/y.txt
+ x.txt
The newly cloned subrepos contain no working copy: