From: Junio C Hamano Date: Wed, 2 Apr 2014 21:18:23 +0000 (-0700) Subject: Merge branch 'ap/remote-hg-skip-null-bookmarks' X-Git-Tag: v2.0.0-rc0~31 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/125d8ecefe817db2d51dd5a85c287989ef8a0c0b?ds=inline;hp=-c Merge branch 'ap/remote-hg-skip-null-bookmarks' * ap/remote-hg-skip-null-bookmarks: remote-hg: do not fail on invalid bookmarks --- 125d8ecefe817db2d51dd5a85c287989ef8a0c0b diff --combined contrib/remote-helpers/git-remote-hg index eb89ef6779,61562b117c..36b526106b --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@@ -51,8 -51,8 +51,8 @@@ import time as ptim # NAME_RE = re.compile('^([^<>]+)') -AUTHOR_RE = re.compile('^([^<>]+?)? ?<([^<>]*)>$') -EMAIL_RE = re.compile('^([^<>]+[^ \\\t<>])?\\b(?:[ \\t<>]*?)\\b([^ \\t<>]+@[^ \\t<>]+)') +AUTHOR_RE = re.compile('^([^<>]+?)? ?[<>]([^<>]*)(?:$|>)') +EMAIL_RE = re.compile(r'([^ \t<>]+@[^ \t<>]+)') AUTHOR_HG_RE = re.compile('^(.*?) ?<(.*?)(?:>(.+)?)?$') RAW_AUTHOR_RE = re.compile('^(\w+) (?:(.+)? )?<(.*)> (\d+) ([+-]\d+)') @@@ -316,7 -316,8 +316,7 @@@ def fixup_user_git(user) else: m = EMAIL_RE.match(user) if m: - name = m.group(1) - mail = m.group(2) + mail = m.group(1) else: m = NAME_RE.match(user) if m: @@@ -415,9 -416,6 +415,9 @@@ def get_repo(url, alias) local_path = os.path.join(dirname, 'clone') if not os.path.exists(local_path): hg.share(myui, shared_path, local_path, update=False) + else: + # make sure the shared path is always up-to-date + util.writefile(os.path.join(local_path, '.hg', 'sharedpath'), hg_path) repo = hg.repository(myui, local_path) try: @@@ -540,7 -538,7 +540,7 @@@ def export_ref(repo, name, kind, head) print "commit %s" % ref print "mark :%d" % (note_mark) - print "committer remote-hg <> %s" % (ptime.strftime('%s %z')) + print "committer remote-hg <> %d %s" % (ptime.time(), gittz(ptime.timezone)) desc = "Notes for %s\n" % (name) print "data %d" % (len(desc)) print desc @@@ -643,7 -641,10 +643,10 @@@ def do_list(parser) print "? refs/heads/branches/%s" % gitref(branch) for bmark in bmarks: - print "? refs/heads/%s" % gitref(bmark) + if bmarks[bmark].hex() == '0000000000000000000000000000000000000000': + warn("Ignoring invalid bookmark '%s'", bmark) + else: + print "? refs/heads/%s" % gitref(bmark) for tag, node in repo.tagslist(): if tag == 'tip': @@@ -1167,16 -1168,6 +1170,16 @@@ def main(args) global dry_run global notes, alias + marks = None + is_tmp = False + gitdir = os.environ.get('GIT_DIR', None) + + if len(args) < 3: + die('Not enough arguments.') + + if not gitdir: + die('GIT_DIR not set') + alias = args[1] url = args[2] peer = None @@@ -1197,12 -1188,16 +1200,12 @@@ if alias[4:] == url: is_tmp = True alias = hashlib.sha1(alias).hexdigest() - else: - is_tmp = False - gitdir = os.environ['GIT_DIR'] dirname = os.path.join(gitdir, 'hg', alias) branches = {} bmarks = {} blob_marks = {} parsed_refs = {} - marks = None parsed_tags = {} filenodes = {} fake_bmark = None diff --combined contrib/remote-helpers/test-hg.sh index a933b1e30c,88344821c3..7d90056cf3 --- a/contrib/remote-helpers/test-hg.sh +++ b/contrib/remote-helpers/test-hg.sh @@@ -8,8 -8,7 +8,8 @@@ test_description='Test remote-hg' -. ./test-lib.sh +test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t +. "$TEST_DIRECTORY"/test-lib.sh if ! test_have_prereq PYTHON then @@@ -54,14 -53,14 +54,14 @@@ check_bookmark () } check_push () { - local expected_ret=$1 ret=0 ref_ret=0 IFS=':' + expected_ret=$1 ret=0 ref_ret=0 shift git push origin "$@" 2>error ret=$? cat error - while read branch kind + while IFS=':' read branch kind do case "$kind" in 'new') @@@ -83,7 -82,7 +83,7 @@@ test $ref_ret -ne 0 && echo "match for '$branch' failed" && break done - if test $expected_ret -ne $ret -o $ref_ret -ne 0 + if test $expected_ret -ne $ret || test $ref_ret -ne 0 then return 1 fi @@@ -206,17 -205,16 +206,17 @@@ test_expect_success 'authors' >../expected && 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 " && - author_test kappa "test@example.com" "Unknown " + author_test beta "beta" "beta " && + author_test gamma "gamma (comment)" "gamma " && + author_test delta "" "Unknown " && + author_test epsilon "epsilon" "epsilon " && + author_test zeta "zeta " && + author_test eta " eta " "eta " && + author_test theta "theta < test@example.com >" "theta " && + author_test iota "iota >test@example.com>" "iota " && + author_test kappa "kappa < test example com>" "kappa " && + author_test lambda "lambda@example.com" "Unknown " && + author_test mu "mu.mu@example.com" "Unknown " ) && git clone "hg::hgrepo" gitrepo && @@@ -337,17 -335,6 +337,17 @@@ test_expect_success 'remote cloning' check gitrepo HEAD zero ' +test_expect_success 'moving remote clone' ' + test_when_finished "rm -rf gitrepo*" && + + ( + git clone "hg::hgrepo" gitrepo && + mv gitrepo gitrepo2 && + cd gitrepo2 && + git fetch + ) +' + test_expect_success 'remote update bookmark' ' test_when_finished "rm -rf gitrepo*" && @@@ -455,74 -442,6 +455,74 @@@ test_expect_success 'remote new bookmar # cleanup previous stuff rm -rf hgrepo +test_expect_success 'fetch special filenames' ' + test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" && + + LC_ALL=en_US.UTF-8 + export LC_ALL + + ( + hg init hgrepo && + cd hgrepo && + + echo test >> "æ rø" && + hg add "æ rø" && + echo test >> "ø~?" && + hg add "ø~?" && + hg commit -m add-utf-8 && + echo test >> "æ rø" && + hg commit -m test-utf-8 && + hg rm "ø~?" && + hg mv "æ rø" "ø~?" && + hg commit -m hg-mv-utf-8 + ) && + + ( + git clone "hg::hgrepo" gitrepo && + cd gitrepo && + git -c core.quotepath=false ls-files > ../actual + ) && + echo "ø~?" > expected && + test_cmp expected actual +' + +test_expect_success 'push special filenames' ' + test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" && + + mkdir -p tmp && cd tmp && + + LC_ALL=en_US.UTF-8 + export LC_ALL + + ( + hg init hgrepo && + cd hgrepo && + + echo one >> content && + hg add content && + hg commit -m one + ) && + + ( + git clone "hg::hgrepo" gitrepo && + cd gitrepo && + + echo test >> "æ rø" && + git add "æ rø" && + git commit -m utf-8 && + + git push + ) && + + (cd hgrepo && + hg update && + hg manifest > ../actual + ) && + + printf "content\næ rø\n" > expected && + test_cmp expected actual +' + setup_big_push () { ( hg init hgrepo && @@@ -680,7 -599,7 +680,7 @@@ test_expect_success 'remote big push fe ) ' -test_expect_failure 'remote big push force' ' +test_expect_success 'remote big push force' ' test_when_finished "rm -rf hgrepo gitrepo*" && setup_big_push @@@ -710,7 -629,7 +710,7 @@@ check_bookmark hgrepo new_bmark six ' -test_expect_failure 'remote big push dry-run' ' +test_expect_success 'remote big push dry-run' ' test_when_finished "rm -rf hgrepo gitrepo*" && setup_big_push @@@ -772,4 -691,77 +772,77 @@@ test_expect_success 'remote double fail ) ' + test_expect_success 'clone remote with master null bookmark, then push to the bookmark' ' + test_when_finished "rm -rf gitrepo* hgrepo*" && + + hg init hgrepo && + ( + cd hgrepo && + echo a >a && + hg add a && + hg commit -m a && + hg bookmark -r null master + ) && + + git clone "hg::hgrepo" gitrepo && + check gitrepo HEAD a && + ( + cd gitrepo && + git checkout --quiet -b master && + echo b >b && + git add b && + git commit -m b && + git push origin master + ) + ' + + test_expect_success 'clone remote with default null bookmark, then push to the bookmark' ' + test_when_finished "rm -rf gitrepo* hgrepo*" && + + hg init hgrepo && + ( + cd hgrepo && + echo a >a && + hg add a && + hg commit -m a && + hg bookmark -r null -f default + ) && + + git clone "hg::hgrepo" gitrepo && + check gitrepo HEAD a && + ( + cd gitrepo && + git checkout --quiet -b default && + echo b >b && + git add b && + git commit -m b && + git push origin default + ) + ' + + test_expect_success 'clone remote with generic null bookmark, then push to the bookmark' ' + test_when_finished "rm -rf gitrepo* hgrepo*" && + + hg init hgrepo && + ( + cd hgrepo && + echo a >a && + hg add a && + hg commit -m a && + hg bookmark -r null bmark + ) && + + git clone "hg::hgrepo" gitrepo && + check gitrepo HEAD a && + ( + cd gitrepo && + git checkout --quiet -b bmark && + git remote -v && + echo b >b && + git add b && + git commit -m b && + git push origin bmark + ) + ' + test_done