Mercurial > public > mercurial-scm > hg
comparison mercurial/hg.py @ 28632:a2c2dd399f3b stable
hg: perform update after pulling during clone with share (issue5103)
This is a graft of 60adda1a0188 and a4692267bc2d from the default
branch. Combined, they address a bug with pooled shared storage where
an update may not update to the most recent revision when performing
a `hg clone`.
The patches should have been written against the stable branch in
the beginning. I screwed up.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 25 Mar 2016 10:47:49 -0700 |
parents | d493d64757eb |
children | 0e330d7d9f53 |
comparison
equal
deleted
inserted
replaced
28618:7dab4caf11bc | 28632:a2c2dd399f3b |
---|---|
234 destvfs.write('requires', requirements) | 234 destvfs.write('requires', requirements) |
235 destvfs.write('sharedpath', sharedpath) | 235 destvfs.write('sharedpath', sharedpath) |
236 | 236 |
237 r = repository(ui, destwvfs.base) | 237 r = repository(ui, destwvfs.base) |
238 postshare(srcrepo, r, bookmarks=bookmarks) | 238 postshare(srcrepo, r, bookmarks=bookmarks) |
239 | 239 _postshareupdate(r, update, checkout=checkout) |
240 if update: | |
241 r.ui.status(_("updating working directory\n")) | |
242 if update is not True: | |
243 checkout = update | |
244 for test in (checkout, 'default', 'tip'): | |
245 if test is None: | |
246 continue | |
247 try: | |
248 uprev = r.lookup(test) | |
249 break | |
250 except error.RepoLookupError: | |
251 continue | |
252 _update(r, uprev) | |
253 | 240 |
254 def postshare(sourcerepo, destrepo, bookmarks=True): | 241 def postshare(sourcerepo, destrepo, bookmarks=True): |
255 """Called after a new shared repo is created. | 242 """Called after a new shared repo is created. |
256 | 243 |
257 The new repo only has a requirements file and pointer to the source. | 244 The new repo only has a requirements file and pointer to the source. |
269 | 256 |
270 if bookmarks: | 257 if bookmarks: |
271 fp = destrepo.vfs('shared', 'w') | 258 fp = destrepo.vfs('shared', 'w') |
272 fp.write('bookmarks\n') | 259 fp.write('bookmarks\n') |
273 fp.close() | 260 fp.close() |
261 | |
262 def _postshareupdate(repo, update, checkout=None): | |
263 """Maybe perform a working directory update after a shared repo is created. | |
264 | |
265 ``update`` can be a boolean or a revision to update to. | |
266 """ | |
267 if not update: | |
268 return | |
269 | |
270 repo.ui.status(_("updating working directory\n")) | |
271 if update is not True: | |
272 checkout = update | |
273 for test in (checkout, 'default', 'tip'): | |
274 if test is None: | |
275 continue | |
276 try: | |
277 uprev = repo.lookup(test) | |
278 break | |
279 except error.RepoLookupError: | |
280 continue | |
281 _update(repo, uprev) | |
274 | 282 |
275 def copystore(ui, srcrepo, destpath): | 283 def copystore(ui, srcrepo, destpath): |
276 '''copy files from store of srcrepo in destpath | 284 '''copy files from store of srcrepo in destpath |
277 | 285 |
278 returns destlock | 286 returns destlock |
359 # share mode. | 367 # share mode. |
360 clone(ui, peeropts, source, dest=sharepath, pull=True, | 368 clone(ui, peeropts, source, dest=sharepath, pull=True, |
361 rev=rev, update=False, stream=stream) | 369 rev=rev, update=False, stream=stream) |
362 | 370 |
363 sharerepo = repository(ui, path=sharepath) | 371 sharerepo = repository(ui, path=sharepath) |
364 share(ui, sharerepo, dest=dest, update=update, bookmarks=False) | 372 share(ui, sharerepo, dest=dest, update=False, bookmarks=False) |
365 | 373 |
366 # We need to perform a pull against the dest repo to fetch bookmarks | 374 # We need to perform a pull against the dest repo to fetch bookmarks |
367 # and other non-store data that isn't shared by default. In the case of | 375 # and other non-store data that isn't shared by default. In the case of |
368 # non-existing shared repo, this means we pull from the remote twice. This | 376 # non-existing shared repo, this means we pull from the remote twice. This |
369 # is a bit weird. But at the time it was implemented, there wasn't an easy | 377 # is a bit weird. But at the time it was implemented, there wasn't an easy |
370 # way to pull just non-changegroup data. | 378 # way to pull just non-changegroup data. |
371 destrepo = repository(ui, path=dest) | 379 destrepo = repository(ui, path=dest) |
372 exchange.pull(destrepo, srcpeer, heads=revs) | 380 exchange.pull(destrepo, srcpeer, heads=revs) |
381 | |
382 _postshareupdate(destrepo, update) | |
373 | 383 |
374 return srcpeer, peer(ui, peeropts, dest) | 384 return srcpeer, peer(ui, peeropts, dest) |
375 | 385 |
376 def clone(ui, peeropts, source, dest=None, pull=False, rev=None, | 386 def clone(ui, peeropts, source, dest=None, pull=False, rev=None, |
377 update=True, stream=False, branch=None, shareopts=None): | 387 update=True, stream=False, branch=None, shareopts=None): |