# [PATCH v3 00/20] remote-hg: general updates

24 messages from 2013-04-08 to 2013-04-10. Participants: Felipe Contreras, Junio C Hamano.
Thread: https://gitlist.dev/t/33434

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 00/20] remote-hg: general updates
Message-ID: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-1-git-send-email-felipe.contreras%40gmail.com

```
Hi,

Since forced pushes make some people nervous, this new patch series adds a
configuration variable. Also, I added a few more patches that should be safe,
fix important issues and/or add nice features.

I'm still holding on to the ones that I consider less safe.

Dusty Phillips (2):
  remote-hg: add missing config variable in doc
  remote-hg: push to the appropriate branch

Felipe Contreras (15):
  remote-hg: trivial cleanups
  remote-hg: properly report errors on bookmark pushes
  remote-hg: make sure fake bookmarks are updated
  remote-hg: trivial test cleanups
  remote-hg: redirect buggy mercurial output
  remote-hg: split bookmark handling
  remote-hg: refactor export
  remote-hg: update remote bookmarks
  remote-hg: update tags globally
  remote-hg: force remote push
  remote-hg: show more proper errors
  remote-hg: add basic author tests
  remote-hg: add simple mail test
  remote-hg: fix bad state issue
  remote-hg: fix bad file paths

Peter van Zetten (1):
  remote-hg: fix for files with spaces

Simon Ruderich (2):
  remote-hg: add 'insecure' option
  remote-hg: document location of stored hg repository

 contrib/remote-helpers/git-remote-hg     | 122 +++++++++++++++++++++++++------
 contrib/remote-helpers/test-hg-bidi.sh   |   6 +-
 contrib/remote-helpers/test-hg-hg-git.sh |   4 +-
 contrib/remote-helpers/test-hg.sh        |  36 +++++++++
 4 files changed, 141 insertions(+), 27 deletions(-)

-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 01/20] remote-hg: trivial cleanups
Message-ID: <1365441214-21096-2-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-2-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 328c2dc..d0dfb1e 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)
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 02/20] remote-hg: add missing config variable in doc
Message-ID: <1365441214-21096-3-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-3-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
From: Dusty Phillips <dusty@linux.ca>

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 d0dfb1e..844ec50 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
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 03/20] remote-hg: properly report errors on bookmark pushes
Message-ID: <1365441214-21096-4-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-4-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 844ec50..19eb4db 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/'):]
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 04/20] remote-hg: fix for files with spaces
Message-ID: <1365441214-21096-5-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-5-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
From: Peter van Zetten <peter.van.zetten@cgi.com>

Set the maximum number of splits to make when dividing the diff stat
lines based on space characters.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 19eb4db..c6a1a47 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
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 05/20] remote-hg: make sure fake bookmarks are updated
Message-ID: <1365441214-21096-6-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-6-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 c6a1a47..b200e60 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 1d61982..fe38e49 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 3f253b7..e116cb0 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/*'
 	) &&
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 06/20] remote-hg: trivial test cleanups
Message-ID: <1365441214-21096-7-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-7-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 fe38e49..a3c88f6 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 e116cb0..73ae18d 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
 	)
 }
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 07/20] remote-hg: redirect buggy mercurial output
Message-ID: <1365441214-21096-8-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-8-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
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 <felipe.contreras@gmail.com>
---
 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 b200e60..874ccd4 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)
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 08/20] remote-hg: split bookmark handling
Message-ID: <1365441214-21096-9-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-9-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
Will be useful for remote bookmarks.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 874ccd4..6901689 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):
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 09/20] remote-hg: refactor export
Message-ID: <1365441214-21096-10-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-10-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
No functional changes.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 6901689..c741f13 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
 
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 10/20] remote-hg: update remote bookmarks
Message-ID: <1365441214-21096-11-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-11-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 c741f13..b54de1e 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
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 11/20] remote-hg: update tags globally
Message-ID: <1365441214-21096-12-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-12-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 b54de1e..bccdf4e 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
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 12/20] remote-hg: push to the appropriate branch
Message-ID: <1365441214-21096-13-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-13-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
From: Dusty Phillips <dusty@linux.ca>

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 bccdf4e..8f6809a 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.replace('refs/heads/branches/', '')
+
     if mode == 'hg':
         i = data.find('\n--HG--\n')
         if i >= 0:
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 13/20] remote-hg: force remote push
Message-ID: <1365441214-21096-14-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-14-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
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 <felipe.contreras@gmail.com>
---
 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 8f6809a..9fb4d8b 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
 
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 14/20] remote-hg: show more proper errors
Message-ID: <1365441214-21096-15-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-15-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
When cloning or pushing fails, we don't want to show a stack-trace.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 9fb4d8b..078d3e8 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
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 15/20] remote-hg: add basic author tests
Message-ID: <1365441214-21096-16-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-16-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 5f81dfa..62e3a47 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 <wells@example.com>" &&
+  author_test beta "test" "test <unknown>" &&
+  author_test beta "test <test@example.com> (comment)" "test <unknown>" &&
+  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 <unknown>" &&
+  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 <unknown>" &&
+  author_test iota "test < test <at> example <dot> com>" "test <unknown>"
+  ) &&
+
+  git clone "hg::$PWD/hgrepo" gitrepo &&
+  git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
+
+  test_cmp expected actual
+'
+
 test_done
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 16/20] remote-hg: add simple mail test
Message-ID: <1365441214-21096-17-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-17-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 62e3a47..6a1e4b1 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 <unknown>" &&
   author_test eta "test < test@example.com >" "test <test@example.com>" &&
   author_test theta "test >test@example.com>" "test <unknown>" &&
-  author_test iota "test < test <at> example <dot> com>" "test <unknown>"
+  author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
+  author_test kappa "test@example.com" "test@example.com <unknown>"
   ) &&
 
   git clone "hg::$PWD/hgrepo" gitrepo &&
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 17/20] remote-hg: add 'insecure' option
Message-ID: <1365441214-21096-18-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-18-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
From: Simon Ruderich <simon@ruderich.org>

If set to true acts as hg's clone/pull --insecure option.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 078d3e8..2f642a6 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:
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 18/20] remote-hg: fix bad state issue
Message-ID: <1365441214-21096-19-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-19-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
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 <felipe.contreras@gmail.com>
---
 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 2f642a6..a02ec68 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))
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 19/20] remote-hg: document location of stored hg repository
Message-ID: <1365441214-21096-20-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-20-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
From: Simon Ruderich <simon@ruderich.org>

Signed-off-by: Simon Ruderich <simon@ruderich.org>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 a02ec68..37e6aec 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
 
-- 
1.8.2

```

