comparison mercurial/exchange.py @ 20474:c9bceafc61be

pull: move `heads` argument into pull object One more step toward a more modular pull function.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Thu, 30 Jan 2014 17:35:55 -0800
parents 1516daaca632
children b79b405583af
comparison
equal deleted inserted replaced
20473:1516daaca632 20474:c9bceafc61be
380 380
381 A new should be created at the begining of each push and discarded 381 A new should be created at the begining of each push and discarded
382 afterward. 382 afterward.
383 """ 383 """
384 384
385 def __init__(self, repo, remote): 385 def __init__(self, repo, remote, heads=None):
386 # repo we pull from 386 # repo we pull from
387 self.repo = repo 387 self.repo = repo
388 # repo we pull to 388 # repo we pull to
389 self.remote = remote 389 self.remote = remote
390 # revision we try to pull (None is "all")
391 self.heads = heads
390 392
391 def pull(repo, remote, heads=None, force=False): 393 def pull(repo, remote, heads=None, force=False):
392 pullop = pulloperation(repo, remote) 394 pullop = pulloperation(repo, remote, heads)
393 if pullop.remote.local(): 395 if pullop.remote.local():
394 missing = set(pullop.remote.requirements) - pullop.repo.supported 396 missing = set(pullop.remote.requirements) - pullop.repo.supported
395 if missing: 397 if missing:
396 msg = _("required features are not" 398 msg = _("required features are not"
397 " supported in the destination:" 399 " supported in the destination:"
404 trname = 'pull\n' + util.hidepassword(pullop.remote.url()) 406 trname = 'pull\n' + util.hidepassword(pullop.remote.url())
405 lock = pullop.repo.lock() 407 lock = pullop.repo.lock()
406 try: 408 try:
407 tmp = discovery.findcommonincoming(pullop.repo.unfiltered(), 409 tmp = discovery.findcommonincoming(pullop.repo.unfiltered(),
408 pullop.remote, 410 pullop.remote,
409 heads=heads, force=force) 411 heads=pullop.heads,
412 force=force)
410 common, fetch, rheads = tmp 413 common, fetch, rheads = tmp
411 if not fetch: 414 if not fetch:
412 pullop.repo.ui.status(_("no changes found\n")) 415 pullop.repo.ui.status(_("no changes found\n"))
413 result = 0 416 result = 0
414 else: 417 else:
415 tr = pullop.repo.transaction(trname) 418 tr = pullop.repo.transaction(trname)
416 if heads is None and list(common) == [nullid]: 419 if pullop.heads is None and list(common) == [nullid]:
417 pullop.repo.ui.status(_("requesting all changes\n")) 420 pullop.repo.ui.status(_("requesting all changes\n"))
418 elif heads is None and pullop.remote.capable('changegroupsubset'): 421 elif (pullop.heads is None
422 and pullop.remote.capable('changegroupsubset')):
419 # issue1320, avoid a race if remote changed after discovery 423 # issue1320, avoid a race if remote changed after discovery
420 heads = rheads 424 pullop.heads = rheads
421 425
422 if pullop.remote.capable('getbundle'): 426 if pullop.remote.capable('getbundle'):
423 # TODO: get bundlecaps from remote 427 # TODO: get bundlecaps from remote
424 cg = pullop.remote.getbundle('pull', common=common, 428 cg = pullop.remote.getbundle('pull', common=common,
425 heads=heads or rheads) 429 heads=pullop.heads or rheads)
426 elif heads is None: 430 elif pullop.heads is None:
427 cg = pullop.remote.changegroup(fetch, 'pull') 431 cg = pullop.remote.changegroup(fetch, 'pull')
428 elif not pullop.remote.capable('changegroupsubset'): 432 elif not pullop.remote.capable('changegroupsubset'):
429 raise util.Abort(_("partial pull cannot be done because " 433 raise util.Abort(_("partial pull cannot be done because "
430 "other repository doesn't support " 434 "other repository doesn't support "
431 "changegroupsubset.")) 435 "changegroupsubset."))
432 else: 436 else:
433 cg = pullop.remote.changegroupsubset(fetch, heads, 'pull') 437 cg = pullop.remote.changegroupsubset(fetch, pullop.heads,
438 'pull')
434 result = pullop.repo.addchangegroup(cg, 'pull', 439 result = pullop.repo.addchangegroup(cg, 'pull',
435 pullop.remote.url()) 440 pullop.remote.url())
436 441
437 # compute target subset 442 # compute target subset
438 if heads is None: 443 if pullop.heads is None:
439 # We pulled every thing possible 444 # We pulled every thing possible
440 # sync on everything common 445 # sync on everything common
441 subset = common + rheads 446 subset = common + rheads
442 else: 447 else:
443 # We pulled a specific subset 448 # We pulled a specific subset
444 # sync on this subset 449 # sync on this subset
445 subset = heads 450 subset = pullop.heads
446 451
447 # Get remote phases data from remote 452 # Get remote phases data from remote
448 remotephases = pullop.remote.listkeys('phases') 453 remotephases = pullop.remote.listkeys('phases')
449 publishing = bool(remotephases.get('publishing', False)) 454 publishing = bool(remotephases.get('publishing', False))
450 if remotephases and not publishing: 455 if remotephases and not publishing: