sapling/edenscm/hgext/sendunbundlereplay.py
Kostia Balytskyi da3e429150 wireproto: add unbundlereplay command
Summary:
This is to be used from Mononoke->hg sync.
Currently expects only `pushrebase` bundles, e.g. one head and one book to
move.

Reviewed By: StanislavGlebik

Differential Revision: D14116130

fbshipit-source-id: 959a6e51f51e21da5592c84188e294a33057ffaa
2019-02-19 01:57:39 -08:00

50 lines
1.5 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>
"""
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),
)
for part in reply.iterparts():
part.read()