mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 17:27:53 +03:00
31e3ca4aa3
Summary: c6cf3ac8c9bb811afa5b6eb5b69b29d128a7476a made revset API change. This diff fixes our extensions Test Plan: arc unit Reviewers: #sourcecontrol, mjpieters, ikostia Reviewed By: ikostia Subscribers: mjpieters Differential Revision: https://phabricator.intern.facebook.com/D4604848 Signature: t1:4604848:1487851636:1c7618e9050f607e2d8b47ed495a349b877ed48a
80 lines
2.6 KiB
Python
80 lines
2.6 KiB
Python
# Copyright 2017 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 .common import (
|
|
encodebookmarks,
|
|
isremotebooksenabled,
|
|
)
|
|
from mercurial import (
|
|
bundle2,
|
|
changegroup,
|
|
error,
|
|
revsetlang,
|
|
)
|
|
from mercurial.i18n import _
|
|
|
|
scratchbranchparttype = 'b2x:infinitepush'
|
|
scratchbookmarksparttype = 'b2x:infinitepushscratchbookmarks'
|
|
|
|
def getscratchbranchpart(repo, peer, outgoing, confignonforwardmove,
|
|
ui, bookmark, create):
|
|
if not outgoing.missing:
|
|
raise error.Abort(_('no commits to push'))
|
|
|
|
if scratchbranchparttype not in bundle2.bundle2caps(peer):
|
|
raise error.Abort(_('no server support for %r') % scratchbranchparttype)
|
|
|
|
_validaterevset(repo, revsetlang.formatspec('%ln', outgoing.missing),
|
|
bookmark)
|
|
|
|
cgversion = '02'
|
|
cg = changegroup.getlocalchangegroupraw(repo, 'push',
|
|
outgoing, version=cgversion)
|
|
|
|
params = {}
|
|
params['cgversion'] = cgversion
|
|
if bookmark:
|
|
params['bookmark'] = bookmark
|
|
# 'prevbooknode' is necessary for pushkey reply part
|
|
params['bookprevnode'] = ''
|
|
if bookmark in repo:
|
|
params['bookprevnode'] = repo[bookmark].hex()
|
|
if create:
|
|
params['create'] = '1'
|
|
if confignonforwardmove:
|
|
params['force'] = '1'
|
|
|
|
# Do not send pushback bundle2 part with bookmarks if remotenames extension
|
|
# is enabled. It will be handled manually in `_push()`
|
|
if not isremotebooksenabled(ui):
|
|
params['pushbackbookmarks'] = '1'
|
|
|
|
# .upper() marks this as a mandatory part: server will abort if there's no
|
|
# handler
|
|
return bundle2.bundlepart(
|
|
scratchbranchparttype.upper(),
|
|
advisoryparams=params.iteritems(),
|
|
data=cg)
|
|
|
|
def getscratchbookmarkspart(peer, bookmarks):
|
|
if scratchbookmarksparttype not in bundle2.bundle2caps(peer):
|
|
raise error.Abort(
|
|
_('no server support for %r') % scratchbookmarksparttype)
|
|
|
|
return bundle2.bundlepart(
|
|
scratchbookmarksparttype.upper(),
|
|
data=encodebookmarks(bookmarks))
|
|
|
|
def _validaterevset(repo, revset, bookmark):
|
|
"""Abort if the revs to be pushed aren't valid for a scratch branch."""
|
|
if not repo.revs(revset):
|
|
raise error.Abort(_('nothing to push'))
|
|
if bookmark:
|
|
# Allow bundle with many heads only if no bookmark is specified
|
|
heads = repo.revs('heads(%r)', revset)
|
|
if len(heads) > 1:
|
|
raise error.Abort(
|
|
_('cannot push more than one head to a scratch branch'))
|