From 73c5cb89de4e2ac155a565d712b99292e30e376b Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Tue, 21 Apr 2020 09:16:34 -0700 Subject: [PATCH] bookmarks: reload changelog if unknown node is seen Summary: This mitigates loading order issues demonstrated by the previous diff. Reviewed By: DurhamG Differential Revision: D21148446 fbshipit-source-id: 40e4861055822b4676f3ac38d0f004b365efe86d --- eden/scm/edenscm/mercurial/bookmarks.py | 32 +++++++++++++++++-- eden/scm/tests/test-bookmarks-loading-order.t | 6 ++-- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/eden/scm/edenscm/mercurial/bookmarks.py b/eden/scm/edenscm/mercurial/bookmarks.py index 410a393fb6..f3a8377daf 100644 --- a/eden/scm/edenscm/mercurial/bookmarks.py +++ b/eden/scm/edenscm/mercurial/bookmarks.py @@ -96,9 +96,6 @@ class bmstore(dict): try: sha, refspec = line.split(" ", 1) node = tonode(sha) - if node in nm: - refspec = encoding.tolocal(refspec) - setitem(self, refspec, node) except (TypeError, ValueError): # TypeError: # - bin(...) @@ -106,6 +103,35 @@ class bmstore(dict): # - node in nm, for non-20-bytes entry # - split(...), for string without ' ' repo.ui.warn(_("malformed line in .hg/bookmarks: %r\n") % line) + else: + if node in nm: + refspec = encoding.tolocal(refspec) + setitem(self, refspec, node) + else: + # This might happen if: + # - changelog was loaded, bookmarks are not loaded + # - bookmarks was changed to point to unknown nodes + # - bookmarks are loaded + # + # Try to mitigate by reloading changelog. + repo.invalidate(clearfilecache=True) + nm = repo.changelog.nodemap + if node in nm: + refspec = encoding.tolocal(refspec) + setitem(self, refspec, node) + repo.ui.log( + "features", feature="fix-bookmark-changelog-order" + ) + else: + repo.ui.log( + "features", + feature="fix-bookmark-changelog-order-failed", + ) + repo.ui.warn( + _("unknown reference in .hg/bookmarks: %s %s\n") + % (refspec, sha) + ) + except IOError as inst: if inst.errno != errno.ENOENT: raise diff --git a/eden/scm/tests/test-bookmarks-loading-order.t b/eden/scm/tests/test-bookmarks-loading-order.t index 1663bfe5bc..830bbae8dd 100644 --- a/eden/scm/tests/test-bookmarks-loading-order.t +++ b/eden/scm/tests/test-bookmarks-loading-order.t @@ -20,10 +20,8 @@ With metalog it works fine: $ hg log -r A -T '{desc}\n' --config hooks.pre-bookmark-load='hg commit -m A3' A2 -Without metalog it causes errors: +Without metalog: $ setconfig experimental.metalog=false $ hg log -r A -T '{desc}\n' --config hooks.pre-bookmark-load='hg commit -m A4' - abort: unknown revision 'A'! - (if A is a remote bookmark or commit, try to 'hg pull' it first) - [255] + A4