port D16833526 to gitrevset

Summary:
See https://fb.workplace.com/groups/corehg/permalink/448152285780007/ for context.

D16833526 was to add extras lookup for translating hg hash to git hash. However we
also have gitrevset extension which still does mapfile lookup. THis diff should port
the same improvement for it.

Reviewed By: DurhamG

Differential Revision: D17070479

fbshipit-source-id: e469707b0b21541aa2c3b90d1480b04afc4f1485
This commit is contained in:
Shu-Ting Tseng 2019-08-27 11:54:39 -07:00 committed by Facebook Github Bot
parent 66cef07cf9
commit 439e4c6825

View File

@ -110,6 +110,17 @@ def _dolookup(repo, key):
sha = key[14:]
else:
return None
if direction == "togit":
# we've started recording the hg hash in extras.
try:
ctx = repo[sha]
except error.RepoLookupError as e:
if "unknown revision" in str(e):
return None
raise e
fromextra = ctx.extra().get("convert_revision", "")
if fromextra:
return fromextra
hggitmap = open(mapfile, "rb")
for line in hggitmap:
gitsha, hgsha = line.strip().split(" ", 1)