# [PATCH 0/4] remote-hg: small fixes

11 messages from 2012-11-12 to 2012-11-13. Participants: Felipe Contreras, Jeff King, Ramkumar Ramachandra.
Thread: https://gitlist.dev/t/32091

## Felipe Contreras, 2012-11-12 17:41

Subject: [PATCH 0/4] remote-hg: small fixes
Message-ID: <1352742068-15346-1-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1352742068-15346-1-git-send-email-felipe.contreras%40gmail.com

```
Hi,

Just a few fixes, nothing major.

Felipe Contreras (3):
  remote-hg: fix compatibility with older versions of hg
  remote-hg: try the 'tip' if no checkout present
  remote-hg: avoid bad refs

Ramkumar Ramachandra (1):
  remote-hg: add missing config for basic tests

 contrib/remote-helpers/git-remote-hg | 7 ++++++-
 contrib/remote-helpers/test-hg.sh    | 9 +++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

-- 
1.8.0

```

## Felipe Contreras, 2012-11-12 17:41

Subject: [PATCH 1/4] remote-hg: add missing config for basic tests
Message-ID: <1352742068-15346-2-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1352742068-15346-2-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1352742068-15346-1-git-send-email-felipe.contreras@gmail.com>

```
From: Ramkumar Ramachandra <artagnon@gmail.com>

'hg commit' fails otherwise in some versiosn of mercurial because of
the missing user information. Other versions simply throw a warning and
guess though.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/test-hg.sh | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/contrib/remote-helpers/test-hg.sh b/contrib/remote-helpers/test-hg.sh
index 40e6e3c..031dcbd 100755
--- a/contrib/remote-helpers/test-hg.sh
+++ b/contrib/remote-helpers/test-hg.sh
@@ -29,6 +29,15 @@ check () {
 	test_cmp expected actual
 }
 
+setup () {
+	(
+	echo "[ui]"
+	echo "username = A U Thor <author@example.com>"
+	) >> "$HOME"/.hgrc
+}
+
+setup
+
 test_expect_success 'cloning' '
   test_when_finished "rm -rf gitrepo*" &&
 
-- 
1.8.0

```

## Felipe Contreras, 2012-11-12 17:41

Subject: [PATCH 2/4] remote-hg: fix compatibility with older versions of hg
Message-ID: <1352742068-15346-3-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1352742068-15346-3-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1352742068-15346-1-git-send-email-felipe.contreras@gmail.com>

```
Turns out repo.revs was introduced quite late, and it doesn't do
anything fancy for our refspec; only list all the numbers in that range.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/git-remote-hg | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg
index 1d46838..c6d0367 100755
--- a/contrib/remote-helpers/git-remote-hg
+++ b/contrib/remote-helpers/git-remote-hg
@@ -294,7 +294,7 @@ def export_ref(repo, name, kind, head):
     if tip and tip == head.rev():
         # nothing to do
         return
-    revs = repo.revs('%u:%u' % (tip, head))
+    revs = xrange(tip, head.rev() + 1)
     count = 0
 
     revs = [rev for rev in revs if not marks.is_marked(rev)]
-- 
1.8.0

```

## Felipe Contreras, 2012-11-12 17:41

Subject: [PATCH 3/4] remote-hg: try the 'tip' if no checkout present
Message-ID: <1352742068-15346-4-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1352742068-15346-4-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1352742068-15346-1-git-send-email-felipe.contreras@gmail.com>

```
There's no concept of HEAD in mercurial, but let's try our best to do
something sensible.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/git-remote-hg | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg
index c6d0367..3cdc1e2 100755
--- a/contrib/remote-helpers/git-remote-hg
+++ b/contrib/remote-helpers/git-remote-hg
@@ -440,6 +440,8 @@ def list_head(repo, cur):
         head = cur
         node = repo['.']
         if not node:
+            node = repo['tip']
+        if not node:
             return
         if head == 'default':
             head = 'master'
-- 
1.8.0

```

## Felipe Contreras, 2012-11-12 17:41

Subject: [PATCH 4/4] remote-hg: avoid bad refs
Message-ID: <1352742068-15346-5-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1352742068-15346-5-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1352742068-15346-1-git-send-email-felipe.contreras@gmail.com>

