3 # Copyright (c) 2012 Felipe Contreras
6 # Inspired by Rocco Rutte's hg-fast-export
8 # Just copy to your ~/bin, or anywhere in your $PATH.
9 # Then you can clone with:
10 # git clone hg::/path/to/mercurial/repo/
12 # For remote repositories a local clone is stored in
13 # "$GIT_DIR/hg/origin/clone/.hg/".
15 from mercurial import hg, ui, bookmarks, context, encoding, node, error, extensions, discovery, util
25 import urlparse, hashlib
28 # If you are not in hg-git-compat mode and want to disable the tracking of
30 # git config --global remote-hg.track-branches false
32 # If you want the equivalent of hg's clone/pull--insecure option:
33 # git config --global remote-hg.insecure true
35 # If you want to switch to hg-git compatibility mode:
36 # git config --global remote-hg.hg-git-compat true
39 # Sensible defaults for git.
40 # hg bookmarks are exported as git branches, hg branches are prefixed
41 # with 'branches/', HEAD is a special case.
45 # Only hg bookmarks are exported as git branches.
46 # Commits are modified to preserve hg information and allow bidirectionality.
49 NAME_RE = re.compile('^([^<>]+)')
50 AUTHOR_RE = re.compile('^([^<>]+?)? ?<([^<>]*)>$')
51 EMAIL_RE = re.compile('^([^<>]+[^ \\\t<>])?\\b(?:[ \\t<>]*?)\\b([^ \\t<>]+@[^ \\t<>]+)')
52 AUTHOR_HG_RE = re.compile('^(.*?) ?<(.*?)(?:>(.+)?)?$')
53 RAW_AUTHOR_RE = re.compile('^(\w+) (?:(.+)? )?<(.*)> (\d+) ([+-]\d+)')
58 sys.stderr.write('ERROR: %s\n' % (msg % args))
62 sys.stderr.write('WARNING: %s\n' % (msg % args))
65 return 'l' in flags and '120000' or 'x' in flags and '100755' or '100644'
68 return '%+03d%02d' % (-tz / 3600, -tz % 3600 / 60)
71 m = { '100755': 'x', '120000': 'l' }
72 return m.get(mode, '')
81 return ref.replace('___', ' ')
84 return ref.replace(' ', '___')
86 def check_version(*check):
89 return hg_version >= check
91 def get_config(config):
92 cmd = ['git', 'config', '--get', config]
93 process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
94 output, _ = process.communicate()
97 def get_config_bool(config, default=False):
98 value = get_config(config).rstrip('\n')
101 elif value == "false":
108 def __init__(self, path, repo):
114 if self.version < VERSION:
115 if self.version == 1:
119 if self.version < VERSION:
121 self.version = VERSION
131 if not os.path.exists(self.path):
134 tmp = json.load(open(self.path))
136 self.tips = tmp['tips']
137 self.marks = tmp['marks']
138 self.last_mark = tmp['last-mark']
139 self.version = tmp.get('version', 1)
141 for rev, mark in self.marks.iteritems():
142 self.rev_marks[mark] = rev
144 def upgrade_one(self):
146 return hghex(self.repo.changelog.node(int(rev)))
147 self.tips = dict((name, get_id(rev)) for name, rev in self.tips.iteritems())
148 self.marks = dict((get_id(rev), mark) for rev, mark in self.marks.iteritems())
149 self.rev_marks = dict((mark, get_id(rev)) for mark, rev in self.rev_marks.iteritems())
153 return { 'tips': self.tips, 'marks': self.marks, 'last-mark' : self.last_mark, 'version' : self.version }
156 json.dump(self.dict(), open(self.path, 'w'))
159 return str(self.dict())
161 def from_rev(self, rev):
162 return self.marks[rev]
164 def to_rev(self, mark):
165 return str(self.rev_marks[mark])
169 return self.last_mark
171 def get_mark(self, rev):
173 self.marks[rev] = self.last_mark
174 return self.last_mark
176 def new_mark(self, rev, mark):
177 self.marks[rev] = mark
178 self.rev_marks[mark] = rev
179 self.last_mark = mark
181 def is_marked(self, rev):
182 return rev in self.marks
184 def get_tip(self, branch):
185 return str(self.tips[branch])
187 def set_tip(self, branch, tip):
188 self.tips[branch] = tip
192 def __init__(self, repo):
194 self.line = self.get_line()
197 return sys.stdin.readline().strip()
199 def __getitem__(self, i):
200 return self.line.split()[i]
202 def check(self, word):
203 return self.line.startswith(word)
205 def each_block(self, separator):
206 while self.line != separator:
208 self.line = self.get_line()
211 return self.each_block('')
214 self.line = self.get_line()
215 if self.line == 'done':
219 i = self.line.index(':') + 1
220 return int(self.line[i:])
223 if not self.check('data'):
225 i = self.line.index(' ') + 1
226 size = int(self.line[i:])
227 return sys.stdin.read(size)
229 def get_author(self):
233 m = RAW_AUTHOR_RE.match(self.line)
236 _, name, email, date, tz = m.groups()
237 if name and 'ext:' in name:
238 m = re.match('^(.+?) ext:\((.+)\)$', name)
241 ex = urllib.unquote(m.group(2))
243 if email != bad_mail:
245 user = '%s <%s>' % (name, email)
247 user = '<%s>' % (email)
255 tz = ((tz / 100) * 3600) + ((tz % 100) * 60)
256 return (user, int(date), -tz)
258 def fix_file_path(path):
259 if not os.path.isabs(path):
261 return os.path.relpath(path, '/')
263 def export_files(files):
264 global marks, filenodes
268 fid = node.hex(f.filenode())
271 mark = filenodes[fid]
273 mark = marks.next_mark()
274 filenodes[fid] = mark
278 print "mark :%u" % mark
279 print "data %d" % len(d)
282 path = fix_file_path(f.path())
283 final.append((gitmode(f.flags()), mark, path))
287 def get_filechanges(repo, ctx, parent):
292 # load earliest manifest first for caching reasons
293 prev = parent.manifest().copy()
298 if (cur.flags(fn) != prev.flags(fn) or cur[fn] != prev[fn]):
303 removed |= set(prev.keys())
305 return added | modified, removed
307 def fixup_user_git(user):
309 user = user.replace('"', '')
310 m = AUTHOR_RE.match(user)
313 mail = m.group(2).strip()
315 m = EMAIL_RE.match(user)
320 m = NAME_RE.match(user)
322 name = m.group(1).strip()
325 def fixup_user_hg(user):
327 # stole this from hg-git
328 return re.sub('[<>\n]', '?', name.lstrip('< ').rstrip('> '))
330 m = AUTHOR_HG_RE.match(user)
332 name = sanitize(m.group(1))
333 mail = sanitize(m.group(2))
336 name += ' ext:(' + urllib.quote(ex) + ')'
338 name = sanitize(user)
346 def fixup_user(user):
347 global mode, bad_mail
350 name, mail = fixup_user_git(user)
352 name, mail = fixup_user_hg(user)
359 return '%s <%s>' % (name, mail)
361 def updatebookmarks(repo, peer):
362 remotemarks = peer.listkeys('bookmarks')
363 localmarks = repo._bookmarks
368 for k, v in remotemarks.iteritems():
369 localmarks[k] = hgbin(v)
371 if hasattr(localmarks, 'write'):
374 bookmarks.write(repo)
376 def get_repo(url, alias):
380 myui.setconfig('ui', 'interactive', 'off')
381 myui.fout = sys.stderr
383 if get_config_bool('remote-hg.insecure'):
384 myui.setconfig('web', 'cacerts', '')
386 extensions.loadall(myui)
388 if hg.islocal(url) and not os.environ.get('GIT_REMOTE_HG_TEST_REMOTE'):
389 repo = hg.repository(myui, url)
390 if not os.path.exists(dirname):
393 shared_path = os.path.join(gitdir, 'hg')
394 if not os.path.exists(shared_path):
396 hg.clone(myui, {}, url, shared_path, update=False, pull=True)
398 die('Repository error')
400 if not os.path.exists(dirname):
403 local_path = os.path.join(dirname, 'clone')
404 if not os.path.exists(local_path):
405 hg.share(myui, shared_path, local_path, update=False)
407 repo = hg.repository(myui, local_path)
409 peer = hg.peer(myui, {}, url)
411 die('Repository error')
412 repo.pull(peer, heads=None, force=True)
414 updatebookmarks(repo, peer)
418 def rev_to_mark(rev):
420 return marks.from_rev(rev.hex())
422 def mark_to_rev(mark):
424 return marks.to_rev(mark)
426 def export_ref(repo, name, kind, head):
427 global prefix, marks, mode
429 ename = '%s/%s' % (kind, name)
431 tip = marks.get_tip(ename)
432 tip = repo[tip].rev()
436 revs = xrange(tip, head.rev() + 1)
444 if marks.is_marked(c.hex()):
447 (manifest, user, (time, tz), files, desc, extra) = repo.changelog.read(node)
448 rev_branch = extra['branch']
450 author = "%s %d %s" % (fixup_user(user), time, gittz(tz))
451 if 'committer' in extra:
452 user, time, tz = extra['committer'].rsplit(' ', 2)
453 committer = "%s %s %s" % (user, time, gittz(int(tz)))
457 parents = [repo[p] for p in repo.changelog.parentrevs(rev) if p >= 0]
459 if len(parents) == 0:
460 modified = c.manifest().keys()
463 modified, removed = get_filechanges(repo, c, parents[0])
470 if rev_branch != 'default':
471 extra_msg += 'branch : %s\n' % rev_branch
475 if f not in c.manifest():
477 rename = c.filectx(f).renamed()
479 renames.append((rename[0], f))
482 extra_msg += "rename : %s => %s\n" % e
484 for key, value in extra.iteritems():
485 if key in ('author', 'committer', 'encoding', 'message', 'branch', 'hg-git'):
488 extra_msg += "extra : %s : %s\n" % (key, urllib.quote(value))
491 desc += '\n--HG--\n' + extra_msg
493 if len(parents) == 0 and rev:
494 print 'reset %s/%s' % (prefix, ename)
496 modified_final = export_files(c.filectx(f) for f in modified)
498 print "commit %s/%s" % (prefix, ename)
499 print "mark :%d" % (marks.get_mark(c.hex()))
500 print "author %s" % (author)
501 print "committer %s" % (committer)
502 print "data %d" % (len(desc))
506 print "from :%s" % (rev_to_mark(parents[0]))
508 print "merge :%s" % (rev_to_mark(parents[1]))
511 print "D %s" % (fix_file_path(f))
512 for f in modified_final:
513 print "M %s :%u %s" % f
516 progress = (rev - tip)
517 if (progress % 100 == 0):
518 print "progress revision %d '%s' (%d/%d)" % (rev, name, progress, total)
520 # make sure the ref is updated
521 print "reset %s/%s" % (prefix, ename)
522 print "from :%u" % rev_to_mark(head)
525 marks.set_tip(ename, head.hex())
527 def export_tag(repo, tag):
528 export_ref(repo, tag, 'tags', repo[hgref(tag)])
530 def export_bookmark(repo, bmark):
531 head = bmarks[hgref(bmark)]
532 export_ref(repo, bmark, 'bookmarks', head)
534 def export_branch(repo, branch):
535 tip = get_branch_tip(repo, branch)
537 export_ref(repo, branch, 'branches', head)
539 def export_head(repo):
541 export_ref(repo, g_head[0], 'bookmarks', g_head[1])
543 def do_capabilities(parser):
544 global prefix, dirname
548 print "refspec refs/heads/branches/*:%s/branches/*" % prefix
549 print "refspec refs/heads/*:%s/bookmarks/*" % prefix
550 print "refspec refs/tags/*:%s/tags/*" % prefix
552 path = os.path.join(dirname, 'marks-git')
554 if os.path.exists(path):
555 print "*import-marks %s" % path
556 print "*export-marks %s" % path
561 def branch_tip(branch):
562 return branches[branch][-1]
564 def get_branch_tip(repo, branch):
567 heads = branches.get(hgref(branch), None)
571 # verify there's only one head
573 warn("Branch '%s' has more than one head, consider merging" % branch)
574 return branch_tip(hgref(branch))
578 def list_head(repo, cur):
579 global g_head, bmarks, fake_bmark
581 if 'default' not in branches:
585 node = repo[branch_tip('default')]
586 head = 'master' if not 'master' in bmarks else 'default'
591 print "@refs/heads/%s HEAD" % head
592 g_head = (head, node)
595 global branches, bmarks, track_branches
598 for bmark, node in bookmarks.listbookmarks(repo).iteritems():
599 bmarks[bmark] = repo[node]
601 cur = repo.dirstate.branch()
602 orig = peer if peer else repo
604 for branch, heads in orig.branchmap().iteritems():
606 heads = [h for h in heads if 'close' not in repo.changelog.read(h)[5]]
608 branches[branch] = heads
613 for branch in branches:
614 print "? refs/heads/branches/%s" % gitref(branch)
617 print "? refs/heads/%s" % gitref(bmark)
619 for tag, node in repo.tagslist():
622 print "? refs/tags/%s" % gitref(tag)
626 def do_import(parser):
629 path = os.path.join(dirname, 'marks-git')
632 if os.path.exists(path):
633 print "feature import-marks=%s" % path
634 print "feature export-marks=%s" % path
635 print "feature force"
638 tmp = encoding.encoding
639 encoding.encoding = 'utf-8'
641 # lets get all the import lines
642 while parser.check('import'):
647 elif ref.startswith('refs/heads/branches/'):
648 branch = ref[len('refs/heads/branches/'):]
649 export_branch(repo, branch)
650 elif ref.startswith('refs/heads/'):
651 bmark = ref[len('refs/heads/'):]
652 export_bookmark(repo, bmark)
653 elif ref.startswith('refs/tags/'):
654 tag = ref[len('refs/tags/'):]
655 export_tag(repo, tag)
659 encoding.encoding = tmp
663 def parse_blob(parser):
667 mark = parser.get_mark()
669 data = parser.get_data()
670 blob_marks[mark] = data
673 def get_merge_files(repo, p1, p2, files):
674 for e in repo[p1].files():
676 if e not in repo[p1].manifest():
678 f = { 'ctx' : repo[p1][e] }
681 def parse_commit(parser):
682 global marks, blob_marks, parsed_refs
685 from_mark = merge_mark = None
690 commit_mark = parser.get_mark()
692 author = parser.get_author()
694 committer = parser.get_author()
696 data = parser.get_data()
698 if parser.check('from'):
699 from_mark = parser.get_mark()
701 if parser.check('merge'):
702 merge_mark = parser.get_mark()
704 if parser.check('merge'):
705 die('octopus merges are not supported yet')
707 # fast-export adds an extra newline
714 if parser.check('M'):
715 t, m, mark_ref, path = line.split(' ', 3)
716 mark = int(mark_ref[1:])
717 f = { 'mode' : hgmode(m), 'data' : blob_marks[mark] }
718 elif parser.check('D'):
719 t, path = line.split(' ', 1)
720 f = { 'deleted' : True }
722 die('Unknown file command: %s' % line)
725 # only export the commits if we are on an internal proxy repo
726 if dry_run and not peer:
727 parsed_refs[ref] = None
730 def getfilectx(repo, memctx, f):
736 is_exec = of['mode'] == 'x'
737 is_link = of['mode'] == 'l'
738 rename = of.get('rename', None)
739 return context.memfilectx(f, of['data'],
740 is_link, is_exec, rename)
744 user, date, tz = author
747 if committer != author:
748 extra['committer'] = "%s %u %u" % committer
751 p1 = mark_to_rev(from_mark)
756 p2 = mark_to_rev(merge_mark)
761 # If files changed from any of the parents, hg wants to know, but in git if
762 # nothing changed from the first parent, nothing changed.
765 get_merge_files(repo, p1, p2, files)
767 # Check if the ref is supposed to be a named branch
768 if ref.startswith('refs/heads/branches/'):
769 branch = ref[len('refs/heads/branches/'):]
770 extra['branch'] = hgref(branch)
773 i = data.find('\n--HG--\n')
775 tmp = data[i + len('\n--HG--\n'):].strip()
776 for k, v in [e.split(' : ', 1) for e in tmp.split('\n')]:
778 old, new = v.split(' => ', 1)
779 files[new]['rename'] = old
783 ek, ev = v.split(' : ', 1)
784 extra[ek] = urllib.unquote(ev)
787 ctx = context.memctx(repo, (p1, p2), data,
788 files.keys(), getfilectx,
789 user, (date, tz), extra)
791 tmp = encoding.encoding
792 encoding.encoding = 'utf-8'
794 node = hghex(repo.commitctx(ctx))
796 encoding.encoding = tmp
798 parsed_refs[ref] = node
799 marks.new_mark(node, commit_mark)
801 def parse_reset(parser):
807 if parser.check('commit'):
810 if not parser.check('from'):
812 from_mark = parser.get_mark()
816 rev = mark_to_rev(from_mark)
819 parsed_refs[ref] = rev
821 def parse_tag(parser):
824 from_mark = parser.get_mark()
826 tagger = parser.get_author()
828 data = parser.get_data()
831 parsed_tags[name] = (tagger, data)
833 def write_tag(repo, tag, node, msg, author):
834 branch = repo[node].branch()
835 tip = branch_tip(branch)
838 def getfilectx(repo, memctx, f):
840 fctx = tip.filectx(f)
842 except error.ManifestLookupError:
844 content = data + "%s %s\n" % (node, tag)
845 return context.memfilectx(f, content, False, False, None)
850 user, date, tz = author
853 cmd = ['git', 'var', 'GIT_COMMITTER_IDENT']
854 process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
855 output, _ = process.communicate()
856 m = re.match('^.* <.*>', output)
860 user = repo.ui.username()
863 ctx = context.memctx(repo, (p1, p2), msg,
864 ['.hgtags'], getfilectx,
865 user, date_tz, {'branch' : branch})
867 tmp = encoding.encoding
868 encoding.encoding = 'utf-8'
870 tagnode = repo.commitctx(ctx)
872 encoding.encoding = tmp
874 return (tagnode, branch)
876 def checkheads_bmark(repo, ref, ctx):
877 bmark = ref[len('refs/heads/'):]
878 if not bmark in bmarks:
882 ctx_old = bmarks[bmark]
884 if not repo.changelog.descendant(ctx_old.rev(), ctx_new.rev()):
886 print "ok %s forced update" % ref
888 print "error %s non-fast forward" % ref
893 def checkheads(repo, remote, p_revs):
895 remotemap = remote.branchmap()
903 for node, ref in p_revs.iteritems():
905 branch = ctx.branch()
906 if not branch in remotemap:
909 if not ref.startswith('refs/heads/branches'):
910 if ref.startswith('refs/heads/'):
911 if not checkheads_bmark(repo, ref, ctx):
914 # only check branches
916 new.setdefault(branch, []).append(ctx.rev())
918 for branch, heads in new.iteritems():
919 old = [repo.changelog.rev(x) for x in remotemap[branch]]
921 if check_version(2, 3):
922 ancestors = repo.changelog.ancestors([rev], stoprev=min(old))
924 ancestors = repo.changelog.ancestors(rev)
935 node = repo.changelog.node(rev)
938 print "ok %s forced update" % ref
940 print "error %s non-fast forward" % ref
945 def push_unsafe(repo, remote, parsed_refs, p_revs):
949 fci = discovery.findcommonincoming
950 commoninc = fci(repo, remote, force=force)
951 common, _, remoteheads = commoninc
953 if not checkheads(repo, remote, p_revs):
956 cg = repo.getbundle('push', heads=list(p_revs), common=common)
958 unbundle = remote.capable('unbundle')
961 remoteheads = ['force']
962 return remote.unbundle(cg, remoteheads, 'push')
964 return remote.addchangegroup(cg, 'push', repo.url())
966 def push(repo, remote, parsed_refs, p_revs):
967 if hasattr(remote, 'canpush') and not remote.canpush():
968 print "error cannot push"
975 unbundle = remote.capable('unbundle')
979 ret = push_unsafe(repo, remote, parsed_refs, p_revs)
986 def check_tip(ref, kind, name, heads):
988 ename = '%s/%s' % (kind, name)
989 tip = marks.get_tip(ename)
995 def do_export(parser):
996 global parsed_refs, bmarks, peer
1003 for line in parser.each_block('done'):
1004 if parser.check('blob'):
1006 elif parser.check('commit'):
1007 parse_commit(parser)
1008 elif parser.check('reset'):
1010 elif parser.check('tag'):
1012 elif parser.check('feature'):
1015 die('unhandled export command: %s' % line)
1019 for ref, node in parsed_refs.iteritems():
1020 bnode = hgbin(node) if node else None
1021 if ref.startswith('refs/heads/branches'):
1022 branch = ref[len('refs/heads/branches/'):]
1023 if branch in branches and bnode in branches[branch]:
1028 remotemap = peer.branchmap()
1029 if remotemap and branch in remotemap:
1030 heads = [hghex(e) for e in remotemap[branch]]
1031 if not check_tip(ref, 'branches', branch, heads):
1032 print "error %s fetch first" % ref
1038 elif ref.startswith('refs/heads/'):
1039 bmark = ref[len('refs/heads/'):]
1041 old = bmarks[bmark].hex() if bmark in bmarks else ''
1047 if bmark != fake_bmark and \
1048 not (bmark == 'master' and bmark not in parser.repo._bookmarks):
1049 p_bmarks.append((ref, bmark, old, new))
1052 remote_old = peer.listkeys('bookmarks').get(bmark)
1054 if not check_tip(ref, 'bookmarks', bmark, remote_old):
1055 print "error %s fetch first" % ref
1060 elif ref.startswith('refs/tags/'):
1064 tag = ref[len('refs/tags/'):]
1066 author, msg = parsed_tags.get(tag, (None, None))
1069 msg = 'Added tag %s for changeset %s' % (tag, node[:12]);
1070 tagnode, branch = write_tag(parser.repo, tag, node, msg, author)
1071 p_revs[tagnode] = 'refs/heads/branches/' + gitref(branch)
1073 fp = parser.repo.opener('localtags', 'a')
1074 fp.write('%s %s\n' % (node, tag))
1079 # transport-helper/fast-export bugs
1087 if peer and not force_push:
1088 checkheads(parser.repo, peer, p_revs)
1093 if not push(parser.repo, peer, parsed_refs, p_revs):
1094 # do not update bookmarks
1098 # update remote bookmarks
1099 remote_bmarks = peer.listkeys('bookmarks')
1100 for ref, bmark, old, new in p_bmarks:
1102 old = remote_bmarks.get(bmark, '')
1103 if not peer.pushkey('bookmarks', bmark, old, new):
1104 print "error %s" % ref
1106 # update local bookmarks
1107 for ref, bmark, old, new in p_bmarks:
1108 if not bookmarks.pushbookmark(parser.repo, bmark, old, new):
1109 print "error %s" % ref
1113 def do_option(parser):
1114 global dry_run, force_push
1115 _, key, value = parser.line.split(' ')
1116 if key == 'dry-run':
1117 dry_run = (value == 'true')
1119 elif key == 'force':
1120 force_push = (value == 'true')
1125 def fix_path(alias, repo, orig_url):
1126 url = urlparse.urlparse(orig_url, 'file')
1127 if url.scheme != 'file' or os.path.isabs(url.path):
1129 abs_url = urlparse.urljoin("%s/" % os.getcwd(), orig_url)
1130 cmd = ['git', 'config', 'remote.%s.url' % alias, "hg::%s" % abs_url]
1131 subprocess.call(cmd)
1134 global prefix, gitdir, dirname, branches, bmarks
1135 global marks, blob_marks, parsed_refs
1136 global peer, mode, bad_mail, bad_name
1137 global track_branches, force_push, is_tmp
1140 global fake_bmark, hg_version
1147 hg_git_compat = get_config_bool('remote-hg.hg-git-compat')
1148 track_branches = get_config_bool('remote-hg.track-branches', True)
1153 bad_mail = 'none@none'
1157 bad_mail = 'unknown'
1158 bad_name = 'Unknown'
1160 if alias[4:] == url:
1162 alias = hashlib.sha1(alias).hexdigest()
1166 gitdir = os.environ['GIT_DIR']
1167 dirname = os.path.join(gitdir, 'hg', alias)
1177 hg_version = tuple(int(e) for e in util.version().split('.'))
1182 repo = get_repo(url, alias)
1183 prefix = 'refs/hg/%s' % alias
1186 fix_path(alias, peer or repo, url)
1188 marks_path = os.path.join(dirname, 'marks-hg')
1189 marks = Marks(marks_path, repo)
1191 if sys.platform == 'win32':
1193 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
1195 parser = Parser(repo)
1197 if parser.check('capabilities'):
1198 do_capabilities(parser)
1199 elif parser.check('list'):
1201 elif parser.check('import'):
1203 elif parser.check('export'):
1205 elif parser.check('option'):
1208 die('unhandled command: %s' % line)
1217 shutil.rmtree(dirname)
1219 atexit.register(bye)
1220 sys.exit(main(sys.argv))