Skip to contentSkip to conversation

remote-hg: do not fail on invalid bookmarks

PATCH In review Antoine Pelisse 4 participants 7 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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

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
index eb89ef6..12d850e 100755
@@ -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.8.5.1.97.g8d784da.dirty
#1 lore raw
Quoted 8 lines · Antoine Pelisse

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.

It's not invalid, it's used to indicate deleted bookmarks. (Tags have the same property)

Mike

#2 lore raw
Quoted 7 lines · Mike Hommey
Quoted 6 lines · Antoine Pelisse

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.

Quoted 5 lines
Quoted 2 lines

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

It's not invalid, it's used to indicate deleted bookmarks. (Tags have the same property)

Hey Mike,
Indeed, I don't know how I ended-up with such a bookmark, but it prevented me from git-cloning the repository (and the backtrace was not very helpful at first).
But I'm still not sure what you mean by "deleted bookmarks" ? I guess it's not "hg bookmark --delete", as it would not be listed at all. Is it "hg strip some_changeset" that end-up deleting the bookmarked changeset ? I think I've tested this use-case and it moved the bookmark to a parent changeset.

Antoine,

#3 lore raw
Quoted 14 lines · Antoine Pelisse
Quoted 7 lines · Mike Hommey
Quoted 6 lines · Antoine Pelisse

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.

Quoted 5 lines
Quoted 2 lines

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

It's not invalid, it's used to indicate deleted bookmarks. (Tags have the same property)

Quoted 9 lines

Hey Mike,
Indeed, I don't know how I ended-up with such a bookmark, but it prevented me from git-cloning the repository (and the backtrace was not very helpful at first).
But I'm still not sure what you mean by "deleted bookmarks" ? I guess it's not "hg bookmark --delete", as it would not be listed at all. Is it "hg strip some_changeset" that end-up deleting the bookmarked changeset ? I think I've tested this use-case and it moved the bookmark to a parent changeset.

Mmmm after looking at the mercurial code, it looks like i was wrong and bookmarks are not handled like tags. You can actually create such a bookmark on purpose with:

$ hg bookmark -r null foo

Then, if you do, say:

$ hg up -r foo
$ echo a > a
$ hg add a
$ hg commit -m a

Then you end up with a completely new head with no ancestors in common with the others.

In git terms,

$ hg bookmark -r null foo
$ hg up -r foo

is equivalent to

$ git checkout --orphan foo

But git never creates an actual ref in that case.

Mike

#4 lore raw
In reply to Mike Hommey
Quoted 7 lines · Mike Hommey
Quoted 6 lines · Antoine Pelisse

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.

Quoted 5 lines
Quoted 2 lines

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

It's not invalid, it's used to indicate deleted bookmarks. (Tags have the same property)

So what should remote-hg behave in such a case, other than what Antoine's change does (which is to, IIRC, warn, ignore and continue).

#5 lore raw
In reply to Antoine Pelisse
Quoted 20 lines · Antoine Pelisse

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 +0 -0
index eb89ef6..12d850e 100755

contrib/remote-helpers/git-remote-hg def list_head(repo, cur): · line 633

Quoted 9 lines
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()

(Side note: ap/remote-hg-skip-null-bookmarks)

When I run the test-suite like this:
~/projects/git/git.pu/contrib/remote-helpers$ debug=t verbose=t make test-hg-hg-git.sh

All 11 test cases fail on my systems (Debian Wheezy and Mac OS X):
[snip]
WARNING: Ignoring invalid bookmark 'master'
To hg::../hgrepo-git
! [remote rejected] master -> master
error: failed to push some refs to 'hg::../hgrepo-git' not ok 1 - executable bit
#
[snip]

#6 lore raw

Thanks for noticing,
I can reproduce at work, I will try to come-up with an improved version soon,

Cheers,
Antoine

Quoted 46 lines · Torsten Bögershausen
Quoted 20 lines · Antoine Pelisse

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 +0 -0
index eb89ef6..12d850e 100755

contrib/remote-helpers/git-remote-hg def list_head(repo, cur): · line 633

Quoted 9 lines
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()

(Side note: ap/remote-hg-skip-null-bookmarks)

When I run the test-suite like this:
~/projects/git/git.pu/contrib/remote-helpers$ debug=t verbose=t make test-hg-hg-git.sh

All 11 test cases fail on my systems (Debian Wheezy and Mac OS X):
[snip]
WARNING: Ignoring invalid bookmark 'master'
To hg::../hgrepo-git
! [remote rejected] master -> master
error: failed to push some refs to 'hg::../hgrepo-git' not ok 1 - executable bit
#
[snip]