diff --git a/mercurial/archival.py b/mercurial/archival.py --- a/mercurial/archival.py +++ b/mercurial/archival.py @@ -35,6 +35,20 @@ def tidyprefix(dest, prefix, suffixes): raise util.Abort(_('archive prefix contains illegal components')) return prefix +exts = { + 'tar': ['.tar'], + 'tbz2': ['.tbz2', '.tar.bz2'], + 'tgz': ['.tgz', '.tar.gz'], + 'zip': ['.zip'], + } + +def guesskind(dest): + for kind, extensions in exts.iteritems(): + if util.any(dest.endswith(ext) for ext in extensions): + return kind + return None + + class tarit(object): '''write archive to tar file or stream. can write uncompressed, or compress with gzip or bzip2.''' diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -196,20 +196,7 @@ def archive(ui, repo, dest, **opts): if os.path.realpath(dest) == repo.root: raise util.Abort(_('repository root cannot be destination')) - def guess_type(): - exttypes = { - 'tar': ['.tar'], - 'tbz2': ['.tbz2', '.tar.bz2'], - 'tgz': ['.tgz', '.tar.gz'], - 'zip': ['.zip'], - } - - for type, extensions in exttypes.items(): - if util.any(dest.endswith(ext) for ext in extensions): - return type - return None - - kind = opts.get('type') or guess_type() or 'files' + kind = opts.get('type') or archival.guesskind(dest) or 'files' prefix = opts.get('prefix') if dest == '-':