Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/localrepo.py @ 20469:6b4c789d618d
exchange: extract pull function from localrepo
The localrepo class if far too big. Push and pull logic are extracted and
reworked to better fit with the fact we exchange more than bundle now.
This changeset extract the pulh code. later changeset will slowly slice it into
smaller brick.
The localrepo.pull method is kept for now to limit impact on user code. But it
will be ultimately removed, now that the public API is hold by peer.
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Thu, 30 Jan 2014 16:12:49 -0800 |
parents | 9e331f1f0573 |
children | db0740a487ab |
comparison
equal
deleted
inserted
replaced
20468:7d0bbb6dd730 | 20469:6b4c789d618d |
---|---|
1657 r.append(l) | 1657 r.append(l) |
1658 | 1658 |
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 |
1748 to be performed before pushing, or call it if they override push | 1666 to be performed before pushing, or call it if they override push |
1749 command. | 1667 command. |