comparison mercurial/exchange.py @ 20349:89f90457979e

push: move `force` argument into the push object One more step toward a more modular push function.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Thu, 30 Jan 2014 16:59:25 -0800
parents d64c904db55a
children 8c85d968ee65
comparison
equal deleted inserted replaced
20348:d64c904db55a 20349:89f90457979e
19 19
20 A new should be created at the begining of each push and discarded 20 A new should be created at the begining of each push and discarded
21 afterward. 21 afterward.
22 """ 22 """
23 23
24 def __init__(self, repo, remote): 24 def __init__(self, repo, remote, force=False):
25 # repo we push from 25 # repo we push from
26 self.repo = repo 26 self.repo = repo
27 self.ui = repo.ui 27 self.ui = repo.ui
28 # repo we push to 28 # repo we push to
29 self.remote = remote 29 self.remote = remote
30 # force option provided
31 self.force = force
30 32
31 def push(repo, remote, force=False, revs=None, newbranch=False): 33 def push(repo, remote, force=False, revs=None, newbranch=False):
32 '''Push outgoing changesets (limited by revs) from a local 34 '''Push outgoing changesets (limited by revs) from a local
33 repository to remote. Return an integer: 35 repository to remote. Return an integer:
34 - None means nothing to push 36 - None means nothing to push
35 - 0 means HTTP error 37 - 0 means HTTP error
36 - 1 means we pushed and remote head count is unchanged *or* 38 - 1 means we pushed and remote head count is unchanged *or*
37 we have outgoing changesets but refused to push 39 we have outgoing changesets but refused to push
38 - other values as described by addchangegroup() 40 - other values as described by addchangegroup()
39 ''' 41 '''
40 pushop = pushoperation(repo, remote) 42 pushop = pushoperation(repo, remote, force)
41 if pushop.remote.local(): 43 if pushop.remote.local():
42 missing = (set(pushop.repo.requirements) 44 missing = (set(pushop.repo.requirements)
43 - pushop.remote.local().supported) 45 - pushop.remote.local().supported)
44 if missing: 46 if missing:
45 msg = _("required features are not" 47 msg = _("required features are not"
82 # We do not abort the push, but just disable the local phase 84 # We do not abort the push, but just disable the local phase
83 # synchronisation. 85 # synchronisation.
84 msg = 'cannot lock source repository: %s\n' % err 86 msg = 'cannot lock source repository: %s\n' % err
85 pushop.ui.debug(msg) 87 pushop.ui.debug(msg)
86 try: 88 try:
87 pushop.repo.checkpush(force, revs) 89 pushop.repo.checkpush(pushop.force, revs)
88 lock = None 90 lock = None
89 unbundle = pushop.remote.capable('unbundle') 91 unbundle = pushop.remote.capable('unbundle')
90 if not unbundle: 92 if not unbundle:
91 lock = pushop.remote.lock() 93 lock = pushop.remote.lock()
92 try: 94 try:
93 # discovery 95 # discovery
94 fci = discovery.findcommonincoming 96 fci = discovery.findcommonincoming
95 commoninc = fci(unfi, pushop.remote, force=force) 97 commoninc = fci(unfi, pushop.remote, force=pushop.force)
96 common, inc, remoteheads = commoninc 98 common, inc, remoteheads = commoninc
97 fco = discovery.findcommonoutgoing 99 fco = discovery.findcommonoutgoing
98 outgoing = fco(unfi, pushop.remote, onlyheads=revs, 100 outgoing = fco(unfi, pushop.remote, onlyheads=revs,
99 commoninc=commoninc, force=force) 101 commoninc=commoninc, force=pushop.force)
100 102
101 103
102 if not outgoing.missing: 104 if not outgoing.missing:
103 # nothing to push 105 # nothing to push
104 scmutil.nochangesfound(unfi.ui, unfi, outgoing.excluded) 106 scmutil.nochangesfound(unfi.ui, unfi, outgoing.excluded)
105 ret = None 107 ret = None
106 else: 108 else:
107 # something to push 109 # something to push
108 if not force: 110 if not pushop.force:
109 # if repo.obsstore == False --> no obsolete 111 # if repo.obsstore == False --> no obsolete
110 # then, save the iteration 112 # then, save the iteration
111 if unfi.obsstore: 113 if unfi.obsstore:
112 # this message are here for 80 char limit reason 114 # this message are here for 80 char limit reason
113 mso = _("push includes obsolete changeset: %s!") 115 mso = _("push includes obsolete changeset: %s!")
153 if unbundle: 155 if unbundle:
154 # local repo finds heads on server, finds out what 156 # local repo finds heads on server, finds out what
155 # revs it must push. once revs transferred, if server 157 # revs it must push. once revs transferred, if server
156 # finds it has different heads (someone else won 158 # finds it has different heads (someone else won
157 # commit/push race), server aborts. 159 # commit/push race), server aborts.
158 if force: 160 if pushop.force:
159 remoteheads = ['force'] 161 remoteheads = ['force']
160 # ssh: return remote's addchangegroup() 162 # ssh: return remote's addchangegroup()
161 # http: return remote's addchangegroup() or 0 for error 163 # http: return remote's addchangegroup() or 0 for error
162 ret = pushop.remote.unbundle(cg, remoteheads, 'push') 164 ret = pushop.remote.unbundle(cg, remoteheads, 'push')
163 else: 165 else: