comparison mercurial/commands.py @ 10650:9ea7238ad935

archive: autodetect archive type by extension (issue2058)
author David Wolever <david@wolever.net>
date Thu, 11 Mar 2010 15:52:17 +0100
parents e13797685ee6
children 5f091fc1bab7
comparison
equal deleted inserted replaced
10649:e13797685ee6 10650:9ea7238ad935
156 '''create an unversioned archive of a repository revision 156 '''create an unversioned archive of a repository revision
157 157
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
166 :``tbz2``: tar archive, compressed using bzip2 168 :``tbz2``: tar archive, compressed using bzip2
167 :``tgz``: tar archive, compressed using gzip 169 :``tgz``: tar archive, compressed using gzip
182 raise util.Abort(_('no working directory: please specify a revision')) 184 raise util.Abort(_('no working directory: please specify a revision'))
183 node = ctx.node() 185 node = ctx.node()
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
200 def backout(ui, repo, node=None, rev=None, **opts): 218 def backout(ui, repo, node=None, rev=None, **opts):
201 '''reverse effect of earlier changeset 219 '''reverse effect of earlier changeset