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
16 from mercurial import changegroup
26 import urlparse, hashlib
30 # If you want to see Mercurial revisions as Git commit notes:
31 # git config core.notesRef refs/notes/hg
33 # If you are not in hg-git-compat mode and want to disable the tracking of
35 # git config --global remote-hg.track-branches false
37 # If you want the equivalent of hg's clone/pull--insecure option:
38 # git config --global remote-hg.insecure true
40 # If you want to switch to hg-git compatibility mode:
41 # git config --global remote-hg.hg-git-compat true
44 # Sensible defaults for git.
45 # hg bookmarks are exported as git branches, hg branches are prefixed
46 # with 'branches/', HEAD is a special case.
50 # Only hg bookmarks are exported as git branches.
51 # Commits are modified to preserve hg information and allow bidirectionality.
54 NAME_RE = re.compile('^([^<>]+)')
55 AUTHOR_RE = re.compile('^([^<>]+?)? ?[<>]([^<>]*)(?:$|>)')
56 EMAIL_RE = re.compile(r'([^ \t<>]+@[^ \t<>]+)')
57 AUTHOR_HG_RE = re.compile('^(.*?) ?<(.*?)(?:>(.*))?$')
58 RAW_AUTHOR_RE = re.compile('^(\w+) (?:(.+)? )?<(.*)> (\d+) ([+-]\d+)')
63 sys.stderr.write('ERROR: %s\n' % (msg % args))
67 sys.stderr.write('WARNING: %s\n' % (msg % args))
70 return 'l' in flags and '120000' or 'x' in flags and '100755' or '100644'
73 return '%+03d%02d' % (-tz / 3600, -tz % 3600 / 60)
76 m = { '100755': 'x', '120000': 'l' }
77 return m.get(mode, '')
86 return ref.replace('___', ' ')
89 return ref.replace(' ', '___')
91 def check_version(*check):
94 return hg_version >= check
96 def get_config(config):
97 cmd = ['git', 'config', '--get', config]
98 process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
99 output, _ = process.communicate()
102 def get_config_bool(config, default=False):
103 value = get_config(config).rstrip('\n')
106 elif value == "false":
113 def __init__(self, path, repo):
119 if self.version < VERSION:
120 if self.version == 1:
124 if self.version < VERSION:
126 self.version = VERSION
137 if not os.path.exists(self.path):
140 tmp = json.load(open(self.path))
142 self.tips = tmp['tips']
143 self.marks = tmp['marks']
144 self.last_mark = tmp['last-mark']
145 self.version = tmp.get('version', 1)
146 self.last_note = tmp.get('last-note', 0)
148 for rev, mark in self.marks.iteritems():
149 self.rev_marks[mark] = rev
151 def upgrade_one(self):
153 return hghex(self.repo.changelog.node(int(rev)))
154 self.tips = dict((name, get_id(rev)) for name, rev in self.tips.iteritems())
155 self.marks = dict((get_id(rev), mark) for rev, mark in self.marks.iteritems())
156 self.rev_marks = dict((mark, get_id(rev)) for mark, rev in self.rev_marks.iteritems())
160 return { 'tips': self.tips, 'marks': self.marks,
161 'last-mark': self.last_mark, 'version': self.version,
162 'last-note': self.last_note }
165 json.dump(self.dict(), open(self.path, 'w'))
168 return str(self.dict())
170 def from_rev(self, rev):
171 return self.marks[rev]
173 def to_rev(self, mark):
174 return str(self.rev_marks[mark])
178 return self.last_mark
180 def get_mark(self, rev):
182 self.marks[rev] = self.last_mark
183 return self.last_mark
185 def new_mark(self, rev, mark):
186 self.marks[rev] = mark
187 self.rev_marks[mark] = rev
188 self.last_mark = mark
190 def is_marked(self, rev):
191 return rev in self.marks
193 def get_tip(self, branch):
194 return str(self.tips[branch])
196 def set_tip(self, branch, tip):
197 self.tips[branch] = tip
201 def __init__(self, repo):
203 self.line = self.get_line()
206 return sys.stdin.readline().strip()
208 def __getitem__(self, i):
209 return self.line.split()[i]
211 def check(self, word):
212 return self.line.startswith(word)
214 def each_block(self, separator):
215 while self.line != separator:
217 self.line = self.get_line()
220 return self.each_block('')
223 self.line = self.get_line()
224 if self.line == 'done':
228 i = self.line.index(':') + 1
229 return int(self.line[i:])
232 if not self.check('data'):
234 i = self.line.index(' ') + 1
235 size = int(self.line[i:])
236 return sys.stdin.read(size)
238 def get_author(self):
240 m = RAW_AUTHOR_RE.match(self.line)
243 _, name, email, date, tz = m.groups()
244 if name and 'ext:' in name:
245 m = re.match('^(.+?) ext:\((.+)\)$', name)
248 ex = urllib.unquote(m.group(2))
250 if email != bad_mail:
252 user = '%s <%s>' % (name, email)
254 user = '<%s>' % (email)
262 tz = ((tz / 100) * 3600) + ((tz % 100) * 60)
263 return (user, int(date), -tz)
265 def fix_file_path(path):
266 path = os.path.normpath(path)
267 if not os.path.isabs(path):
269 return os.path.relpath(path, '/')
271 def export_files(files):
274 fid = node.hex(f.filenode())
277 mark = filenodes[fid]
279 mark = marks.next_mark()
280 filenodes[fid] = mark
284 print "mark :%u" % mark
285 print "data %d" % len(d)
288 path = fix_file_path(f.path())
289 final.append((gitmode(f.flags()), mark, path))
293 def get_filechanges(repo, ctx, parent):
298 # load earliest manifest first for caching reasons
299 prev = parent.manifest().copy()
304 if (cur.flags(fn) != prev.flags(fn) or cur[fn] != prev[fn]):
309 removed |= set(prev.keys())
311 return added | modified, removed
313 def fixup_user_git(user):
315 user = user.replace('"', '')
316 m = AUTHOR_RE.match(user)
319 mail = m.group(2).strip()
321 m = EMAIL_RE.match(user)
325 m = NAME_RE.match(user)
327 name = m.group(1).strip()
330 def fixup_user_hg(user):
332 # stole this from hg-git
333 return re.sub('[<>\n]', '?', name.lstrip('< ').rstrip('> '))
335 m = AUTHOR_HG_RE.match(user)
337 name = sanitize(m.group(1))
338 mail = sanitize(m.group(2))
341 name += ' ext:(' + urllib.quote(ex) + ')'
343 name = sanitize(user)
351 def fixup_user(user):
353 name, mail = fixup_user_git(user)
355 name, mail = fixup_user_hg(user)
362 return '%s <%s>' % (name, mail)
364 def updatebookmarks(repo, peer):
365 remotemarks = peer.listkeys('bookmarks')
366 localmarks = repo._bookmarks
371 for k, v in remotemarks.iteritems():
372 localmarks[k] = hgbin(v)
374 if hasattr(localmarks, 'write'):
377 bookmarks.write(repo)
379 def get_repo(url, alias):
383 myui.setconfig('ui', 'interactive', 'off')
384 myui.fout = sys.stderr
386 if get_config_bool('remote-hg.insecure'):
387 myui.setconfig('web', 'cacerts', '')
389 extensions.loadall(myui)
391 if hg.islocal(url) and not os.environ.get('GIT_REMOTE_HG_TEST_REMOTE'):
392 repo = hg.repository(myui, url)
393 if not os.path.exists(dirname):
396 shared_path = os.path.join(gitdir, 'hg')
398 # check and upgrade old organization
399 hg_path = os.path.join(shared_path, '.hg')
400 if os.path.exists(shared_path) and not os.path.exists(hg_path):
401 repos = os.listdir(shared_path)
403 local_hg = os.path.join(shared_path, x, 'clone', '.hg')
404 if not os.path.exists(local_hg):
406 if not os.path.exists(hg_path):
407 shutil.move(local_hg, hg_path)
408 shutil.rmtree(os.path.join(shared_path, x, 'clone'))
410 # setup shared repo (if not there)
412 hg.peer(myui, {}, shared_path, create=True)
413 except error.RepoError:
416 if not os.path.exists(dirname):
419 local_path = os.path.join(dirname, 'clone')
420 if not os.path.exists(local_path):
421 hg.share(myui, shared_path, local_path, update=False)
423 # make sure the shared path is always up-to-date
424 util.writefile(os.path.join(local_path, '.hg', 'sharedpath'), hg_path)
426 repo = hg.repository(myui, local_path)
428 peer = hg.peer(repo.ui, {}, url)
430 die('Repository error')
431 repo.pull(peer, heads=None, force=True)
433 updatebookmarks(repo, peer)
437 def rev_to_mark(rev):
438 return marks.from_rev(rev.hex())
440 def mark_to_rev(mark):
441 return marks.to_rev(mark)
443 # Get a range of revisions in the form of a..b (git committish)
444 def gitrange(repo, a, b):
446 pending = set([int(b)])
447 negative = set([int(a)])
448 for cur in xrange(b, -1, -1):
452 parents = [p for p in repo.changelog.parentrevs(cur) if p >= 0]
458 if p not in negative:
460 elif cur in negative:
471 def export_ref(repo, name, kind, head):
472 ename = '%s/%s' % (kind, name)
474 tip = marks.get_tip(ename)
479 revs = gitrange(repo, tip, head)
489 if marks.is_marked(c.hex()):
492 (manifest, user, (time, tz), files, desc, extra) = repo.changelog.read(node)
493 rev_branch = extra['branch']
495 author = "%s %d %s" % (fixup_user(user), time, gittz(tz))
496 if 'committer' in extra:
498 cuser, ctime, ctz = extra['committer'].rsplit(' ', 2)
499 committer = "%s %s %s" % (cuser, ctime, gittz(int(ctz)))
501 cuser = extra['committer']
502 committer = "%s %d %s" % (fixup_user(cuser), time, gittz(tz))
506 parents = [repo[p] for p in repo.changelog.parentrevs(rev) if p >= 0]
508 if len(parents) == 0:
509 modified = c.manifest().keys()
512 modified, removed = get_filechanges(repo, c, parents[0])
519 if rev_branch != 'default':
520 extra_msg += 'branch : %s\n' % rev_branch
524 if f not in c.manifest():
526 rename = c.filectx(f).renamed()
528 renames.append((rename[0], f))
531 extra_msg += "rename : %s => %s\n" % e
533 for key, value in extra.iteritems():
534 if key in ('author', 'committer', 'encoding', 'message', 'branch', 'hg-git'):
537 extra_msg += "extra : %s : %s\n" % (key, urllib.quote(value))
540 desc += '\n--HG--\n' + extra_msg
542 if len(parents) == 0 and rev:
543 print 'reset %s/%s' % (prefix, ename)
545 modified_final = export_files(c.filectx(f) for f in modified)
547 print "commit %s/%s" % (prefix, ename)
548 print "mark :%d" % (marks.get_mark(c.hex()))
549 print "author %s" % (author)
550 print "committer %s" % (committer)
551 print "data %d" % (len(desc))
555 print "from :%s" % (rev_to_mark(parents[0]))
557 print "merge :%s" % (rev_to_mark(parents[1]))
560 print "D %s" % (fix_file_path(f))
561 for f in modified_final:
562 print "M %s :%u %s" % f
565 progress = (rev - tip)
566 if (progress % 100 == 0):
567 print "progress revision %d '%s' (%d/%d)" % (rev, name, progress, total)
569 # make sure the ref is updated
570 print "reset %s/%s" % (prefix, ename)
571 print "from :%u" % rev_to_mark(head)
574 pending_revs = set(revs) - notes
576 note_mark = marks.next_mark()
577 ref = "refs/notes/hg"
579 print "commit %s" % ref
580 print "mark :%d" % (note_mark)
581 print "committer remote-hg <> %d %s" % (ptime.time(), gittz(ptime.timezone))
582 desc = "Notes for %s\n" % (name)
583 print "data %d" % (len(desc))
586 print "from :%u" % marks.last_note
588 for rev in pending_revs:
591 print "N inline :%u" % rev_to_mark(c)
593 print "data %d" % (len(msg))
597 marks.last_note = note_mark
599 marks.set_tip(ename, head.hex())
601 def export_tag(repo, tag):
602 export_ref(repo, tag, 'tags', repo[hgref(tag)])
604 def export_bookmark(repo, bmark):
605 head = bmarks[hgref(bmark)]
606 export_ref(repo, bmark, 'bookmarks', head)
608 def export_branch(repo, branch):
609 tip = get_branch_tip(repo, branch)
611 export_ref(repo, branch, 'branches', head)
613 def export_head(repo):
614 export_ref(repo, g_head[0], 'bookmarks', g_head[1])
616 def do_capabilities(parser):
619 print "refspec refs/heads/branches/*:%s/branches/*" % prefix
620 print "refspec refs/heads/*:%s/bookmarks/*" % prefix
621 print "refspec refs/tags/*:%s/tags/*" % prefix
623 path = os.path.join(dirname, 'marks-git')
625 if os.path.exists(path):
626 print "*import-marks %s" % path
627 print "*export-marks %s" % path
632 def branch_tip(branch):
633 return branches[branch][-1]
635 def get_branch_tip(repo, branch):
636 heads = branches.get(hgref(branch), None)
640 # verify there's only one head
642 warn("Branch '%s' has more than one head, consider merging" % branch)
643 return branch_tip(hgref(branch))
647 def list_head(repo, cur):
648 global g_head, fake_bmark
650 if 'default' not in branches:
654 node = repo[branch_tip('default')]
655 head = 'master' if 'master' not in bmarks else 'default'
660 print "@refs/heads/%s HEAD" % head
661 g_head = (head, node)
665 for bmark, node in bookmarks.listbookmarks(repo).iteritems():
666 bmarks[bmark] = repo[node]
668 cur = repo.dirstate.branch()
669 orig = peer if peer else repo
671 for branch, heads in orig.branchmap().iteritems():
673 heads = [h for h in heads if 'close' not in repo.changelog.read(h)[5]]
675 branches[branch] = heads
680 for branch in branches:
681 print "? refs/heads/branches/%s" % gitref(branch)
684 if bmarks[bmark].hex() == '0' * 40:
685 warn("Ignoring invalid bookmark '%s'", bmark)
687 print "? refs/heads/%s" % gitref(bmark)
689 for tag, node in repo.tagslist():
692 print "? refs/tags/%s" % gitref(tag)
696 def do_import(parser):
699 path = os.path.join(dirname, 'marks-git')
702 if os.path.exists(path):
703 print "feature import-marks=%s" % path
704 print "feature export-marks=%s" % path
705 print "feature force"
708 tmp = encoding.encoding
709 encoding.encoding = 'utf-8'
711 # lets get all the import lines
712 while parser.check('import'):
717 elif ref.startswith('refs/heads/branches/'):
718 branch = ref[len('refs/heads/branches/'):]
719 export_branch(repo, branch)
720 elif ref.startswith('refs/heads/'):
721 bmark = ref[len('refs/heads/'):]
722 export_bookmark(repo, bmark)
723 elif ref.startswith('refs/tags/'):
724 tag = ref[len('refs/tags/'):]
725 export_tag(repo, tag)
729 encoding.encoding = tmp
733 def parse_blob(parser):
735 mark = parser.get_mark()
737 data = parser.get_data()
738 blob_marks[mark] = data
741 def get_merge_files(repo, p1, p2, files):
742 for e in repo[p1].files():
744 if e not in repo[p1].manifest():
746 f = { 'ctx': repo[p1][e] }
749 def c_style_unescape(string):
750 if string[0] == string[-1] == '"':
751 return string.decode('string-escape')[1:-1]
754 def parse_commit(parser):
755 from_mark = merge_mark = None
760 commit_mark = parser.get_mark()
762 author = parser.get_author()
764 committer = parser.get_author()
766 data = parser.get_data()
768 if parser.check('from'):
769 from_mark = parser.get_mark()
771 if parser.check('merge'):
772 merge_mark = parser.get_mark()
774 if parser.check('merge'):
775 die('octopus merges are not supported yet')
777 # fast-export adds an extra newline
784 if parser.check('M'):
785 t, m, mark_ref, path = line.split(' ', 3)
786 mark = int(mark_ref[1:])
787 f = { 'mode': hgmode(m), 'data': blob_marks[mark] }
788 elif parser.check('D'):
789 t, path = line.split(' ', 1)
790 f = { 'deleted': True }
792 die('Unknown file command: %s' % line)
793 path = c_style_unescape(path)
796 # only export the commits if we are on an internal proxy repo
797 if dry_run and not peer:
798 parsed_refs[ref] = None
801 def getfilectx(repo, memctx, f):
807 is_exec = of['mode'] == 'x'
808 is_link = of['mode'] == 'l'
809 rename = of.get('rename', None)
810 return context.memfilectx(f, of['data'],
811 is_link, is_exec, rename)
815 user, date, tz = author
818 if committer != author:
819 extra['committer'] = "%s %u %u" % committer
822 p1 = mark_to_rev(from_mark)
827 p2 = mark_to_rev(merge_mark)
832 # If files changed from any of the parents, hg wants to know, but in git if
833 # nothing changed from the first parent, nothing changed.
836 get_merge_files(repo, p1, p2, files)
838 # Check if the ref is supposed to be a named branch
839 if ref.startswith('refs/heads/branches/'):
840 branch = ref[len('refs/heads/branches/'):]
841 extra['branch'] = hgref(branch)
844 i = data.find('\n--HG--\n')
846 tmp = data[i + len('\n--HG--\n'):].strip()
847 for k, v in [e.split(' : ', 1) for e in tmp.split('\n')]:
849 old, new = v.split(' => ', 1)
850 files[new]['rename'] = old
854 ek, ev = v.split(' : ', 1)
855 extra[ek] = urllib.unquote(ev)
858 ctx = context.memctx(repo, (p1, p2), data,
859 files.keys(), getfilectx,
860 user, (date, tz), extra)
862 tmp = encoding.encoding
863 encoding.encoding = 'utf-8'
865 node = hghex(repo.commitctx(ctx))
867 encoding.encoding = tmp
869 parsed_refs[ref] = node
870 marks.new_mark(node, commit_mark)
872 def parse_reset(parser):
876 if parser.check('commit'):
879 if not parser.check('from'):
881 from_mark = parser.get_mark()
885 rev = mark_to_rev(from_mark)
888 parsed_refs[ref] = rev
890 def parse_tag(parser):
893 from_mark = parser.get_mark()
895 tagger = parser.get_author()
897 data = parser.get_data()
900 parsed_tags[name] = (tagger, data)
902 def write_tag(repo, tag, node, msg, author):
903 branch = repo[node].branch()
904 tip = branch_tip(branch)
907 def getfilectx(repo, memctx, f):
909 fctx = tip.filectx(f)
911 except error.ManifestLookupError:
913 content = data + "%s %s\n" % (node, tag)
914 return context.memfilectx(f, content, False, False, None)
919 user, date, tz = author
922 cmd = ['git', 'var', 'GIT_COMMITTER_IDENT']
923 process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
924 output, _ = process.communicate()
925 m = re.match('^.* <.*>', output)
929 user = repo.ui.username()
932 ctx = context.memctx(repo, (p1, p2), msg,
933 ['.hgtags'], getfilectx,
934 user, date_tz, {'branch': branch})
936 tmp = encoding.encoding
937 encoding.encoding = 'utf-8'
939 tagnode = repo.commitctx(ctx)
941 encoding.encoding = tmp
943 return (tagnode, branch)
945 def checkheads_bmark(repo, ref, ctx):
946 bmark = ref[len('refs/heads/'):]
947 if bmark not in bmarks:
951 ctx_old = bmarks[bmark]
955 print "error %s unknown" % ref
958 if not repo.changelog.descendant(ctx_old.rev(), ctx_new.rev()):
960 print "ok %s forced update" % ref
962 print "error %s non-fast forward" % ref
967 def checkheads(repo, remote, p_revs):
969 remotemap = remote.branchmap()
977 for node, ref in p_revs.iteritems():
979 branch = ctx.branch()
980 if branch not in remotemap:
983 if not ref.startswith('refs/heads/branches'):
984 if ref.startswith('refs/heads/'):
985 if not checkheads_bmark(repo, ref, ctx):
988 # only check branches
990 new.setdefault(branch, []).append(ctx.rev())
992 for branch, heads in new.iteritems():
993 old = [repo.changelog.rev(x) for x in remotemap[branch]]
995 if check_version(2, 3):
996 ancestors = repo.changelog.ancestors([rev], stoprev=min(old))
998 ancestors = repo.changelog.ancestors(rev)
1009 node = repo.changelog.node(rev)
1012 print "ok %s forced update" % ref
1014 print "error %s non-fast forward" % ref
1019 def push_unsafe(repo, remote, parsed_refs, p_revs):
1023 fci = discovery.findcommonincoming
1024 commoninc = fci(repo, remote, force=force)
1025 common, _, remoteheads = commoninc
1027 if not checkheads(repo, remote, p_revs):
1030 if check_version(3, 0):
1031 cg = changegroup.getbundle(repo, 'push', heads=list(p_revs), common=common)
1033 cg = repo.getbundle('push', heads=list(p_revs), common=common)
1035 unbundle = remote.capable('unbundle')
1038 remoteheads = ['force']
1039 ret = remote.unbundle(cg, remoteheads, 'push')
1041 ret = remote.addchangegroup(cg, 'push', repo.url())
1043 phases = remote.listkeys('phases')
1047 remote.pushkey('phases', hghex(head), '1', '0')
1051 def push(repo, remote, parsed_refs, p_revs):
1052 if hasattr(remote, 'canpush') and not remote.canpush():
1053 print "error cannot push"
1060 unbundle = remote.capable('unbundle')
1062 lock = remote.lock()
1064 ret = push_unsafe(repo, remote, parsed_refs, p_revs)
1066 if lock is not None:
1071 def check_tip(ref, kind, name, heads):
1073 ename = '%s/%s' % (kind, name)
1074 tip = marks.get_tip(ename)
1080 def do_export(parser):
1086 for line in parser.each_block('done'):
1087 if parser.check('blob'):
1089 elif parser.check('commit'):
1090 parse_commit(parser)
1091 elif parser.check('reset'):
1093 elif parser.check('tag'):
1095 elif parser.check('feature'):
1098 die('unhandled export command: %s' % line)
1102 for ref, node in parsed_refs.iteritems():
1103 bnode = hgbin(node) if node else None
1104 if ref.startswith('refs/heads/branches'):
1105 branch = ref[len('refs/heads/branches/'):]
1106 if branch in branches and bnode in branches[branch]:
1111 remotemap = peer.branchmap()
1112 if remotemap and branch in remotemap:
1113 heads = [hghex(e) for e in remotemap[branch]]
1114 if not check_tip(ref, 'branches', branch, heads):
1115 print "error %s fetch first" % ref
1121 elif ref.startswith('refs/heads/'):
1122 bmark = ref[len('refs/heads/'):]
1124 old = bmarks[bmark].hex() if bmark in bmarks else ''
1130 if bmark != fake_bmark and \
1131 not (bmark == 'master' and bmark not in parser.repo._bookmarks):
1132 p_bmarks.append((ref, bmark, old, new))
1135 remote_old = peer.listkeys('bookmarks').get(bmark)
1137 if not check_tip(ref, 'bookmarks', bmark, remote_old):
1138 print "error %s fetch first" % ref
1143 elif ref.startswith('refs/tags/'):
1147 tag = ref[len('refs/tags/'):]
1149 author, msg = parsed_tags.get(tag, (None, None))
1152 msg = 'Added tag %s for changeset %s' % (tag, node[:12])
1153 tagnode, branch = write_tag(parser.repo, tag, node, msg, author)
1154 p_revs[tagnode] = 'refs/heads/branches/' + gitref(branch)
1156 fp = parser.repo.opener('localtags', 'a')
1157 fp.write('%s %s\n' % (node, tag))
1162 # transport-helper/fast-export bugs
1170 if peer and not force_push:
1171 checkheads(parser.repo, peer, p_revs)
1176 if not push(parser.repo, peer, parsed_refs, p_revs):
1177 # do not update bookmarks
1181 # update remote bookmarks
1182 remote_bmarks = peer.listkeys('bookmarks')
1183 for ref, bmark, old, new in p_bmarks:
1185 old = remote_bmarks.get(bmark, '')
1186 if not peer.pushkey('bookmarks', bmark, old, new):
1187 print "error %s" % ref
1189 # update local bookmarks
1190 for ref, bmark, old, new in p_bmarks:
1191 if not bookmarks.pushbookmark(parser.repo, bmark, old, new):
1192 print "error %s" % ref
1196 def do_option(parser):
1197 global dry_run, force_push
1198 _, key, value = parser.line.split(' ')
1199 if key == 'dry-run':
1200 dry_run = (value == 'true')
1202 elif key == 'force':
1203 force_push = (value == 'true')
1208 def fix_path(alias, repo, orig_url):
1209 url = urlparse.urlparse(orig_url, 'file')
1210 if url.scheme != 'file' or os.path.isabs(os.path.expanduser(url.path)):
1212 abs_url = urlparse.urljoin("%s/" % os.getcwd(), orig_url)
1213 cmd = ['git', 'config', 'remote.%s.url' % alias, "hg::%s" % abs_url]
1214 subprocess.call(cmd)
1217 global prefix, gitdir, dirname, branches, bmarks
1218 global marks, blob_marks, parsed_refs
1219 global peer, mode, bad_mail, bad_name
1220 global track_branches, force_push, is_tmp
1223 global fake_bmark, hg_version
1229 gitdir = os.environ.get('GIT_DIR', None)
1232 die('Not enough arguments.')
1235 die('GIT_DIR not set')
1241 hg_git_compat = get_config_bool('remote-hg.hg-git-compat')
1242 track_branches = get_config_bool('remote-hg.track-branches', True)
1247 bad_mail = 'none@none'
1251 bad_mail = 'unknown'
1252 bad_name = 'Unknown'
1254 if alias[4:] == url:
1256 alias = hashlib.sha1(alias).hexdigest()
1258 dirname = os.path.join(gitdir, 'hg', alias)
1267 hg_version = tuple(int(e) for e in util.version().split('.'))
1273 repo = get_repo(url, alias)
1274 prefix = 'refs/hg/%s' % alias
1277 fix_path(alias, peer or repo, url)
1279 marks_path = os.path.join(dirname, 'marks-hg')
1280 marks = Marks(marks_path, repo)
1282 if sys.platform == 'win32':
1284 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
1286 parser = Parser(repo)
1288 if parser.check('capabilities'):
1289 do_capabilities(parser)
1290 elif parser.check('list'):
1292 elif parser.check('import'):
1294 elif parser.check('export'):
1296 elif parser.check('option'):
1299 die('unhandled command: %s' % line)
1306 shutil.rmtree(dirname)
1308 atexit.register(bye)
1309 sys.exit(main(sys.argv))