##// END OF EJS Templates
push: introduce a pushoperation object...
Pierre-Yves David -
r20346:42df1fe3 default
parent child Browse files
Show More
@@ -11,6 +11,20 b' import errno'
11 import util, scmutil, changegroup
11 import util, scmutil, changegroup
12 import discovery, phases, obsolete, bookmarks
12 import discovery, phases, obsolete, bookmarks
13
13
14
15 class pushoperation(object):
16 """A object that represent a single push operation
17
18 It purpose is to carry push related state and very common operation.
19
20 A new should be created at the begining of each push and discarded
21 afterward.
22 """
23
24 def __init__(self, repo):
25 # repo we push from
26 self.repo = repo
27
14 def push(repo, remote, force=False, revs=None, newbranch=False):
28 def push(repo, remote, force=False, revs=None, newbranch=False):
15 '''Push outgoing changesets (limited by revs) from a local
29 '''Push outgoing changesets (limited by revs) from a local
16 repository to remote. Return an integer:
30 repository to remote. Return an integer:
@@ -20,8 +34,9 b' def push(repo, remote, force=False, revs'
20 we have outgoing changesets but refused to push
34 we have outgoing changesets but refused to push
21 - other values as described by addchangegroup()
35 - other values as described by addchangegroup()
22 '''
36 '''
37 pushop = pushoperation(repo)
23 if remote.local():
38 if remote.local():
24 missing = set(repo.requirements) - remote.local().supported
39 missing = set(pushop.repo.requirements) - remote.local().supported
25 if missing:
40 if missing:
26 msg = _("required features are not"
41 msg = _("required features are not"
27 " supported in the destination:"
42 " supported in the destination:"
@@ -38,24 +53,24 b' def push(repo, remote, force=False, revs'
38
53
39 if not remote.canpush():
54 if not remote.canpush():
40 raise util.Abort(_("destination does not support push"))
55 raise util.Abort(_("destination does not support push"))
41 unfi = repo.unfiltered()
56 unfi = pushop.repo.unfiltered()
42 def localphasemove(nodes, phase=phases.public):
57 def localphasemove(nodes, phase=phases.public):
43 """move <nodes> to <phase> in the local source repo"""
58 """move <nodes> to <phase> in the local source repo"""
44 if locallock is not None:
59 if locallock is not None:
45 phases.advanceboundary(repo, phase, nodes)
60 phases.advanceboundary(pushop.repo, phase, nodes)
46 else:
61 else:
47 # repo is not locked, do not change any phases!
62 # repo is not locked, do not change any phases!
48 # Informs the user that phases should have been moved when
63 # Informs the user that phases should have been moved when
49 # applicable.
64 # applicable.
50 actualmoves = [n for n in nodes if phase < repo[n].phase()]
65 actualmoves = [n for n in nodes if phase < pushop.repo[n].phase()]
51 phasestr = phases.phasenames[phase]
66 phasestr = phases.phasenames[phase]
52 if actualmoves:
67 if actualmoves:
53 repo.ui.status(_('cannot lock source repo, skipping local'
68 pushop.repo.ui.status(_('cannot lock source repo, skipping '
54 ' %s phase update\n') % phasestr)
69 'local %s phase update\n') % phasestr)
55 # get local lock as we might write phase data
70 # get local lock as we might write phase data
56 locallock = None
71 locallock = None
57 try:
72 try:
58 locallock = repo.lock()
73 locallock = pushop.repo.lock()
59 except IOError, err:
74 except IOError, err:
60 if err.errno != errno.EACCES:
75 if err.errno != errno.EACCES:
61 raise
76 raise
@@ -63,9 +78,9 b' def push(repo, remote, force=False, revs'
63 # We do not abort the push, but just disable the local phase
78 # We do not abort the push, but just disable the local phase
64 # synchronisation.
79 # synchronisation.
65 msg = 'cannot lock source repository: %s\n' % err
80 msg = 'cannot lock source repository: %s\n' % err
66 repo.ui.debug(msg)
81 pushop.repo.ui.debug(msg)
67 try:
82 try:
68 repo.checkpush(force, revs)
83 pushop.repo.checkpush(force, revs)
69 lock = None
84 lock = None
70 unbundle = remote.capable('unbundle')
85 unbundle = remote.capable('unbundle')
71 if not unbundle:
86 if not unbundle:
@@ -109,7 +124,7 b' def push(repo, remote, force=False, revs'
109 raise util.Abort(_(mst)
124 raise util.Abort(_(mst)
110 % (ctx.troubles()[0],
125 % (ctx.troubles()[0],
111 ctx))
126 ctx))
112 newbm = repo.ui.configlist('bookmarks', 'pushing')
127 newbm = pushop.repo.ui.configlist('bookmarks', 'pushing')
113 discovery.checkheads(unfi, remote, outgoing,
128 discovery.checkheads(unfi, remote, outgoing,
114 remoteheads, newbranch,
129 remoteheads, newbranch,
115 bool(inc), newbm)
130 bool(inc), newbm)
@@ -118,16 +133,17 b' def push(repo, remote, force=False, revs'
118 bundlecaps = None
133 bundlecaps = None
119 # create a changegroup from local
134 # create a changegroup from local
120 if revs is None and not (outgoing.excluded
135 if revs is None and not (outgoing.excluded
121 or repo.changelog.filteredrevs):
136 or pushop.repo.changelog.filteredrevs):
122 # push everything,
137 # push everything,
123 # use the fast path, no race possible on push
138 # use the fast path, no race possible on push
124 bundler = changegroup.bundle10(repo, bundlecaps)
139 bundler = changegroup.bundle10(pushop.repo, bundlecaps)
125 cg = repo._changegroupsubset(outgoing,
140 cg = pushop.repo._changegroupsubset(outgoing,
126 bundler,
141 bundler,
127 'push',
142 'push',
128 fastpath=True)
143 fastpath=True)
129 else:
144 else:
130 cg = repo.getlocalbundle('push', outgoing, bundlecaps)
145 cg = pushop.repo.getlocalbundle('push', outgoing,
146 bundlecaps)
131
147
132 # apply changegroup to remote
148 # apply changegroup to remote
133 if unbundle:
149 if unbundle:
@@ -143,7 +159,7 b' def push(repo, remote, force=False, revs'
143 else:
159 else:
144 # we return an integer indicating remote head count
160 # we return an integer indicating remote head count
145 # change
161 # change
146 ret = remote.addchangegroup(cg, 'push', repo.url())
162 ret = remote.addchangegroup(cg, 'push', pushop.repo.url())
147
163
148 if ret:
164 if ret:
149 # push succeed, synchronize target of the push
165 # push succeed, synchronize target of the push
@@ -167,7 +183,7 b' def push(repo, remote, force=False, revs'
167 # We can pick:
183 # We can pick:
168 # * missingheads part of common (::commonheads)
184 # * missingheads part of common (::commonheads)
169 common = set(outgoing.common)
185 common = set(outgoing.common)
170 nm = repo.changelog.nodemap
186 nm = pushop.repo.changelog.nodemap
171 cheads = [node for node in revs if nm[node] in common]
187 cheads = [node for node in revs if nm[node] in common]
172 # and
188 # and
173 # * commonheads parents on missing
189 # * commonheads parents on missing
@@ -177,7 +193,7 b' def push(repo, remote, force=False, revs'
177 cheads.extend(c.node() for c in revset)
193 cheads.extend(c.node() for c in revset)
178 # even when we don't push, exchanging phase data is useful
194 # even when we don't push, exchanging phase data is useful
179 remotephases = remote.listkeys('phases')
195 remotephases = remote.listkeys('phases')
180 if (repo.ui.configbool('ui', '_usedassubrepo', False)
196 if (pushop.repo.ui.configbool('ui', '_usedassubrepo', False)
181 and remotephases # server supports phases
197 and remotephases # server supports phases
182 and ret is None # nothing was pushed
198 and ret is None # nothing was pushed
183 and remotephases.get('publishing', False)):
199 and remotephases.get('publishing', False)):
@@ -195,7 +211,8 b' def push(repo, remote, force=False, revs'
195 localphasemove(cheads)
211 localphasemove(cheads)
196 # don't push any phase data as there is nothing to push
212 # don't push any phase data as there is nothing to push
197 else:
213 else:
198 ana = phases.analyzeremotephases(repo, cheads, remotephases)
214 ana = phases.analyzeremotephases(pushop.repo, cheads,
215 remotephases)
199 pheads, droots = ana
216 pheads, droots = ana
200 ### Apply remote phase on local
217 ### Apply remote phase on local
201 if remotephases.get('publishing', False):
218 if remotephases.get('publishing', False):
@@ -216,10 +233,10 b' def push(repo, remote, force=False, revs'
216 str(phases.draft),
233 str(phases.draft),
217 str(phases.public))
234 str(phases.public))
218 if not r:
235 if not r:
219 repo.ui.warn(_('updating %s to public failed!\n')
236 pushop.repo.ui.warn(_('updating %s to public failed!\n')
220 % newremotehead)
237 % newremotehead)
221 repo.ui.debug('try to push obsolete markers to remote\n')
238 pushop.repo.ui.debug('try to push obsolete markers to remote\n')
222 obsolete.syncpush(repo, remote)
239 obsolete.syncpush(pushop.repo, remote)
223 finally:
240 finally:
224 if lock is not None:
241 if lock is not None:
225 lock.release()
242 lock.release()
@@ -227,5 +244,5 b' def push(repo, remote, force=False, revs'
227 if locallock is not None:
244 if locallock is not None:
228 locallock.release()
245 locallock.release()
229
246
230 bookmarks.updateremote(repo.ui, unfi, remote, revs)
247 bookmarks.updateremote(pushop.repo.ui, unfi, remote, revs)
231 return ret
248 return ret
General Comments 0
You need to be logged in to leave comments. Login now