threads / patch / 36223

patch, 3 partsremote-hg: add test cases for null bookmarks

Subject: [PATCH 3/3] remote-hg: add test cases for null bookmarks

## tl;dr

6 messages between Mar 19, 2014 and Mar 19, 2014. Diffs are folded; open one to read it.

replies: 5people: 2as markdown or json

Max Horn· Mar 19, 2014, 12:33 UTC · lore

[PATCH 1/3] remote-hg: do not fail on invalid bookmarks

From: Antoine Pelisse <apelisse@gmail.com>

Mercurial can have bookmarks pointing to "nullid" (the empty root revision), while Git can not have references to it. When cloning or fetching from a Mercurial repository that has such a bookmark, the import will fail because git-remote-hg will not be able to create the corresponding reference.

Warn the user about the invalid reference, and continue the import, instead of stopping right away.

Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
Signed-off-by: Max Horn <max@quendi.de>
---
 contrib/remote-helpers/git-remote-hg | 3 +++
 1 file changed, 3 insertions(+)
Show changes to contrib/remote-helpers/git-remote-hg +3 −0
diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg
index eb89ef6..12d850e 100755
--- a/contrib/remote-helpers/git-remote-hg
+++ b/contrib/remote-helpers/git-remote-hg
@@ -625,6 +625,9 @@ def list_head(repo, cur):
 def do_list(parser):
     repo = parser.repo
     for bmark, node in bookmarks.listbookmarks(repo).iteritems():
+        if node == '0000000000000000000000000000000000000000':
+            warn("Ignoring invalid bookmark '%s'", bmark)
+            continue
         bmarks[bmark] = repo[node]
 
     cur = repo.dirstate.branch()
-- 
1.9.0.7.ga299b13
Max Horn· Mar 19, 2014, 12:33 UTC · re: Max Horn · lore

[PATCH 2/3] remote-hg: allow invalid bookmarks in a few edge cases

Fix the previous commit to workaround issues with edge cases: Specifically, remote-hg inserts a fake 'master' branch, unless the cloned hg repository already contains a 'master' bookmark. If that 'master' bookmark happens to reference the 'null' commit, the preceding fix ignores it. This would leave us in an inconsistent state. Avoid this by NOT ignoring null bookmarks named 'master' or 'default' under suitable circumstances.

Signed-off-by: Max Horn <max@quendi.de>
---
 contrib/remote-helpers/git-remote-hg | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Show changes to contrib/remote-helpers/git-remote-hg +5 −2
diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg
index 12d850e..49b2c2e 100755
--- a/contrib/remote-helpers/git-remote-hg
+++ b/contrib/remote-helpers/git-remote-hg
@@ -626,8 +626,11 @@ def do_list(parser):
     repo = parser.repo
     for bmark, node in bookmarks.listbookmarks(repo).iteritems():
         if node == '0000000000000000000000000000000000000000':
-            warn("Ignoring invalid bookmark '%s'", bmark)
-            continue
+            if fake_bmark == 'default' and bmark == 'master':
+                pass
+            else:
+                warn("Ignoring invalid bookmark '%s'", bmark)
+                continue
         bmarks[bmark] = repo[node]
 
     cur = repo.dirstate.branch()
-- 
1.9.0.7.ga299b13
Antoine Pelisse· Mar 19, 2014, 13:07 UTC · re: Max Horn · lore

Re: [PATCH 2/3] remote-hg: allow invalid bookmarks in a few edge cases

Hi Max,

Thank you for working on this. I believe it would be fair that you forget about patch 1/3 as you fix it in this patch (2/3). Also, I think it would be best NOT to integrate a patch (mine) that breaks a test, as it would make bisect harder to use.

Thanks, Antoine

On Wed, Mar 19, 2014 at 1:33 PM, Max Horn <max@quendi.de> wrote:
Show 33 quoted lines
> Fix the previous commit to workaround issues with edge cases: Specifically,
> remote-hg inserts a fake 'master' branch, unless the cloned hg repository
> already contains a 'master' bookmark. If that 'master' bookmark happens
> to reference the 'null' commit, the preceding fix ignores it. This
> would leave us in an inconsistent state. Avoid this by NOT ignoring
> null bookmarks named 'master' or 'default' under suitable circumstances.
>
> Signed-off-by: Max Horn <max@quendi.de>
> ---
>  contrib/remote-helpers/git-remote-hg | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg
> index 12d850e..49b2c2e 100755
> --- a/contrib/remote-helpers/git-remote-hg
> +++ b/contrib/remote-helpers/git-remote-hg
> @@ -626,8 +626,11 @@ def do_list(parser):
>      repo = parser.repo
>      for bmark, node in bookmarks.listbookmarks(repo).iteritems():
>          if node == '0000000000000000000000000000000000000000':
> -            warn("Ignoring invalid bookmark '%s'", bmark)
> -            continue
> +            if fake_bmark == 'default' and bmark == 'master':
> +                pass
> +            else:
> +                warn("Ignoring invalid bookmark '%s'", bmark)
> +                continue
>          bmarks[bmark] = repo[node]
>
>      cur = repo.dirstate.branch()
> --
> 1.9.0.7.ga299b13
>
Max Horn· Mar 19, 2014, 15:00 UTC · re: Antoine Pelisse · lore

