remote-hg: do not fail on invalid bookmarks
PATCH 1/3 remote-hg: do not fail on invalid bookmarks
From: Antoine Pelisse <[email protected]>
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.
--- contrib/remote-helpers/git-remote-hg | 3 +++ 1 file changed, 3 insertions(+)
contrib/remote-helpers/git-remote-hg +3 -0
@@ -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()
Signature · 1 line
1.9.0.7.ga299b13
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.
--- contrib/remote-helpers/git-remote-hg | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
contrib/remote-helpers/git-remote-hg +5 -2
@@ -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()
Signature · 1 line
1.9.0.7.ga299b13
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
Quoted 33 lines · Max Horn
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 <[email protected]>--- contrib/remote-helpers/git-remote-hg | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)contrib/remote-helpers/git-remote-hg +5
-3@@ -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
Re: [PATCH 2/3] remote-hg: allow invalid bookmarks in a few edge cases
Hi Antoine,
Quoted 8 lines · Antoine Pelisse
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
Quoted 39 lines
Thanks,
AntoineQuoted 33 lines · Max Horn
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 <[email protected]>---
contrib/remote-helpers/git-remote-hg | 7 +++++--1 file changed, 5 insertions(+), 2 deletions(-)contrib/remote-helpers/git-remote-hg +5
-3@@ -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
Re: [PATCH 2/3] remote-hg: allow invalid bookmarks in a few edge cases
Quoted 8 lines · Max Horn
Quoted 6 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
PATCH 3/3 remote-hg: add test cases for null bookmarks
In reply to Max Horn--- contrib/remote-helpers/test-hg.sh | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
contrib/remote-helpers/test-hg.sh +48 -0
@@ -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
Signature · 1 line
1.9.0.7.ga299b13