Show More
@@ -158,8 +158,10 b' def archive(ui, repo, dest, **opts):' | |||||
158 | By default, the revision used is the parent of the working |
|
158 | By default, the revision used is the parent of the working | |
159 | directory; use -r/--rev to specify a different revision. |
|
159 | directory; use -r/--rev to specify a different revision. | |
160 |
|
160 | |||
161 | To specify the type of archive to create, use -t/--type. Valid |
|
161 | The archive type is automatically detected based on file | |
162 | types are: |
|
162 | extension (or override using -t/--type). | |
|
163 | ||||
|
164 | Valid types are: | |||
163 |
|
165 | |||
164 | :``files``: a directory full of files (default) |
|
166 | :``files``: a directory full of files (default) | |
165 | :``tar``: tar archive, uncompressed |
|
167 | :``tar``: tar archive, uncompressed | |
@@ -184,16 +186,32 b' def archive(ui, repo, dest, **opts):' | |||||
184 | dest = cmdutil.make_filename(repo, dest, node) |
|
186 | dest = cmdutil.make_filename(repo, dest, node) | |
185 | if os.path.realpath(dest) == repo.root: |
|
187 | if os.path.realpath(dest) == repo.root: | |
186 | raise util.Abort(_('repository root cannot be destination')) |
|
188 | raise util.Abort(_('repository root cannot be destination')) | |
187 | matchfn = cmdutil.match(repo, [], opts) |
|
189 | ||
188 | kind = opts.get('type') or 'files' |
|
190 | def guess_type(): | |
|
191 | exttypes = { | |||
|
192 | 'tar': ['.tar'], | |||
|
193 | 'tbz2': ['.tbz2', '.tar.bz2'], | |||
|
194 | 'tgz': ['.tgz', '.tar.gz'], | |||
|
195 | 'zip': ['.zip'], | |||
|
196 | } | |||
|
197 | ||||
|
198 | for type, extensions in exttypes.items(): | |||
|
199 | if any(dest.endswith(ext) for ext in extensions): | |||
|
200 | return type | |||
|
201 | return None | |||
|
202 | ||||
|
203 | kind = opts.get('type') or guess_type() or 'files' | |||
189 | prefix = opts.get('prefix') |
|
204 | prefix = opts.get('prefix') | |
|
205 | ||||
190 | if dest == '-': |
|
206 | if dest == '-': | |
191 | if kind == 'files': |
|
207 | if kind == 'files': | |
192 | raise util.Abort(_('cannot archive plain files to stdout')) |
|
208 | raise util.Abort(_('cannot archive plain files to stdout')) | |
193 | dest = sys.stdout |
|
209 | dest = sys.stdout | |
194 | if not prefix: |
|
210 | if not prefix: | |
195 | prefix = os.path.basename(repo.root) + '-%h' |
|
211 | prefix = os.path.basename(repo.root) + '-%h' | |
|
212 | ||||
196 | prefix = cmdutil.make_filename(repo, prefix, node) |
|
213 | prefix = cmdutil.make_filename(repo, prefix, node) | |
|
214 | matchfn = cmdutil.match(repo, [], opts) | |||
197 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), |
|
215 | archival.archive(repo, dest, node, kind, not opts.get('no_decode'), | |
198 | matchfn, prefix) |
|
216 | matchfn, prefix) | |
199 |
|
217 |
@@ -74,6 +74,20 b' bunzip2 -dc test.tar.bz2 | tar tf - 2>/d' | |||||
74 | hg archive -t tgz -p %b-%h test-%h.tar.gz |
|
74 | hg archive -t tgz -p %b-%h test-%h.tar.gz | |
75 | gzip -dc test-$QTIP.tar.gz | tar tf - 2>/dev/null | sed "s/$QTIP/TIP/" |
|
75 | gzip -dc test-$QTIP.tar.gz | tar tf - 2>/dev/null | sed "s/$QTIP/TIP/" | |
76 |
|
76 | |||
|
77 | hg archive autodetected_test.tar | |||
|
78 | tar tf autodetected_test.tar | |||
|
79 | ||||
|
80 | # The '-t' should override autodetection | |||
|
81 | hg archive -t tar autodetect_override_test.zip | |||
|
82 | tar tf autodetect_override_test.zip | |||
|
83 | ||||
|
84 | for ext in tar tar.gz tgz tar.bz2 tbz2 zip; do | |||
|
85 | hg archive auto_test.$ext | |||
|
86 | if [ -d auto_test.$ext ]; then | |||
|
87 | echo "extension $ext was not autodetected." | |||
|
88 | fi | |||
|
89 | done | |||
|
90 | ||||
77 | cat > md5comp.py <<EOF |
|
91 | cat > md5comp.py <<EOF | |
78 | try: |
|
92 | try: | |
79 | from hashlib import md5 |
|
93 | from hashlib import md5 |
@@ -45,6 +45,14 b' test-TIP/.hg_archival.txt' | |||||
45 | test-TIP/bar |
|
45 | test-TIP/bar | |
46 | test-TIP/baz/bletch |
|
46 | test-TIP/baz/bletch | |
47 | test-TIP/foo |
|
47 | test-TIP/foo | |
|
48 | autodetected_test/.hg_archival.txt | |||
|
49 | autodetected_test/bar | |||
|
50 | autodetected_test/baz/bletch | |||
|
51 | autodetected_test/foo | |||
|
52 | autodetect_override_test.zip/.hg_archival.txt | |||
|
53 | autodetect_override_test.zip/bar | |||
|
54 | autodetect_override_test.zip/baz/bletch | |||
|
55 | autodetect_override_test.zip/foo | |||
48 | True |
|
56 | True | |
49 | abort: archive prefix contains illegal components |
|
57 | abort: archive prefix contains illegal components | |
50 | Archive: test.zip |
|
58 | Archive: test.zip |
General Comments 0
You need to be logged in to leave comments.
Login now