def narrow_widen(repo, proto, oldincludes, oldexcludes, newincludes, newexcludes, commonheads, cgversion, known, ellipses): """wireprotocol command to send data when a narrow clone is widen. We will be sending a changegroup here. The current set of arguments which are required: oldincludes: the old includes of the narrow copy oldexcludes: the old excludes of the narrow copy newincludes: the new includes of the narrow copy newexcludes: the new excludes of the narrow copy commonheads: list of heads which are common between the server and client cgversion(maybe): the changegroup version to produce known: list of nodes which are known on the client (used in ellipses cases) ellipses: whether to send ellipses data or not """ preferuncompressed = False try: oldincludes = wireprototypes.decodelist(oldincludes) newincludes = wireprototypes.decodelist(newincludes) oldexcludes = wireprototypes.decodelist(oldexcludes) newexcludes = wireprototypes.decodelist(newexcludes) # validate the patterns narrowspec.validatepatterns(set(oldincludes)) narrowspec.validatepatterns(set(newincludes)) narrowspec.validatepatterns(set(oldexcludes)) narrowspec.validatepatterns(set(newexcludes)) common = wireprototypes.decodelist(commonheads) known = None if known: known = wireprototypes.decodelist(known) if ellipses == '0': ellipses = False else: ellipses = bool(ellipses) cgversion = cgversion newmatch = narrowspec.match(repo.root, include=newincludes, exclude=newexcludes) oldmatch = narrowspec.match(repo.root, include=oldincludes, exclude=oldexcludes) bundler = bundle2.widen_bundle(repo, oldmatch, newmatch, common, known, cgversion, ellipses) except error.Abort as exc: bundler = bundle2.bundle20(repo.ui) manargs = [('message', pycompat.bytestr(exc))] advargs = [] if exc.hint is not None: advargs.append(('hint', exc.hint)) bundler.addpart(bundle2.bundlepart('error:abort', manargs, advargs)) preferuncompressed = True chunks = bundler.getchunks() return wireprototypes.streamres(gen=chunks, prefer_uncompressed=preferuncompressed)
def getfiles(repo, proto): """A server api for requesting particular versions of particular files. """ if shallowrepo.requirement in repo.requirements: raise error.Abort(_('cannot fetch remote files from shallow repo')) if not isinstance(proto, _sshv1server): raise error.Abort(_('cannot fetch remote files over non-ssh protocol')) def streamer(): try: # hg 4.6 and later fin = proto._fin except AttributeError: # hg 4.5 and earlier fin = proto.fin cachepath = repo.ui.config("remotefilelog", "servercachepath") if not cachepath: cachepath = os.path.join(repo.path, "remotefilelogcache") while True: request = fin.readline()[:-1] if not request: break node = bin(request[:40]) if node == nullid: yield '0\n' continue path = request[40:] text = _loadfileblob(repo, cachepath, path, node) yield '%d\n%s' % (len(text), text) # it would be better to only flush after processing a whole batch # but currently we don't know if there are more requests coming try: # hg 4.6 and later proto._fout.flush() except AttributeError: # hg 4.5 and earlier proto.fout.flush() return wireprototypes.streamres(streamer())
def stream_out_shallow(repo, proto, other): includepattern = None excludepattern = None raw = other.get(b'includepattern') if raw: includepattern = raw.split(b'\0') raw = other.get(b'excludepattern') if raw: excludepattern = raw.split(b'\0') oldshallow = state.shallowremote oldmatch = state.match oldnoflatmf = state.noflatmf try: state.shallowremote = True state.match = match.always() state.noflatmf = other.get(b'noflatmanifest') == b'True' if includepattern or excludepattern: state.match = match.match(repo.root, b'', None, includepattern, excludepattern) streamres = wireprotov1server.stream(repo, proto) # Force the first value to execute, so the file list is computed # within the try/finally scope first = next(streamres.gen) second = next(streamres.gen) def gen(): yield first yield second for value in streamres.gen: yield value return wireprototypes.streamres(gen()) finally: state.shallowremote = oldshallow state.match = oldmatch state.noflatmf = oldnoflatmf
def getfiles(repo, proto): """A server api for requesting particular versions of particular files. """ if shallowutil.isenabled(repo): raise error.Abort(_(b'cannot fetch remote files from shallow repo')) if not isinstance(proto, _sshv1server): raise error.Abort( _(b'cannot fetch remote files over non-ssh protocol')) def streamer(): fin = proto._fin cachepath = repo.ui.config(b"remotefilelog", b"servercachepath") if not cachepath: cachepath = os.path.join(repo.path, b"remotefilelogcache") while True: request = fin.readline()[:-1] if not request: break node = bin(request[:40]) if node == nullid: yield b'0\n' continue path = request[40:] text = _loadfileblob(repo, cachepath, path, node) yield b'%d\n%s' % (len(text), text) # it would be better to only flush after processing a whole batch # but currently we don't know if there are more requests coming proto._fout.flush() return wireprototypes.streamres(streamer())
def stream_out_shallow(repo, proto, other): includepattern = None excludepattern = None raw = other.get('includepattern') if raw: includepattern = raw.split('\0') raw = other.get('excludepattern') if raw: excludepattern = raw.split('\0') oldshallow = state.shallowremote oldmatch = state.match oldnoflatmf = state.noflatmf try: state.shallowremote = True state.match = match.always(repo.root, '') state.noflatmf = other.get('noflatmanifest') == 'True' if includepattern or excludepattern: state.match = match.match(repo.root, '', None, includepattern, excludepattern) streamres = wireprotov1server.stream(repo, proto) # Force the first value to execute, so the file list is computed # within the try/finally scope first = next(streamres.gen) second = next(streamres.gen) def gen(): yield first yield second for value in streamres.gen: yield value return wireprototypes.streamres(gen()) finally: state.shallowremote = oldshallow state.match = oldmatch state.noflatmf = oldnoflatmf
def getpack(repo, proto, args): """A server api for requesting a pack of file information. """ if shallowrepo.requirement in repo.requirements: raise error.Abort(_('cannot fetch remote files from shallow repo')) if not isinstance(proto, _sshv1server): raise error.Abort(_('cannot fetch remote files over non-ssh protocol')) def streamer(): """Request format: [<filerequest>,...]\0\0 filerequest = <filename len: 2 byte><filename><count: 4 byte> [<node: 20 byte>,...] Response format: [<fileresponse>,...]<10 null bytes> fileresponse = <filename len: 2 byte><filename><history><deltas> history = <count: 4 byte>[<history entry>,...] historyentry = <node: 20 byte><p1: 20 byte><p2: 20 byte> <linknode: 20 byte><copyfrom len: 2 byte><copyfrom> deltas = <count: 4 byte>[<delta entry>,...] deltaentry = <node: 20 byte><deltabase: 20 byte> <delta len: 8 byte><delta> """ try: # hg 4.6 and later fin = proto._fin except AttributeError: # hg 4.5 and earlier fin = proto.fin files = _receivepackrequest(fin) # Sort the files by name, so we provide deterministic results for filename, nodes in sorted(files.iteritems()): fl = repo.file(filename) # Compute history history = [] for rev in ancestor.lazyancestors(fl.parentrevs, [fl.rev(n) for n in nodes], inclusive=True): x, x, x, x, linkrev, p1, p2, node = fl.index[rev] copyfrom = '' p1node = fl.node(p1) p2node = fl.node(p2) linknode = repo.changelog.node(linkrev) if p1node == nullid: copydata = fl.renamed(node) if copydata: copyfrom, copynode = copydata p1node = copynode history.append((node, p1node, p2node, linknode, copyfrom)) # Scan and send deltas chain = _getdeltachain(fl, nodes, -1) for chunk in wirepack.sendpackpart(filename, history, chain): yield chunk yield wirepack.closepart() try: # hg 4.6 and later proto._fout.flush() except AttributeError: # hg 4.5 and earlier proto.fout.flush() return wireprototypes.streamres(streamer())