## Felipe Contreras, 2013-04-08 17:13

Subject: [PATCH v3 20/20] remote-hg: fix bad file paths
Message-ID: <1365441214-21096-21-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1365441214-21096-21-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1365441214-21096-1-git-send-email-felipe.contreras@gmail.com>

```
Mercurial allows absolute file paths, and Git doesn't like that.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 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 37e6aec..d45f16d 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
-- 
1.8.2

```

## Felipe Contreras, 2013-04-10 19:14

Subject: Re: [PATCH v3 08/20] remote-hg: split bookmark handling
Message-ID: <CAMP44s3VcUyQUNBw+19O-_nf9HPWt=2uc35Keh6Z0jcgFF=Y7A@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s3VcUyQUNBw%2B19O-_nf9HPWt%3D2uc35Keh6Z0jcgFF%3DY7A%40mail.gmail.com
In-Reply-To: <1365441214-21096-9-git-send-email-felipe.contreras@gmail.com>

```
On Mon, Apr 8, 2013 at 12:13 PM, Felipe Contreras
<felipe.contreras@gmail.com> wrote:

> --- a/contrib/remote-helpers/git-remote-hg
> +++ b/contrib/remote-helpers/git-remote-hg

> @@ -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

This should be:

ref = 'refs/heads/' + bmark

Should I reroll?

--
Felipe Contreras

```

## Felipe Contreras, 2013-04-10 19:15

Subject: Re: [PATCH v3 12/20] remote-hg: push to the appropriate branch
Message-ID: <CAMP44s06gKHiEuZF41OkE7tsBn5PAkyGXvmoiqvN1keKFZczJQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s06gKHiEuZF41OkE7tsBn5PAkyGXvmoiqvN1keKFZczJQ%40mail.gmail.com
In-Reply-To: <1365441214-21096-13-git-send-email-felipe.contreras@gmail.com>

```
On Mon, Apr 8, 2013 at 12:13 PM, Felipe Contreras
<felipe.contreras@gmail.com> wrote:

> --- 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.replace('refs/heads/branches/', '')

This should be more consistent with the rest of the code:

branch = ref[len('refs/heads/branches/'):]

Should I reroll?

--
Felipe Contreras

```

## Junio C Hamano, 2013-04-10 19:36

Subject: Re: [PATCH v3 08/20] remote-hg: split bookmark handling
Message-ID: <7vvc7ukwj8.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vvc7ukwj8.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CAMP44s3VcUyQUNBw+19O-_nf9HPWt=2uc35Keh6Z0jcgFF=Y7A@mail.gmail.com>

```
Felipe Contreras <felipe.contreras@gmail.com> writes:

> On Mon, Apr 8, 2013 at 12:13 PM, Felipe Contreras
> <felipe.contreras@gmail.com> wrote:
>
>> --- a/contrib/remote-helpers/git-remote-hg
>> +++ b/contrib/remote-helpers/git-remote-hg
>
>> @@ -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
>
> This should be:
>
> ref = 'refs/heads/' + bmark
>
> Should I reroll?

I'd appreciate it if you can reroll the entire thing.  That way, I
do not have to keep careful track of which one can be reused and
which need to be replaced.

Thanks.

```