Re: [PATCH 2/3] remote-hg: allow invalid bookmarks in a few edge cases

Hi Antoine,
On 19.03.2014, at 14:07, Antoine Pelisse <apelisse@gmail.com> wrote:
Show 8 quoted lines
> Hi Max,
> 
> Thank you for working on this.
> I believe it would be fair that you forget about patch 1/3 as you fix
> it in this patch (2/3).
> Also, I think it would be best NOT to integrate a patch (mine) that
> breaks a test, as it
> would make bisect harder to use.
OK, makes sense. I didn't want to step on anybodies feet by hijacking previously made work (however small or big it might be -- I've been burned by this before). Anyway, so I'll squash the first two commits together (or all three even?), and edit the message. But I'd like to properly attribute that you discovered the issue, so perhaps I can add something like "Reported-by: Antoine Pelisse" or so?
Max
Show 39 quoted lines
> 
> Thanks,
> Antoine
> 
> On Wed, Mar 19, 2014 at 1:33 PM, Max Horn <max@quendi.de> wrote:
>> Fix the previous commit to workaround issues with edge cases: Specifically,
>> remote-hg inserts a fake 'master' branch, unless the cloned hg repository
>> already contains a 'master' bookmark. If that 'master' bookmark happens
>> to reference the 'null' commit, the preceding fix ignores it. This
>> would leave us in an inconsistent state. Avoid this by NOT ignoring
>> null bookmarks named 'master' or 'default' under suitable circumstances.
>> 
>> Signed-off-by: Max Horn <max@quendi.de>
>> ---
>> contrib/remote-helpers/git-remote-hg | 7 +++++--
>> 1 file changed, 5 insertions(+), 2 deletions(-)
>> 
>> diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg
>> index 12d850e..49b2c2e 100755
>> --- a/contrib/remote-helpers/git-remote-hg
>> +++ b/contrib/remote-helpers/git-remote-hg
>> @@ -626,8 +626,11 @@ def do_list(parser):
>>     repo = parser.repo
>>     for bmark, node in bookmarks.listbookmarks(repo).iteritems():
>>         if node == '0000000000000000000000000000000000000000':
>> -            warn("Ignoring invalid bookmark '%s'", bmark)
>> -            continue
>> +            if fake_bmark == 'default' and bmark == 'master':
>> +                pass
>> +            else:
>> +                warn("Ignoring invalid bookmark '%s'", bmark)
>> +                continue
>>         bmarks[bmark] = repo[node]
>> 
>>     cur = repo.dirstate.branch()
>> --
>> 1.9.0.7.ga299b13
>> 
> 
Antoine Pelisse· Mar 19, 2014, 15:18 UTC · re: Max Horn · lore

Re: [PATCH 2/3] remote-hg: allow invalid bookmarks in a few edge cases

On Wed, Mar 19, 2014 at 4:00 PM, Max Horn <max@quendi.de> wrote:
Show 8 quoted lines
>> Thank you for working on this.
>> I believe it would be fair that you forget about patch 1/3 as you fix
>> it in this patch (2/3).
>> Also, I think it would be best NOT to integrate a patch (mine) that
>> breaks a test, as it
>> would make bisect harder to use.
>
> OK, makes sense. I didn't want to step on anybodies feet by hijacking previously made work (however small or big it might be -- I've been burned by this before). Anyway, so I'll squash the first two commits together (or all three even?), and edit the message. But I'd like to properly attribute that you discovered the issue, so perhaps I can add something like "Reported-by: Antoine Pelisse" or so?

Yes, I think you can squash all three commits into one, and use the reported-by line that you mentioned.

Thanks, Antoine

Max Horn· Mar 19, 2014, 12:33 UTC · re: Max Horn · lore
Signed-off-by: Max Horn <max@quendi.de>
---
 contrib/remote-helpers/test-hg.sh | 48 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
Show changes to contrib/remote-helpers/test-hg.sh +48 −0
diff --git a/contrib/remote-helpers/test-hg.sh b/contrib/remote-helpers/test-hg.sh
index a933b1e..8d01b32 100755
--- a/contrib/remote-helpers/test-hg.sh
+++ b/contrib/remote-helpers/test-hg.sh
@@ -772,4 +772,52 @@ test_expect_success 'remote double failed push' '
 	)
 '
 
+test_expect_success 'clone remote with master null 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
+'
+
+test_expect_success 'clone remote with default null 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
+'
+
+test_expect_success 'clone remote with generic null 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
+'
+
 test_done
-- 
1.9.0.7.ga299b13

← back to recent threads