From patchwork Wed Feb 12 01:34:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [11, of, 13] pull: make pulled subset a propertycache of the pull object From: Pierre-Yves David X-Patchwork-Id: 3610 Message-Id: <04223fff05d98b5da574.1392168865@marginatus.alto.octopoid.net> To: mercurial-devel@selenic.com Cc: pierre-yves.david@ens-lyon.org Date: Tue, 11 Feb 2014 17:34:25 -0800 # HG changeset patch # User Pierre-Yves David # Date 1391160840 28800 # Fri Jan 31 01:34:00 2014 -0800 # Node ID 04223fff05d98b5da574c70dec2505009b422c50 # Parent 93c4f719c762381d8b5a820b5896a4851de55653 pull: make pulled subset a propertycache of the pull object The computation of the subset is simple operation using two useful pull information (1) the set of common changeset before the pull (2) the set of pulled changeset. We move this data into the `pulloperation` object since some phase will need them. And we turn the pulled subset computation behind a property case as multiple pull phase will need it. diff --git a/mercurial/exchange.py b/mercurial/exchange.py --- a/mercurial/exchange.py +++ b/mercurial/exchange.py @@ -334,12 +334,27 @@ class pulloperation(object): self.force = force # the name the pull transaction self._trname = 'pull\n' + util.hidepassword(remote.url()) # hold the transaction once created self._tr = None - # heads of the set of changeset target by the pull - self.pulledsubset = None + # set of common changeset between local and remote before pull + self.common = None + # set of pulled head + self.rheads = None + + @util.propertycache + def pulledsubset(self): + """heads of the set of changeset target by the pull""" + # compute target subset + if self.heads is None: + # We pulled every thing possible + # sync on everything common + return self.common + self.rheads + else: + # We pulled a specific subset + # sync on this subset + return self.heads def gettransaction(self): """get appropriate pull transaction, creating it if needed""" if self._tr is None: self._tr = self.repo.transaction(self._trname) @@ -369,30 +384,32 @@ def pull(repo, remote, heads=None, force try: tmp = discovery.findcommonincoming(pullop.repo.unfiltered(), pullop.remote, heads=pullop.heads, force=pullop.force) - common, fetch, rheads = tmp + pullop.common, fetch, pullop.rheads = tmp if not fetch: pullop.repo.ui.status(_("no changes found\n")) result = 0 else: # We delay the open of the transaction as late as possible so we # don't open transaction for nothing or you break future useful # rollback call pullop.gettransaction() - if pullop.heads is None and list(common) == [nullid]: + if pullop.heads is None and list(pullop.common) == [nullid]: pullop.repo.ui.status(_("requesting all changes\n")) elif (pullop.heads is None and pullop.remote.capable('changegroupsubset')): # issue1320, avoid a race if remote changed after discovery - pullop.heads = rheads + pullop.heads = pullop.rheads if pullop.remote.capable('getbundle'): # TODO: get bundlecaps from remote - cg = pullop.remote.getbundle('pull', common=common, - heads=pullop.heads or rheads) + cg = pullop.remote.getbundle('pull', + common=pullop.common, + heads=(pullop.heads + or pullop.rheads)) elif pullop.heads is None: cg = pullop.remote.changegroup(fetch, 'pull') elif not pullop.remote.capable('changegroupsubset'): raise util.Abort(_("partial pull cannot be done because " "other repository doesn't support " @@ -401,21 +418,10 @@ def pull(repo, remote, heads=None, force cg = pullop.remote.changegroupsubset(fetch, pullop.heads, 'pull') result = pullop.repo.addchangegroup(cg, 'pull', pullop.remote.url()) - # compute target subset - if pullop.heads is None: - # We pulled every thing possible - # sync on everything common - subset = common + rheads - else: - # We pulled a specific subset - # sync on this subset - subset = pullop.heads - pullop.pulledsubset = subset - _pullphase(pullop) _pullobsolete(pullop) pullop.closetransaction() finally: pullop.releasetransaction()