comparison mercurial/exchange.py @ 20350:8c85d968ee65

push: move `revs` 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 17:04:23 -0800
parents 89f90457979e
children c05ad450df23
comparison
equal deleted inserted replaced
20349:89f90457979e 20350:8c85d968ee65
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, force=False): 24 def __init__(self, repo, remote, force=False, revs=None):
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 30 # force option provided
31 self.force = force 31 self.force = force
32 # revs to be pushed (None is "all")
33 self.revs = revs
32 34
33 def push(repo, remote, force=False, revs=None, newbranch=False): 35 def push(repo, remote, force=False, revs=None, newbranch=False):
34 '''Push outgoing changesets (limited by revs) from a local 36 '''Push outgoing changesets (limited by revs) from a local
35 repository to remote. Return an integer: 37 repository to remote. Return an integer:
36 - None means nothing to push 38 - None means nothing to push
37 - 0 means HTTP error 39 - 0 means HTTP error
38 - 1 means we pushed and remote head count is unchanged *or* 40 - 1 means we pushed and remote head count is unchanged *or*
39 we have outgoing changesets but refused to push 41 we have outgoing changesets but refused to push
40 - other values as described by addchangegroup() 42 - other values as described by addchangegroup()
41 ''' 43 '''
42 pushop = pushoperation(repo, remote, force) 44 pushop = pushoperation(repo, remote, force, revs)
43 if pushop.remote.local(): 45 if pushop.remote.local():
44 missing = (set(pushop.repo.requirements) 46 missing = (set(pushop.repo.requirements)
45 - pushop.remote.local().supported) 47 - pushop.remote.local().supported)
46 if missing: 48 if missing:
47 msg = _("required features are not" 49 msg = _("required features are not"
84 # We do not abort the push, but just disable the local phase 86 # We do not abort the push, but just disable the local phase
85 # synchronisation. 87 # synchronisation.
86 msg = 'cannot lock source repository: %s\n' % err 88 msg = 'cannot lock source repository: %s\n' % err
87 pushop.ui.debug(msg) 89 pushop.ui.debug(msg)
88 try: 90 try:
89 pushop.repo.checkpush(pushop.force, revs) 91 pushop.repo.checkpush(pushop.force, pushop.revs)
90 lock = None 92 lock = None
91 unbundle = pushop.remote.capable('unbundle') 93 unbundle = pushop.remote.capable('unbundle')
92 if not unbundle: 94 if not unbundle:
93 lock = pushop.remote.lock() 95 lock = pushop.remote.lock()
94 try: 96 try:
95 # discovery 97 # discovery
96 fci = discovery.findcommonincoming 98 fci = discovery.findcommonincoming
97 commoninc = fci(unfi, pushop.remote, force=pushop.force) 99 commoninc = fci(unfi, pushop.remote, force=pushop.force)
98 common, inc, remoteheads = commoninc 100 common, inc, remoteheads = commoninc
99 fco = discovery.findcommonoutgoing 101 fco = discovery.findcommonoutgoing
100 outgoing = fco(unfi, pushop.remote, onlyheads=revs, 102 outgoing = fco(unfi, pushop.remote, onlyheads=pushop.revs,
101 commoninc=commoninc, force=pushop.force) 103 commoninc=commoninc, force=pushop.force)
102 104
103 105
104 if not outgoing.missing: 106 if not outgoing.missing:
105 # nothing to push 107 # nothing to push
136 bool(inc), newbm) 138 bool(inc), newbm)
137 139
138 # TODO: get bundlecaps from remote 140 # TODO: get bundlecaps from remote
139 bundlecaps = None 141 bundlecaps = None
140 # create a changegroup from local 142 # create a changegroup from local
141 if revs is None and not (outgoing.excluded 143 if pushop.revs is None and not (outgoing.excluded
142 or pushop.repo.changelog.filteredrevs): 144 or pushop.repo.changelog.filteredrevs):
143 # push everything, 145 # push everything,
144 # use the fast path, no race possible on push 146 # use the fast path, no race possible on push
145 bundler = changegroup.bundle10(pushop.repo, bundlecaps) 147 bundler = changegroup.bundle10(pushop.repo, bundlecaps)
146 cg = pushop.repo._changegroupsubset(outgoing, 148 cg = pushop.repo._changegroupsubset(outgoing,
169 pushop.repo.url()) 171 pushop.repo.url())
170 172
171 if ret: 173 if ret:
172 # push succeed, synchronize target of the push 174 # push succeed, synchronize target of the push
173 cheads = outgoing.missingheads 175 cheads = outgoing.missingheads
174 elif revs is None: 176 elif pushop.revs is None:
175 # All out push fails. synchronize all common 177 # All out push fails. synchronize all common
176 cheads = outgoing.commonheads 178 cheads = outgoing.commonheads
177 else: 179 else:
178 # I want cheads = heads(::missingheads and ::commonheads) 180 # I want cheads = heads(::missingheads and ::commonheads)
179 # (missingheads is revs with secret changeset filtered out) 181 # (missingheads is revs with secret changeset filtered out)
189 # 191 #
190 # We can pick: 192 # We can pick:
191 # * missingheads part of common (::commonheads) 193 # * missingheads part of common (::commonheads)
192 common = set(outgoing.common) 194 common = set(outgoing.common)
193 nm = pushop.repo.changelog.nodemap 195 nm = pushop.repo.changelog.nodemap
194 cheads = [node for node in revs if nm[node] in common] 196 cheads = [node for node in pushop.revs if nm[node] in common]
195 # and 197 # and
196 # * commonheads parents on missing 198 # * commonheads parents on missing
197 revset = unfi.set('%ln and parents(roots(%ln))', 199 revset = unfi.set('%ln and parents(roots(%ln))',
198 outgoing.commonheads, 200 outgoing.commonheads,
199 outgoing.missing) 201 outgoing.missing)
249 lock.release() 251 lock.release()
250 finally: 252 finally:
251 if locallock is not None: 253 if locallock is not None:
252 locallock.release() 254 locallock.release()
253 255
254 bookmarks.updateremote(pushop.ui, unfi, pushop.remote, revs) 256 bookmarks.updateremote(pushop.ui, unfi, pushop.remote, pushop.revs)
255 return ret 257 return ret