```
Turns out fast-export throws bad 'reset' commands because of a behavior
in transport-helper that is not even needed.

Either way, better to ignore them, otherwise the user will get warnings
when we OK them.

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 3cdc1e2..48f8f5d 100755
--- a/contrib/remote-helpers/git-remote-hg
+++ b/contrib/remote-helpers/git-remote-hg
@@ -704,6 +704,9 @@ def do_export(parser):
         elif ref.startswith('refs/tags/'):
             tag = ref[len('refs/tags/'):]
             parser.repo.tag([tag], node, None, True, None, {})
+        else:
+            # transport-helper/fast-export bugs
+            continue
         print "ok %s" % ref
 
     print
-- 
1.8.0

```

## Jeff King, 2012-11-12 20:32

Subject: Re: [PATCH 1/4] remote-hg: add missing config for basic tests
Message-ID: <20121112203207.GF4623@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20121112203207.GF4623%40sigill.intra.peff.net
In-Reply-To: <1352742068-15346-2-git-send-email-felipe.contreras@gmail.com>

```
On Mon, Nov 12, 2012 at 06:41:05PM +0100, Felipe Contreras wrote:

> From: Ramkumar Ramachandra <artagnon@gmail.com>
> 
> 'hg commit' fails otherwise in some versiosn of mercurial because of

s/versiosn/versions/

> +setup () {
> +	(
> +	echo "[ui]"
> +	echo "username = A U Thor <author@example.com>"
> +	) >> "$HOME"/.hgrc
> +}

This makes sense, but I wonder if we should use something different from
the git author ident set up by the test scripts, just to double check
that we do not have any bugs in confusing the two during the import.

Something like "H G Wells <wells@example.com>" would work, and satisfies
my deep-seated desire for bad puns.

-Peff

```

## Felipe Contreras, 2012-11-13 03:46

Subject: Re: [PATCH 1/4] remote-hg: add missing config for basic tests
Message-ID: <CAMP44s2GzX_+6+eNU5n6kGue_-MWvU9qNXAr3Caw3A7nWhkawA@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s2GzX_%2B6%2BeNU5n6kGue_-MWvU9qNXAr3Caw3A7nWhkawA%40mail.gmail.com
In-Reply-To: <20121112203207.GF4623@sigill.intra.peff.net>

```
On Mon, Nov 12, 2012 at 9:32 PM, Jeff King <peff@peff.net> wrote:
> On Mon, Nov 12, 2012 at 06:41:05PM +0100, Felipe Contreras wrote:
>
>> From: Ramkumar Ramachandra <artagnon@gmail.com>
>>
>> 'hg commit' fails otherwise in some versiosn of mercurial because of
>
> s/versiosn/versions/
>
>> +setup () {
>> +     (
>> +     echo "[ui]"
>> +     echo "username = A U Thor <author@example.com>"
>> +     ) >> "$HOME"/.hgrc
>> +}
>
> This makes sense, but I wonder if we should use something different from
> the git author ident set up by the test scripts, just to double check
> that we do not have any bugs in confusing the two during the import.

I don't know, but these tests would not check for any of those issues.
When such tests are added I would prefer the author to use to be
explicitly defined, but lets see.

-- 
Felipe Contreras

```

## Ramkumar Ramachandra, 2012-11-13 05:25

Subject: Re: [PATCH 2/4] remote-hg: fix compatibility with older versions of hg
Message-ID: <CALkWK0k9Ta-SOo43Knz9kMV0ePKf7wjK-3Zm6ocDQpe7VzFz+A@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0k9Ta-SOo43Knz9kMV0ePKf7wjK-3Zm6ocDQpe7VzFz%2BA%40mail.gmail.com
In-Reply-To: <1352742068-15346-3-git-send-email-felipe.contreras@gmail.com>

```
This patch fixes my original problem. So,
Reported-by: Ramkumar Ramachandra <artagnon@gmail.com>
Tested-by: Ramkumar Ramachandra <artagnon@gmail.com>

However, test 4 in test-hg.sh still fails for me:

--- expected    2012-11-13 05:22:57.946637384 +0000
+++ actual      2012-11-13 05:22:57.946637384 +0000
@@ -1,2 +1,2 @@
-zero
-refs/heads/master
+feature-a
+refs/heads/feature-a

What is going on?

Ram

```

