archival: move commands.archive.guess_type to archival.guesskind
The list of suffixes for each kind of archive belongs in archival.
Renamed function to fit with out code style.
--- a/mercurial/archival.py Wed Jul 14 20:41:01 2010 +0200
+++ b/mercurial/archival.py Wed Jul 14 20:25:31 2010 +0200
@@ -35,6 +35,20 @@
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.'''
--- a/mercurial/commands.py Wed Jul 14 20:41:01 2010 +0200
+++ b/mercurial/commands.py Wed Jul 14 20:25:31 2010 +0200
@@ -196,20 +196,7 @@
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 == '-':