From a57ad51d1ae136e704a004c7d5c6307b4ce19c63 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:22:57 -0500 Subject: [PATCH 01/21] remote-hg: trivial cleanups Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 328c2dc76..d0dfb1ec2 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -531,7 +531,6 @@ def parse_blob(parser): data = parser.get_data() blob_marks[mark] = data parser.next() - return def get_merge_files(repo, p1, p2, files): for e in repo[p1].files(): @@ -542,7 +541,7 @@ def get_merge_files(repo, p1, p2, files): files[e] = f def parse_commit(parser): - global marks, blob_marks, bmarks, parsed_refs + global marks, blob_marks, parsed_refs global mode from_mark = merge_mark = None @@ -647,10 +646,11 @@ def parse_commit(parser): rev = repo[node].rev() parsed_refs[ref] = node - marks.new_mark(rev, commit_mark) def parse_reset(parser): + global parsed_refs + ref = parser[1] parser.next() # ugh @@ -715,11 +715,11 @@ def do_export(parser): continue print "ok %s" % ref - print - if peer: parser.repo.push(peer, force=False) + print + def fix_path(alias, repo, orig_url): repo_url = util.url(repo.url()) url = util.url(orig_url) From e1219e45bdcb3f6b298bdee21fe07ddfa38778ef Mon Sep 17 00:00:00 2001 From: Dusty Phillips Date: Thu, 11 Apr 2013 07:22:58 -0500 Subject: [PATCH 02/21] remote-hg: add missing config variable in doc Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index d0dfb1ec2..844ec5081 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -23,6 +23,10 @@ import urllib # If you want to switch to hg-git compatibility mode: # git config --global remote-hg.hg-git-compat true # +# If you are not in hg-git-compat mode and want to disable the tracking of +# named branches: +# git config --global remote-hg.track-branches false +# # git: # Sensible defaults for git. # hg bookmarks are exported as git branches, hg branches are prefixed From 031873f8f1661c4e712b8b181c50508c6eff2b08 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:22:59 -0500 Subject: [PATCH 03/21] remote-hg: properly report errors on bookmark pushes Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 844ec5081..19eb4dbd9 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -710,6 +710,7 @@ def do_export(parser): else: old = '' if not bookmarks.pushbookmark(parser.repo, bmark, old, node): + print "error %s" % ref continue elif ref.startswith('refs/tags/'): tag = ref[len('refs/tags/'):] From 15a8d901dd38cdc10d6b17d718e20e8ba91c66d1 Mon Sep 17 00:00:00 2001 From: Peter van Zetten Date: Thu, 11 Apr 2013 07:23:00 -0500 Subject: [PATCH 04/21] remote-hg: fix for files with spaces Set the maximum number of splits to make when dividing the diff stat lines based on space characters. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 19eb4dbd9..c6a1a47cc 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -578,7 +578,7 @@ def parse_commit(parser): mark = int(mark_ref[1:]) f = { 'mode' : hgmode(m), 'data' : blob_marks[mark] } elif parser.check('D'): - t, path = line.split(' ') + t, path = line.split(' ', 1) f = { 'deleted' : True } else: die('Unknown file command: %s' % line) @@ -625,7 +625,7 @@ def parse_commit(parser): i = data.find('\n--HG--\n') if i >= 0: tmp = data[i + len('\n--HG--\n'):].strip() - for k, v in [e.split(' : ') for e in tmp.split('\n')]: + for k, v in [e.split(' : ', 1) for e in tmp.split('\n')]: if k == 'rename': old, new = v.split(' => ', 1) files[new]['rename'] = old From 8120014e2ba0e65748c8a3c1642bed0891be851d Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:23:01 -0500 Subject: [PATCH 05/21] remote-hg: make sure fake bookmarks are updated Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 7 +++++++ contrib/remote-helpers/test-hg-bidi.sh | 1 + contrib/remote-helpers/test-hg-hg-git.sh | 1 + 3 files changed, 9 insertions(+) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index c6a1a47cc..b200e60c7 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -709,9 +709,16 @@ def do_export(parser): old = bmarks[bmark].hex() else: old = '' + + if bmark == 'master' and 'master' not in parser.repo._bookmarks: + # fake bookmark + print "ok %s" % ref + continue + if not bookmarks.pushbookmark(parser.repo, bmark, old, node): print "error %s" % ref continue + elif ref.startswith('refs/tags/'): tag = ref[len('refs/tags/'):] parser.repo.tag([tag], node, None, True, None, {}) diff --git a/contrib/remote-helpers/test-hg-bidi.sh b/contrib/remote-helpers/test-hg-bidi.sh index 1d6198243..fe38e49bc 100755 --- a/contrib/remote-helpers/test-hg-bidi.sh +++ b/contrib/remote-helpers/test-hg-bidi.sh @@ -30,6 +30,7 @@ git_clone () { hg_clone () { ( hg init $2 && + hg -R $2 bookmark -i master && cd $1 && git push -q "hg::$PWD/../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' ) && diff --git a/contrib/remote-helpers/test-hg-hg-git.sh b/contrib/remote-helpers/test-hg-hg-git.sh index 7e3967f5b..4c71c45d0 100755 --- a/contrib/remote-helpers/test-hg-hg-git.sh +++ b/contrib/remote-helpers/test-hg-hg-git.sh @@ -35,6 +35,7 @@ git_clone_git () { hg_clone_git () { ( hg init $2 && + hg -R $2 bookmark -i master && cd $1 && git push -q "hg::$PWD/../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' ) && From 71c6c95c310b0389f07fdbe40db6f068c1fa95a5 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:23:02 -0500 Subject: [PATCH 06/21] remote-hg: trivial test cleanups Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/test-hg-bidi.sh | 5 ++--- contrib/remote-helpers/test-hg-hg-git.sh | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/contrib/remote-helpers/test-hg-bidi.sh b/contrib/remote-helpers/test-hg-bidi.sh index fe38e49bc..a3c88f65b 100755 --- a/contrib/remote-helpers/test-hg-bidi.sh +++ b/contrib/remote-helpers/test-hg-bidi.sh @@ -22,7 +22,6 @@ fi # clone to a git repo git_clone () { - hg -R $1 bookmark -f -r tip master && git clone -q "hg::$PWD/$1" $2 } @@ -201,8 +200,8 @@ test_expect_success 'hg branch' ' hg_push hgrepo gitrepo && hg_clone gitrepo hgrepo2 && - : TODO, avoid "master" bookmark && - (cd hgrepo2 && hg checkout gamma) && + : Back to the common revision && + (cd hgrepo && hg checkout default) && hg_log hgrepo > expected && hg_log hgrepo2 > actual && diff --git a/contrib/remote-helpers/test-hg-hg-git.sh b/contrib/remote-helpers/test-hg-hg-git.sh index 4c71c45d0..8c59d8e72 100755 --- a/contrib/remote-helpers/test-hg-hg-git.sh +++ b/contrib/remote-helpers/test-hg-hg-git.sh @@ -27,7 +27,6 @@ fi # clone to a git repo with git git_clone_git () { - hg -R $1 bookmark -f -r tip master && git clone -q "hg::$PWD/$1" $2 } @@ -48,7 +47,7 @@ git_clone_hg () { ( git init -q $2 && cd $1 && - hg bookmark -f -r tip master && + hg bookmark -i -f -r tip master && hg -q push -r master ../$2 || true ) } From 25027b983eb82b95316f362e03a207b49b033b00 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:23:03 -0500 Subject: [PATCH 07/21] remote-hg: redirect buggy mercurial output Mercurial emits messages like "searching for changes", "no changes found", etc. meant for the use of its own UI layer, which break the pipe between transport helper and remote helper. Since there's no way to silence Mercurial, let's redirect to standard error. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index b200e60c7..874ccd4e2 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -271,6 +271,7 @@ def get_repo(url, alias): myui = ui.ui() myui.setconfig('ui', 'interactive', 'off') + myui.fout = sys.stderr if hg.islocal(url): repo = hg.repository(myui, url) From f04f489f6b91213a1a6c4f7e88c8c83d43a68eeb Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:23:04 -0500 Subject: [PATCH 08/21] remote-hg: split bookmark handling Will be useful for remote bookmarks. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 39 ++++++++++++++++++---------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 874ccd4e2..73cd81228 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -685,6 +685,8 @@ def parse_tag(parser): def do_export(parser): global parsed_refs, bmarks, peer + p_bmarks = [] + parser.next() for line in parser.each_block('done'): @@ -706,20 +708,9 @@ def do_export(parser): pass elif ref.startswith('refs/heads/'): bmark = ref[len('refs/heads/'):] - if bmark in bmarks: - old = bmarks[bmark].hex() - else: - old = '' - - if bmark == 'master' and 'master' not in parser.repo._bookmarks: - # fake bookmark - print "ok %s" % ref - continue - - if not bookmarks.pushbookmark(parser.repo, bmark, old, node): - print "error %s" % ref - continue - + p_bmarks.append((bmark, node)) + # handle below + continue elif ref.startswith('refs/tags/'): tag = ref[len('refs/tags/'):] parser.repo.tag([tag], node, None, True, None, {}) @@ -731,6 +722,26 @@ def do_export(parser): if peer: parser.repo.push(peer, force=False) + # handle bookmarks + for bmark, node in p_bmarks: + ref = 'refs/heads/' + bmark + + if bmark in bmarks: + old = bmarks[bmark].hex() + else: + old = '' + + if bmark == 'master' and 'master' not in parser.repo._bookmarks: + # fake bookmark + print "ok %s" % ref + continue + + if not bookmarks.pushbookmark(parser.repo, bmark, old, node): + print "error %s" % ref + continue + + print "ok %s" % ref + print def fix_path(alias, repo, orig_url): From 0ff1b61770f42921d68b488f0ec3756d5477bc78 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:23:05 -0500 Subject: [PATCH 09/21] remote-hg: refactor export No functional changes. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 73cd81228..3ceec8502 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -9,7 +9,7 @@ # Then you can clone with: # git clone hg::/path/to/mercurial/repo/ -from mercurial import hg, ui, bookmarks, context, util, encoding +from mercurial import hg, ui, bookmarks, context, util, encoding, node import re import sys @@ -60,6 +60,9 @@ def hgmode(mode): m = { '100755': 'x', '120000': 'l' } return m.get(mode, '') +def hghex(node): + return hg.node.hex(node) + def get_config(config): cmd = ['git', 'config', '--get', config] process = subprocess.Popen(cmd, stdout=subprocess.PIPE) @@ -705,19 +708,18 @@ def do_export(parser): for ref, node in parsed_refs.iteritems(): if ref.startswith('refs/heads/branches'): - pass + print "ok %s" % ref elif ref.startswith('refs/heads/'): bmark = ref[len('refs/heads/'):] p_bmarks.append((bmark, node)) - # handle below continue elif ref.startswith('refs/tags/'): tag = ref[len('refs/tags/'):] parser.repo.tag([tag], node, None, True, None, {}) + print "ok %s" % ref else: # transport-helper/fast-export bugs continue - print "ok %s" % ref if peer: parser.repo.push(peer, force=False) @@ -725,6 +727,7 @@ def do_export(parser): # handle bookmarks for bmark, node in p_bmarks: ref = 'refs/heads/' + bmark + new = hghex(node) if bmark in bmarks: old = bmarks[bmark].hex() @@ -733,10 +736,11 @@ def do_export(parser): if bmark == 'master' and 'master' not in parser.repo._bookmarks: # fake bookmark - print "ok %s" % ref - continue - - if not bookmarks.pushbookmark(parser.repo, bmark, old, node): + pass + elif bookmarks.pushbookmark(parser.repo, bmark, old, new): + # updated locally + pass + else: print "error %s" % ref continue From d7314b3acffbce985a90e594cfa5046d9b94f39e Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:23:06 -0500 Subject: [PATCH 10/21] remote-hg: update remote bookmarks Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 3ceec8502..46cddc93a 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -744,6 +744,11 @@ def do_export(parser): print "error %s" % ref continue + if peer: + if not peer.pushkey('bookmarks', bmark, old, new): + print "error %s" % ref + continue + print "ok %s" % ref print From 7a6c1859b69c287a1962c718d93bc8412448e7f8 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:23:07 -0500 Subject: [PATCH 11/21] remote-hg: update tags globally Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 46cddc93a..fc04f8132 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -715,7 +715,11 @@ def do_export(parser): continue elif ref.startswith('refs/tags/'): tag = ref[len('refs/tags/'):] - parser.repo.tag([tag], node, None, True, None, {}) + if mode == 'git': + msg = 'Added tag %s for changeset %s' % (tag, hghex(node[:6])); + parser.repo.tag([tag], node, msg, False, None, {}) + else: + parser.repo.tag([tag], node, None, True, None, {}) print "ok %s" % ref else: # transport-helper/fast-export bugs From 11dc88f49c1dc177132fb724d46c80ae8e6a2e99 Mon Sep 17 00:00:00 2001 From: Dusty Phillips Date: Thu, 11 Apr 2013 07:23:08 -0500 Subject: [PATCH 12/21] remote-hg: push to the appropriate branch Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index fc04f8132..ec599c60f 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -625,6 +625,10 @@ def parse_commit(parser): if merge_mark: get_merge_files(repo, p1, p2, files) + # Check if the ref is supposed to be a named branch + if ref.startswith('refs/heads/branches/'): + extra['branch'] = ref[len('refs/heads/branches/'):] + if mode == 'hg': i = data.find('\n--HG--\n') if i >= 0: From b0c3db860cac2215f07deeb9e91cbd2597fe41d0 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:23:09 -0500 Subject: [PATCH 13/21] remote-hg: force remote push Ideally we shouldn't do this, as it's not recommended in mercurial documentation, but there's no other way to push multiple bookmarks (on the same branch), which would be the behavior most similar to git. At the same time, add a configuration option for the people that don't want to risk creating new remote heads. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index ec599c60f..ff8972579 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -27,6 +27,9 @@ import urllib # named branches: # git config --global remote-hg.track-branches false # +# If you don't want to force pushes (and thus risk creating new remote heads): +# git config --global remote-hg.force-push false +# # git: # Sensible defaults for git. # hg bookmarks are exported as git branches, hg branches are prefixed @@ -730,7 +733,7 @@ def do_export(parser): continue if peer: - parser.repo.push(peer, force=False) + parser.repo.push(peer, force=force_push) # handle bookmarks for bmark, node in p_bmarks: @@ -773,7 +776,7 @@ def main(args): global prefix, dirname, branches, bmarks global marks, blob_marks, parsed_refs global peer, mode, bad_mail, bad_name - global track_branches + global track_branches, force_push alias = args[1] url = args[2] @@ -781,12 +784,16 @@ def main(args): hg_git_compat = False track_branches = True + force_push = True + try: if get_config('remote-hg.hg-git-compat') == 'true\n': hg_git_compat = True track_branches = False if get_config('remote-hg.track-branches') == 'false\n': track_branches = False + if get_config('remote-hg.force-push') == 'false\n': + force_push = False except subprocess.CalledProcessError: pass From cbf6237c2ba989794815f980af1d26860840daf6 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:23:10 -0500 Subject: [PATCH 14/21] remote-hg: show more proper errors When cloning or pushing fails, we don't want to show a stack-trace. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index ff8972579..3ae3598a2 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -9,7 +9,7 @@ # Then you can clone with: # git clone hg::/path/to/mercurial/repo/ -from mercurial import hg, ui, bookmarks, context, util, encoding, node +from mercurial import hg, ui, bookmarks, context, util, encoding, node, error import re import sys @@ -284,11 +284,17 @@ def get_repo(url, alias): else: local_path = os.path.join(dirname, 'clone') if not os.path.exists(local_path): - peer, dstpeer = hg.clone(myui, {}, url, local_path, update=False, pull=True) + try: + peer, dstpeer = hg.clone(myui, {}, url, local_path, update=True, pull=True) + except: + die('Repository error') repo = dstpeer.local() else: repo = hg.repository(myui, local_path) - peer = hg.peer(myui, {}, url) + try: + peer = hg.peer(myui, {}, url) + except: + die('Repository error') repo.pull(peer, heads=None, force=True) return repo From 6181b9a63ceccce9aff29b14f3872f2c3d187d45 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:23:11 -0500 Subject: [PATCH 15/21] remote-hg: add basic author tests Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/test-hg.sh | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/contrib/remote-helpers/test-hg.sh b/contrib/remote-helpers/test-hg.sh index 5f81dfae6..62e3a473b 100755 --- a/contrib/remote-helpers/test-hg.sh +++ b/contrib/remote-helpers/test-hg.sh @@ -118,4 +118,39 @@ test_expect_success 'update bookmark' ' hg -R hgrepo bookmarks | grep "devel\s\+3:" ' +author_test () { + echo $1 >> content && + hg commit -u "$2" -m "add $1" && + echo "$3" >> ../expected +} + +test_expect_success 'authors' ' + mkdir -p tmp && cd tmp && + test_when_finished "cd .. && rm -rf tmp" && + + ( + hg init hgrepo && + cd hgrepo && + + touch content && + hg add content && + + author_test alpha "" "H G Wells " && + author_test beta "test" "test " && + author_test beta "test (comment)" "test " && + author_test gamma "" "Unknown " && + author_test delta "name" "name " && + author_test epsilon "name " && + author_test zeta " test " "test " && + author_test eta "test < test@example.com >" "test " && + author_test theta "test >test@example.com>" "test " && + author_test iota "test < test example com>" "test " + ) && + + git clone "hg::$PWD/hgrepo" gitrepo && + git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual && + + test_cmp expected actual +' + test_done From b3ab6fd1ac692397b43559385ac4a57c45ce83ec Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:23:12 -0500 Subject: [PATCH 16/21] remote-hg: add simple mail test Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/test-hg.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/remote-helpers/test-hg.sh b/contrib/remote-helpers/test-hg.sh index 62e3a473b..6a1e4b1ad 100755 --- a/contrib/remote-helpers/test-hg.sh +++ b/contrib/remote-helpers/test-hg.sh @@ -144,7 +144,8 @@ test_expect_success 'authors' ' author_test zeta " test " "test " && author_test eta "test < test@example.com >" "test " && author_test theta "test >test@example.com>" "test " && - author_test iota "test < test example com>" "test " + author_test iota "test < test example com>" "test " && + author_test kappa "test@example.com" "test@example.com " ) && git clone "hg::$PWD/hgrepo" gitrepo && From 2e8e813232d33bb7454cc56edb4b5336b7c89ccd Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Thu, 11 Apr 2013 07:23:13 -0500 Subject: [PATCH 17/21] remote-hg: add 'insecure' option If set to true acts as hg's clone/pull --insecure option. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 3ae3598a2..3eb07dc93 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -30,6 +30,9 @@ import urllib # If you don't want to force pushes (and thus risk creating new remote heads): # git config --global remote-hg.force-push false # +# If you want the equivalent of hg's clone/pull--insecure option: +# git config remote-hg.insecure true +# # git: # Sensible defaults for git. # hg bookmarks are exported as git branches, hg branches are prefixed @@ -279,6 +282,12 @@ def get_repo(url, alias): myui.setconfig('ui', 'interactive', 'off') myui.fout = sys.stderr + try: + if get_config('remote-hg.insecure') == 'true\n': + myui.setconfig('web', 'cacerts', '') + except subprocess.CalledProcessError: + pass + if hg.islocal(url): repo = hg.repository(myui, url) else: From 2594a79ea9d34053384d514afd5dcaaaeed15480 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:23:14 -0500 Subject: [PATCH 18/21] remote-hg: fix bad state issue The problem reportedly happened after doing a push that fails, the abort causes the state of remote-hg to go bad, this happens because remote-hg's marks are not stored, but 'git fast-export' marks are. Ensure that the marks are _always_ stored. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 3eb07dc93..e3d7f7787 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -18,6 +18,7 @@ import json import shutil import subprocess import urllib +import atexit # # If you want to switch to hg-git compatibility mode: @@ -791,7 +792,7 @@ def main(args): global prefix, dirname, branches, bmarks global marks, blob_marks, parsed_refs global peer, mode, bad_mail, bad_name - global track_branches, force_push + global track_branches, force_push, is_tmp alias = args[1] url = args[2] @@ -833,6 +834,7 @@ def main(args): bmarks = {} blob_marks = {} parsed_refs = {} + marks = None repo = get_repo(url, alias) prefix = 'refs/hg/%s' % alias @@ -860,9 +862,13 @@ def main(args): die('unhandled command: %s' % line) sys.stdout.flush() +def bye(): + if not marks: + return if not is_tmp: marks.store() else: shutil.rmtree(dirname) +atexit.register(bye) sys.exit(main(sys.argv)) From 7b21ec24a54c412d3a4f1d5d5d32370876ec5327 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Thu, 11 Apr 2013 07:23:15 -0500 Subject: [PATCH 19/21] remote-hg: document location of stored hg repository Signed-off-by: Simon Ruderich Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index e3d7f7787..0db4ccae5 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -8,6 +8,9 @@ # Just copy to your ~/bin, or anywhere in your $PATH. # Then you can clone with: # git clone hg::/path/to/mercurial/repo/ +# +# For remote repositories a local clone is stored in +# "$GIT_DIR/hg/origin/clone/.hg/". from mercurial import hg, ui, bookmarks, context, util, encoding, node, error From 20c4b59c352529bda3f5d44baba5e393badc2ee8 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 11 Apr 2013 07:23:16 -0500 Subject: [PATCH 20/21] remote-hg: fix bad file paths Mercurial allows absolute file paths, and Git doesn't like that. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-hg | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 0db4ccae5..a5f0013c6 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -205,9 +205,15 @@ class Parser: tz = ((tz / 100) * 3600) + ((tz % 100) * 60) return (user, int(date), -tz) +def fix_file_path(path): + if not os.path.isabs(path): + return path + return os.path.relpath(path, '/') + def export_file(fc): d = fc.data() - print "M %s inline %s" % (gitmode(fc.flags()), fc.path()) + path = fix_file_path(fc.path()) + print "M %s inline %s" % (gitmode(fc.flags()), path) print "data %d" % len(d) print d @@ -401,7 +407,7 @@ def export_ref(repo, name, kind, head): for f in modified: export_file(c.filectx(f)) for f in removed: - print "D %s" % (f) + print "D %s" % (fix_file_path(f)) print count += 1 From 9a57988b3fac79e0458515a555392d00b759cf4c Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Thu, 11 Apr 2013 07:23:17 -0500 Subject: [PATCH 21/21] remote-hg: activate graphlog extension for hg_log() The hg_log() test helper uses the "--graph" parameter that is implemented by the GraphLog extension. If the extension is not activated by the user, the parameter is not available. Activate the extension in setup(). Also changes the way we grep the output in hg_log(). The pipe operator can hide the return code of hg command. As a matter of fact, if log fails because it doesn't know about "--graph", it doesn't report any failure and let's you think everything worked. Signed-off-by: Antoine Pelisse Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/test-hg-bidi.sh | 5 ++++- contrib/remote-helpers/test-hg-hg-git.sh | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/contrib/remote-helpers/test-hg-bidi.sh b/contrib/remote-helpers/test-hg-bidi.sh index a3c88f65b..f36895311 100755 --- a/contrib/remote-helpers/test-hg-bidi.sh +++ b/contrib/remote-helpers/test-hg-bidi.sh @@ -50,7 +50,8 @@ hg_push () { } hg_log () { - hg -R $1 log --graph --debug | grep -v 'tag: *default/' + hg -R $1 log --graph --debug >log && + grep -v 'tag: *default/' log } setup () { @@ -62,6 +63,8 @@ setup () { echo "commit = -d \"0 0\"" echo "debugrawcommit = -d \"0 0\"" echo "tag = -d \"0 0\"" + echo "[extensions]" + echo "graphlog =" ) >> "$HOME"/.hgrc && git config --global remote-hg.hg-git-compat true diff --git a/contrib/remote-helpers/test-hg-hg-git.sh b/contrib/remote-helpers/test-hg-hg-git.sh index 8c59d8e72..5daad6b96 100755 --- a/contrib/remote-helpers/test-hg-hg-git.sh +++ b/contrib/remote-helpers/test-hg-hg-git.sh @@ -78,7 +78,8 @@ hg_push_hg () { } hg_log () { - hg -R $1 log --graph --debug | grep -v 'tag: *default/' + hg -R $1 log --graph --debug >log && + grep -v 'tag: *default/' log } git_log () { @@ -97,6 +98,7 @@ setup () { echo "[extensions]" echo "hgext.bookmarks =" echo "hggit =" + echo "graphlog =" ) >> "$HOME"/.hgrc && git config --global receive.denycurrentbranch warn git config --global remote-hg.hg-git-compat true