##// END OF EJS Templates
exchange: extract pull function from localrepo...
Pierre-Yves David -
r20469:6b4c789d default
parent child Browse files
Show More
@@ -6,7 +6,7 b''
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from i18n import _
8 from i18n import _
9 from node import hex
9 from node import hex, nullid
10 import errno
10 import errno
11 import util, scmutil, changegroup
11 import util, scmutil, changegroup
12 import discovery, phases, obsolete, bookmarks
12 import discovery, phases, obsolete, bookmarks
@@ -372,3 +372,89 b' def _pushbookmark(pushop):'
372 ui.status(_("updating bookmark %s\n") % b)
372 ui.status(_("updating bookmark %s\n") % b)
373 else:
373 else:
374 ui.warn(_('updating bookmark %s failed!\n') % b)
374 ui.warn(_('updating bookmark %s failed!\n') % b)
375
376
377 def pull(repo, remote, heads=None, force=False):
378 if remote.local():
379 missing = set(remote.requirements) - repo.supported
380 if missing:
381 msg = _("required features are not"
382 " supported in the destination:"
383 " %s") % (', '.join(sorted(missing)))
384 raise util.Abort(msg)
385
386 # don't open transaction for nothing or you break future useful
387 # rollback call
388 tr = None
389 trname = 'pull\n' + util.hidepassword(remote.url())
390 lock = repo.lock()
391 try:
392 tmp = discovery.findcommonincoming(repo.unfiltered(), remote,
393 heads=heads, force=force)
394 common, fetch, rheads = tmp
395 if not fetch:
396 repo.ui.status(_("no changes found\n"))
397 result = 0
398 else:
399 tr = repo.transaction(trname)
400 if heads is None and list(common) == [nullid]:
401 repo.ui.status(_("requesting all changes\n"))
402 elif heads is None and remote.capable('changegroupsubset'):
403 # issue1320, avoid a race if remote changed after discovery
404 heads = rheads
405
406 if remote.capable('getbundle'):
407 # TODO: get bundlecaps from remote
408 cg = remote.getbundle('pull', common=common,
409 heads=heads or rheads)
410 elif heads is None:
411 cg = remote.changegroup(fetch, 'pull')
412 elif not remote.capable('changegroupsubset'):
413 raise util.Abort(_("partial pull cannot be done because "
414 "other repository doesn't support "
415 "changegroupsubset."))
416 else:
417 cg = remote.changegroupsubset(fetch, heads, 'pull')
418 result = repo.addchangegroup(cg, 'pull', remote.url())
419
420 # compute target subset
421 if heads is None:
422 # We pulled every thing possible
423 # sync on everything common
424 subset = common + rheads
425 else:
426 # We pulled a specific subset
427 # sync on this subset
428 subset = heads
429
430 # Get remote phases data from remote
431 remotephases = remote.listkeys('phases')
432 publishing = bool(remotephases.get('publishing', False))
433 if remotephases and not publishing:
434 # remote is new and unpublishing
435 pheads, _dr = phases.analyzeremotephases(repo, subset,
436 remotephases)
437 phases.advanceboundary(repo, phases.public, pheads)
438 phases.advanceboundary(repo, phases.draft, subset)
439 else:
440 # Remote is old or publishing all common changesets
441 # should be seen as public
442 phases.advanceboundary(repo, phases.public, subset)
443
444 def gettransaction():
445 if tr is None:
446 return repo.transaction(trname)
447 return tr
448
449 obstr = obsolete.syncpull(repo, remote, gettransaction)
450 if obstr is not None:
451 tr = obstr
452
453 if tr is not None:
454 tr.close()
455 finally:
456 if tr is not None:
457 tr.release()
458 lock.release()
459
460 return result
@@ -1659,89 +1659,7 b' class localrepository(object):'
1659 return r
1659 return r
1660
1660
1661 def pull(self, remote, heads=None, force=False):
1661 def pull(self, remote, heads=None, force=False):
1662 if remote.local():
1662 return exchange.pull (self, remote, heads, force)
1663 missing = set(remote.requirements) - self.supported
1664 if missing:
1665 msg = _("required features are not"
1666 " supported in the destination:"
1667 " %s") % (', '.join(sorted(missing)))
1668 raise util.Abort(msg)
1669
1670 # don't open transaction for nothing or you break future useful
1671 # rollback call
1672 tr = None
1673 trname = 'pull\n' + util.hidepassword(remote.url())
1674 lock = self.lock()
1675 try:
1676 tmp = discovery.findcommonincoming(self.unfiltered(), remote,
1677 heads=heads, force=force)
1678 common, fetch, rheads = tmp
1679 if not fetch:
1680 self.ui.status(_("no changes found\n"))
1681 result = 0
1682 else:
1683 tr = self.transaction(trname)
1684 if heads is None and list(common) == [nullid]:
1685 self.ui.status(_("requesting all changes\n"))
1686 elif heads is None and remote.capable('changegroupsubset'):
1687 # issue1320, avoid a race if remote changed after discovery
1688 heads = rheads
1689
1690 if remote.capable('getbundle'):
1691 # TODO: get bundlecaps from remote
1692 cg = remote.getbundle('pull', common=common,
1693 heads=heads or rheads)
1694 elif heads is None:
1695 cg = remote.changegroup(fetch, 'pull')
1696 elif not remote.capable('changegroupsubset'):
1697 raise util.Abort(_("partial pull cannot be done because "
1698 "other repository doesn't support "
1699 "changegroupsubset."))
1700 else:
1701 cg = remote.changegroupsubset(fetch, heads, 'pull')
1702 result = self.addchangegroup(cg, 'pull', remote.url())
1703
1704 # compute target subset
1705 if heads is None:
1706 # We pulled every thing possible
1707 # sync on everything common
1708 subset = common + rheads
1709 else:
1710 # We pulled a specific subset
1711 # sync on this subset
1712 subset = heads
1713
1714 # Get remote phases data from remote
1715 remotephases = remote.listkeys('phases')
1716 publishing = bool(remotephases.get('publishing', False))
1717 if remotephases and not publishing:
1718 # remote is new and unpublishing
1719 pheads, _dr = phases.analyzeremotephases(self, subset,
1720 remotephases)
1721 phases.advanceboundary(self, phases.public, pheads)
1722 phases.advanceboundary(self, phases.draft, subset)
1723 else:
1724 # Remote is old or publishing all common changesets
1725 # should be seen as public
1726 phases.advanceboundary(self, phases.public, subset)
1727
1728 def gettransaction():
1729 if tr is None:
1730 return self.transaction(trname)
1731 return tr
1732
1733 obstr = obsolete.syncpull(self, remote, gettransaction)
1734 if obstr is not None:
1735 tr = obstr
1736
1737 if tr is not None:
1738 tr.close()
1739 finally:
1740 if tr is not None:
1741 tr.release()
1742 lock.release()
1743
1744 return result
1745
1663
1746 def checkpush(self, force, revs):
1664 def checkpush(self, force, revs):
1747 """Extensions can override this function if additional checks have
1665 """Extensions can override this function if additional checks have
General Comments 0
You need to be logged in to leave comments. Login now