snapshot: Improve parent uploading to commit cloud

Summary:
Right now we continue silently if parent upload to commit cloud fails, which may cause more cryptic errors in Mononoke requests. Let's fail early with a good error message.

I also changed slightly how to find the parents, using the same logic as we use to send the parents to Mononoke, for sanity.

Reviewed By: mitrandir77

Differential Revision: D35499845

fbshipit-source-id: c97359ebd879554b7ac659db194af22689cba55c
This commit is contained in:
Yan Soares Couto 2022-04-12 03:52:14 -07:00 committed by Facebook GitHub Bot
parent 2efa1b5f7f
commit 12de61bfe5

View File

@ -6,6 +6,7 @@
from dataclasses import dataclass
from pathlib import Path
from edenscm.mercurial import error
from edenscm.mercurial.edenapi_upload import (
filetypefromfile,
uploadhgchangesets,
@ -17,14 +18,20 @@ from edenscm.mercurial.revset import parseage
from .metalog import fetchlatestbubble, storelatest
def _backupcurrentcommit(repo):
"""make sure the current commit is backed up in commitcloud"""
currentcommit = (repo["."].node(),)
def _backupparents(repo, wctx):
"""make sure this commit's ancestors are backed up in commitcloud"""
parents = (wctx.p1().node(), wctx.p2().node())
draftrevs = repo.changelog.torevset(
repo.dageval(lambda: ancestors(currentcommit) & draft())
repo.dageval(lambda: ancestors(parents) & draft())
)
uploadhgchangesets(repo, draftrevs)
(success, failed) = uploadhgchangesets(repo, draftrevs)
if failed:
raise error.Abort(
_("failed to upload ancestors to commit cloud: {}").format(
[repo[node].hex() for node in failed]
)
)
def _parselifetime(opts):
@ -105,11 +112,12 @@ def createremote(ui, repo, **opts):
if ui.plain():
overrides[("ui", "quiet")] = True
with repo.lock(), ui.configoverride(overrides):
_backupcurrentcommit(repo)
# Current working context
wctx = repo[None]
hgparents = parentsfromwctx(ui, wctx)
_backupparents(repo, wctx)
(time, tz) = wctx.date()
wc = workingcopy.fromrepo(repo, maxuntrackedsize)
@ -128,7 +136,7 @@ def createremote(ui, repo, **opts):
"author": wctx.user(),
"time": int(time),
"tz": tz,
"hg_parents": parentsfromwctx(ui, wctx),
"hg_parents": hgparents,
},
lifetime,
previousbubble,