## Jeff King, 2012-11-13 05:48

Subject: Re: [PATCH 1/4] remote-hg: add missing config for basic tests
Message-ID: <20121113054826.GC10995@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20121113054826.GC10995%40sigill.intra.peff.net
In-Reply-To: <CAMP44s2GzX_+6+eNU5n6kGue_-MWvU9qNXAr3Caw3A7nWhkawA@mail.gmail.com>

```
On Tue, Nov 13, 2012 at 04:46:36AM +0100, Felipe Contreras wrote:

> >> +setup () {
> >> +     (
> >> +     echo "[ui]"
> >> +     echo "username = A U Thor <author@example.com>"
> >> +     ) >> "$HOME"/.hgrc
> >> +}
> >
> > This makes sense, but I wonder if we should use something different from
> > the git author ident set up by the test scripts, just to double check
> > that we do not have any bugs in confusing the two during the import.
> 
> I don't know, but these tests would not check for any of those issues.
> When such tests are added I would prefer the author to use to be
> explicitly defined, but lets see.

It's OK if we do not add more explicit tests at this point. I'd just
rather set a safer precedent on the off chance that it might catch
something in a later test, just as we use separate GIT_AUTHOR_* and
GIT_COMMITTER_* in the rest of the test suite. If the choice were not
completely arbitrary and had some maintenance cost, I might be more
concerned, but as far as I can tell, one name is as good as another at
this point.

Any objection to me marking it up as I apply?

-Peff

```

## Felipe Contreras, 2012-11-13 07:11

Subject: Re: [PATCH 2/4] remote-hg: fix compatibility with older versions of hg
Message-ID: <CAMP44s3GQOVUGOMsz=U5zbecsHybejjH-KLgmbmJsbnzFzC+qg@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s3GQOVUGOMsz%3DU5zbecsHybejjH-KLgmbmJsbnzFzC%2Bqg%40mail.gmail.com
In-Reply-To: <CALkWK0k9Ta-SOo43Knz9kMV0ePKf7wjK-3Zm6ocDQpe7VzFz+A@mail.gmail.com>

```
On Tue, Nov 13, 2012 at 6:25 AM, Ramkumar Ramachandra
<artagnon@gmail.com> wrote:
> This patch fixes my original problem. So,
> Reported-by: Ramkumar Ramachandra <artagnon@gmail.com>
> Tested-by: Ramkumar Ramachandra <artagnon@gmail.com>
>
> However, test 4 in test-hg.sh still fails for me:
>
> --- expected    2012-11-13 05:22:57.946637384 +0000
> +++ actual      2012-11-13 05:22:57.946637384 +0000
> @@ -1,2 +1,2 @@
> -zero
> -refs/heads/master
> +feature-a
> +refs/heads/feature-a
>
> What is going on?

Probably a bug in mercurial, but can be worked around:

--- a/contrib/remote-helpers/git-remote-hg
+++ b/contrib/remote-helpers/git-remote-hg
@@ -429,10 +429,18 @@ def get_branch_tip(repo, branch):

     return heads[0]

+def get_current_bookmark(repo):
+    head = bookmarks.readcurrent(repo)
+    if not head:
+        return None
+    if repo[head] != repo['.']:
+        return None
+    return head
+
 def list_head(repo, cur):
     global g_head, bmarks

-    head = bookmarks.readcurrent(repo)
+    head = get_current_bookmark(repo)
     if head:
         node = repo[head]
     else:

-- 
Felipe Contreras

```

## Felipe Contreras, 2012-11-13 07:12

Subject: Re: [PATCH 1/4] remote-hg: add missing config for basic tests
Message-ID: <CAMP44s2AH=JmopgMsrhuKm20WAh7yP5B6vz7oew9FL-nu+c4rA@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s2AH%3DJmopgMsrhuKm20WAh7yP5B6vz7oew9FL-nu%2Bc4rA%40mail.gmail.com
In-Reply-To: <20121113054826.GC10995@sigill.intra.peff.net>

```
On Tue, Nov 13, 2012 at 6:48 AM, Jeff King <peff@peff.net> wrote:

> Any objection to me marking it up as I apply?

Nope.

-- 
Felipe Contreras

```
