@@ -12,11 +12,20 @@ import discovery, phases, obsolete, book
class pushoperation(object):
"""A object that represent a single push operation"""
- def perform(self, repo, remote, force=False, revs=None, newbranch=False):
+ def __init__(self, repo, remote, force=False, revs=None, newbranch=False):
+ if not remote.canpush():
+ raise util.Abort(_("destination does not support push"))
+ self.repo = repo
+ self.remote = remote
+ self.force = force
+ self.revs = revs
+ self.newbranch = newbranch
+
+ def perform(self):
'''Push outgoing changesets (limited by revs) from the current
repository to remote. Return an integer:
- None means nothing to push
- 0 means HTTP error
- 1 means we pushed and remote head count is unchanged *or*
@@ -29,37 +38,37 @@ class pushoperation(object):
# repo (local filesystem, old ssh servers).
#
# unbundle assumes local user cannot lock remote repo (new ssh
# servers, http servers).
- if not remote.canpush():
- raise util.Abort(_("destination does not support push"))
+ repo = self.repo
+ remote = self.remote
unfi = repo.unfiltered()
# get local lock as we might write phase data
locallock = repo.lock()
try:
- repo.checkpush(force, revs)
+ repo.checkpush(self.force, self.revs)
lock = None
unbundle = remote.capable('unbundle')
if not unbundle:
lock = remote.lock()
try:
# discovery
fci = discovery.findcommonincoming
- commoninc = fci(unfi, remote, force=force)
+ commoninc = fci(unfi, remote, force=self.force)
common, inc, remoteheads = commoninc
fco = discovery.findcommonoutgoing
- outgoing = fco(unfi, remote, onlyheads=revs,
- commoninc=commoninc, force=force)
+ outgoing = fco(unfi, remote, onlyheads=self.revs,
+ commoninc=commoninc, force=self.force)
if not outgoing.missing:
# nothing to push
scmutil.nochangesfound(unfi.ui, unfi, outgoing.excluded)
ret = None
else:
# something to push
- if not force:
+ if not self.force:
# if self.obsstore == False --> no obsolete
# then, save the iteration
if unfi.obsstore:
# this message are here for 80 char limit reason
mso = _("push includes obsolete changeset: %s!")
@@ -79,15 +88,15 @@ class pushoperation(object):
elif ctx.troubled():
raise util.Abort(_(mst)
% (ctx.troubles()[0],
ctx))
discovery.checkheads(unfi, remote, outgoing,
- remoteheads, newbranch,
+ remoteheads, self.newbranch,
bool(inc))
# create a changegroup from local
- if revs is None and not outgoing.excluded:
+ if self.revs is None and not outgoing.excluded:
# push everything,
# use the fast path, no race possible on push
cg = repo._changegroup(outgoing.missing, 'push')
else:
cg = repo.getlocalbundle('push', outgoing)
@@ -96,11 +105,11 @@ class pushoperation(object):
if unbundle:
# local repo finds heads on server, finds out what
# revs it must push. once revs transferred, if server
# finds it has different heads (someone else won
# commit/push race), server aborts.
- if force:
+ if self.force:
remoteheads = ['force']
# ssh: return remote's addchangegroup()
# http: return remote's addchangegroup() or 0 for error
ret = remote.unbundle(cg, remoteheads, 'push')
else:
@@ -109,11 +118,11 @@ class pushoperation(object):
ret = remote.addchangegroup(cg, 'push', repo.url())
if ret:
# push succeed, synchronize target of the push
cheads = outgoing.missingheads
- elif revs is None:
+ elif self.revs is None:
# All out push fails. synchronize all common
cheads = outgoing.commonheads
else:
# I want cheads = heads(::missingheads and ::commonheads)
# (missingheads is revs with secret changeset filtered out)
@@ -128,11 +137,11 @@ class pushoperation(object):
# missing = ((commonheads::missingheads) - commonheads)
#
# We can pick:
# * missingheads part of common (::commonheads)
common = set(outgoing.common)
- cheads = [node for node in revs if node in common]
+ cheads = [node for node in self.revs if node in common]
# and
# * commonheads parents on missing
revset = unfi.set('%ln and parents(roots(%ln))',
outgoing.commonheads,
outgoing.missing)
@@ -1660,12 +1660,12 @@ class localrepository(object):
command.
"""
pass
def push(self, remote, force=False, revs=None, newbranch=False):
- push = exchangeutil.pushoperation()
- return push.perform(self, remote, force, revs, newbranch)
+ push = exchangeutil.pushoperation(self, remote, force, revs, newbranch)
+ return push.perform()
def changegroupinfo(self, nodes, source):
if self.ui.verbose or source == 'bundle':
self.ui.status(_("%d changesets found\n") % len(nodes))
if self.ui.debugflag: