sapling/edenscm/hgext/sendunbundlereplay.py
Stanislau Hlebik ddd0f0ed99 mononoke: mononoke -> hg sync job
Summary:
First stab at a job that will keep hg in sync with Mononoke when Mononoke
becomes a source of truth.

Reviewed By: ikostia

Differential Revision: D14018269

fbshipit-source-id: f88c5eba8bf5482f2f162b7807ca8e41a3b4291d
2019-02-21 05:46:40 -08:00

58 lines
1.9 KiB
Python

# sendunbundlereplay.py - send unbundlereplay wireproto command
#
# Copyright 2019-present Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
from edenscm.mercurial import hg, replay, util
from edenscm.mercurial.commands import command
from edenscm.mercurial.i18n import _
@command(
"^sendunbundlereplay",
[
("", "file", "", _("file to read bundle from"), ""),
("", "path", "", _("hg server remotepath (ssh)"), ""),
("r", "rebasedhead", "", _("expected rebased head hash"), ""),
("b", "ontobook", "", _("expected onto bookmark for pushrebase"), ""),
],
_("[OPTION]..."),
norepo=True,
)
def sendunbundlereplay(ui, **opts):
"""Send unbundlereplay wireproto command to a given server
Takes `rebasedhook` and `ontobook` arguments on the commmand
line, and commit dates in stdin. The commit date format is:
<commithash>=<hg-parseable-date>
``sendunbundlereplay.respondlightly`` config option instructs the server
to avoid sending large bundle2 parts back.
"""
fname = opts["file"]
path = opts["path"]
rebasedhead = opts["rebasedhead"]
ontobook = opts["ontobook"]
commitdates = dict(map(lambda s: s.split("="), ui.fin))
with open(fname, "rb") as f:
stream = util.chunkbuffer([f.read()])
remote = hg.peer(ui, {}, path)
reply = remote.unbundlereplay(
stream,
["force"],
remote.url(),
replay.ReplayData(commitdates, rebasedhead, ontobook),
ui.configbool("sendunbundlereplay", "respondlightly", True),
)
for part in reply.iterparts():
part.read()
if part.type == "error:pushkey":
# Updating a bookmark failed, return non-zero error code
# stderr should contain the reason for the error
return 1