Mercurial > hg
changeset 26441:56527b886d1d
streamclone: move applystreamclone() from localrepo.py
Upcoming patches will modernize the streaming clone code. Streaming
clone data and code kind of lives in its own world. exchange.py is
arguably the most appropriate existing location for it. However, over
a dozen patches from now it became apparent that there was a lot of code
related to streaming clones and that having it contained within its own
module would make it easier to comprehend. So, we establish
streamclone.py.
It's worth noting that streamclone.py existed a long time ago, last seen
in the 1.6 release. It was removed in 04f76a954842.
The function was renamed as part of the move because its old name was
redundant with the new module name. The only other content change was
"self" was renamed to "repo" and minor grammar in the docstring was
updated.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 02 Oct 2015 15:51:32 -0700 |
parents | 85b992177d2a |
children | ef8d27f53204 |
files | mercurial/localrepo.py mercurial/streamclone.py |
diffstat | 2 files changed, 66 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/localrepo.py Fri Oct 02 15:36:00 2015 -0700 +++ b/mercurial/localrepo.py Fri Oct 02 15:51:32 2015 -0700 @@ -19,6 +19,7 @@ import weakref, errno, os, time, inspect, random import branchmap, pathutil import namespaces +import streamclone propertycache = util.propertycache filecache = scmutil.filecache @@ -1808,60 +1809,9 @@ elif resp != 0: raise util.Abort(_('the server sent an unknown error code')) - self.applystreamclone(remotereqs, rbranchmap, fp) + streamclone.applyremotedata(self, remotereqs, rbranchmap, fp) return len(self.heads()) + 1 - def applystreamclone(self, remotereqs, remotebranchmap, fp): - """Apply stream clone data to this repository. - - "remotereqs" is a set of requirements to handle the incoming data. - "remotebranchmap" is the result of a branchmap lookup on the remote. It - can be None. - "fp" is a file object containing the raw stream data, suitable for - feeding into exchange.consumestreamclone. - """ - lock = self.lock() - try: - exchange.consumestreamclone(self, fp) - - # new requirements = old non-format requirements + - # new format-related remote requirements - # requirements from the streamed-in repository - self.requirements = remotereqs | ( - self.requirements - self.supportedformats) - self._applyopenerreqs() - self._writerequirements() - - if remotebranchmap: - rbheads = [] - closed = [] - for bheads in remotebranchmap.itervalues(): - rbheads.extend(bheads) - for h in bheads: - r = self.changelog.rev(h) - b, c = self.changelog.branchinfo(r) - if c: - closed.append(h) - - if rbheads: - rtiprev = max((int(self.changelog.rev(node)) - for node in rbheads)) - cache = branchmap.branchcache(remotebranchmap, - self[rtiprev].node(), - rtiprev, - closednodes=closed) - # Try to stick it as low as possible - # filter above served are unlikely to be fetch from a clone - for candidate in ('base', 'immutable', 'served'): - rview = self.filtered(candidate) - if cache.validfor(rview): - self._branchcaches[candidate] = cache - cache.write(rview) - break - self.invalidate() - finally: - lock.release() - def clone(self, remote, heads=[], stream=None): '''clone remote repository.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial/streamclone.py Fri Oct 02 15:51:32 2015 -0700 @@ -0,0 +1,64 @@ +# streamclone.py - producing and consuming streaming repository data +# +# Copyright 2015 Gregory Szorc <gregory.szorc@gmail.com> +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. + +from __future__ import absolute_import + +from . import ( + branchmap, + exchange, +) + +def applyremotedata(repo, remotereqs, remotebranchmap, fp): + """Apply stream clone data to a repository. + + "remotereqs" is a set of requirements to handle the incoming data. + "remotebranchmap" is the result of a branchmap lookup on the remote. It + can be None. + "fp" is a file object containing the raw stream data, suitable for + feeding into exchange.consumestreamclone. + """ + lock = repo.lock() + try: + exchange.consumestreamclone(repo, fp) + + # new requirements = old non-format requirements + + # new format-related remote requirements + # requirements from the streamed-in repository + repo.requirements = remotereqs | ( + repo.requirements - repo.supportedformats) + repo._applyopenerreqs() + repo._writerequirements() + + if remotebranchmap: + rbheads = [] + closed = [] + for bheads in remotebranchmap.itervalues(): + rbheads.extend(bheads) + for h in bheads: + r = repo.changelog.rev(h) + b, c = repo.changelog.branchinfo(r) + if c: + closed.append(h) + + if rbheads: + rtiprev = max((int(repo.changelog.rev(node)) + for node in rbheads)) + cache = branchmap.branchcache(remotebranchmap, + repo[rtiprev].node(), + rtiprev, + closednodes=closed) + # Try to stick it as low as possible + # filter above served are unlikely to be fetch from a clone + for candidate in ('base', 'immutable', 'served'): + rview = repo.filtered(candidate) + if cache.validfor(rview): + repo._branchcaches[candidate] = cache + cache.write(rview) + break + repo.invalidate() + finally: + lock.release()