diff --git a/remotefilelog/remotefilelogserver.py b/remotefilelog/remotefilelogserver.py --- a/remotefilelog/remotefilelogserver.py +++ b/remotefilelog/remotefilelogserver.py @@ -6,7 +6,7 @@ # GNU General Public License version 2 or any later version. from __future__ import absolute_import -from mercurial import wireproto, changegroup, match, util, changelog, context +from mercurial import changegroup, match, util, changelog, context from mercurial import store, error from mercurial import streamclone from mercurial.extensions import wrapfunction @@ -37,6 +37,21 @@ from mercurial.hgweb import protocol as httpprotocol httpprotocol.decodevaluefromheaders + +try: + from mercurial import wireprototypes + wireprototypes.streamres # force demandimport +except ImportError: + # Before b4d85bc1 (4.6) + from mercurial import wireproto as wireprototypes + +try: + from mercurial import wireprotov1server + wireprotov1server.commands # force demandimport +except ImportError: + # Before b4d85bc1 (4.6) + from mercurial import wireproto as wireprotov1server + def setupserver(ui, repo): """Sets up a normal Mercurial repo so it can serve files to shallow repos. """ @@ -75,10 +90,10 @@ onetime = True # support file content requests - wireproto.commands['getflogheads'] = (getflogheads, 'path') - wireproto.commands['getfiles'] = (getfiles, '') - wireproto.commands['getfile'] = (getfile, 'file node') - wireproto.commands['getpackv1'] = (getpack, '*') + wireprotov1server.commands['getflogheads'] = (getflogheads, 'path') + wireprotov1server.commands['getfiles'] = (getfiles, '') + wireprotov1server.commands['getfile'] = (getfile, 'file node') + wireprotov1server.commands['getpackv1'] = (getpack, '*') class streamstate(object): match = None @@ -106,7 +121,7 @@ if includepattern or excludepattern: state.match = match.match(repo.root, '', None, includepattern, excludepattern) - streamres = wireproto.stream(repo, proto) + streamres = wireprotov1server.stream(repo, proto) # Force the first value to execute, so the file list is computed # within the try/finally scope @@ -117,13 +132,13 @@ yield second for value in streamres.gen: yield value - return wireproto.streamres(gen()) + return wireprototypes.streamres(gen()) finally: state.shallowremote = oldshallow state.match = oldmatch state.noflatmf = oldnoflatmf - wireproto.commands['stream_out_shallow'] = (stream_out_shallow, '*') + wireprotov1server.commands['stream_out_shallow'] = (stream_out_shallow, '*') # don't clone filelogs to shallow clients def _walkstreamfiles(orig, repo): @@ -187,9 +202,9 @@ bundlecaps.add('remotefilelog') others['bundlecaps'] = ','.join(bundlecaps) - return wireproto.commands["getbundle"][0](repo, proto, others) + return wireprotov1server.commands["getbundle"][0](repo, proto, others) - wireproto.commands["getbundle_shallow"] = (getbundleshallow, '*') + wireprotov1server.commands["getbundle_shallow"] = (getbundleshallow, '*') # expose remotefilelog capabilities def _capabilities(orig, repo, proto): @@ -202,10 +217,10 @@ caps.append('getflogheads') caps.append('getfile') return caps - if util.safehasattr(wireproto, '_capabilities'): - wrapfunction(wireproto, '_capabilities', _capabilities) + if util.safehasattr(wireprotov1server, '_capabilities'): + wrapfunction(wireprotov1server, '_capabilities', _capabilities) else: - wrapfunction(wireproto, 'capabilities', _capabilities) + wrapfunction(wireprotov1server, 'capabilities', _capabilities) def _adjustlinkrev(orig, self, *args, **kwargs): # When generating file blobs, taking the real path is too slow on large @@ -334,7 +349,7 @@ except AttributeError: # hg 4.5 and earlier proto.fout.flush() - return wireproto.streamres(streamer()) + return wireprototypes.streamres(streamer()) def createfileblob(filectx): """ @@ -497,7 +512,7 @@ # hg 4.5 and earlier proto.fout.flush() - return wireproto.streamres(streamer()) + return wireprototypes.streamres(streamer()) def _receivepackrequest(stream): files = {}