Merge branch 'ap/remote-hg-skip-null-bookmarks'
authorJunio C Hamano <gitster@pobox.com>
Wed, 2 Apr 2014 21:18:23 +0000 (14:18 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 2 Apr 2014 21:18:23 +0000 (14:18 -0700)
* ap/remote-hg-skip-null-bookmarks:
remote-hg: do not fail on invalid bookmarks

1  2 
contrib/remote-helpers/git-remote-hg
contrib/remote-helpers/test-hg.sh
index eb89ef67798e70fd77eff341e3dda5385d3cde48,61562b117c2f023961cdf8e80869dd8b47c8d25f..36b526106ba7b3c61b70549770c1ec82f45e1baf
@@@ -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
      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
index a933b1e30c6fe82393f3df1446333386d9795b12,88344821c31f0d2eaa151d173c9cf74c1b8a9f8a..7d90056cf346e69891ec455e44ba16e88f32af90
@@@ -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 <wells@example.com>" &&
 -      author_test beta "test" "test <unknown>" &&
 -      author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
 -      author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
 -      author_test delta "name<test@example.com>" "name <test@example.com>" &&
 -      author_test epsilon "name <test@example.com" "name <test@example.com>" &&
 -      author_test zeta " test " "test <unknown>" &&
 -      author_test eta "test < test@example.com >" "test <test@example.com>" &&
 -      author_test theta "test >test@example.com>" "test <test@example.com>" &&
 -      author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
 -      author_test kappa "test@example.com" "Unknown <test@example.com>"
 +      author_test beta "beta" "beta <unknown>" &&
 +      author_test gamma "gamma <test@example.com> (comment)" "gamma <test@example.com>" &&
 +      author_test delta "<delta@example.com>" "Unknown <delta@example.com>" &&
 +      author_test epsilon "epsilon<test@example.com>" "epsilon <test@example.com>" &&
 +      author_test zeta "zeta <test@example.com" "zeta <test@example.com>" &&
 +      author_test eta " eta " "eta <unknown>" &&
 +      author_test theta "theta < test@example.com >" "theta <test@example.com>" &&
 +      author_test iota "iota >test@example.com>" "iota <test@example.com>" &&
 +      author_test kappa "kappa < test <at> example <dot> com>" "kappa <unknown>" &&
 +      author_test lambda "lambda@example.com" "Unknown <lambda@example.com>" &&
 +      author_test mu "mu.mu@example.com" "Unknown <mu.mu@example.com>"
        ) &&
  
        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
        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