def _handlechangespec_2(op, inpart): includepats = set(inpart.params.get(_SPECPART_INCLUDE, '').splitlines()) excludepats = set(inpart.params.get(_SPECPART_EXCLUDE, '').splitlines()) narrowspec.validatepatterns(includepats) narrowspec.validatepatterns(excludepats) if not repository.NARROW_REQUIREMENT in op.repo.requirements: op.repo.requirements.add(repository.NARROW_REQUIREMENT) op.repo._writerequirements() op.repo.setnarrowpats(includepats, excludepats)
def _handlenarrowspecs(op, inpart): data = inpart.read() inc, exc = data.split(b'\0') includepats = set(inc.splitlines()) excludepats = set(exc.splitlines()) narrowspec.validatepatterns(includepats) narrowspec.validatepatterns(excludepats) if requirements.NARROW_REQUIREMENT not in op.repo.requirements: op.repo.requirements.add(requirements.NARROW_REQUIREMENT) scmutil.writereporequirements(op.repo) op.repo.setnarrowpats(includepats, excludepats) narrowspec.copytoworkingcopy(op.repo)
def _handlechangespec_2(op, inpart): # XXX: This bundle2 handling is buggy and should be removed after hg5.2 is # released. New servers will send a mandatory bundle2 part named # 'Narrowspec' and will send specs as data instead of params. # Refer to issue5952 and 6019 includepats = set(inpart.params.get(_SPECPART_INCLUDE, b'').splitlines()) excludepats = set(inpart.params.get(_SPECPART_EXCLUDE, b'').splitlines()) narrowspec.validatepatterns(includepats) narrowspec.validatepatterns(excludepats) if not requirements.NARROW_REQUIREMENT in op.repo.requirements: op.repo.requirements.add(requirements.NARROW_REQUIREMENT) scmutil.writereporequirements(op.repo) op.repo.setnarrowpats(includepats, excludepats) narrowspec.copytoworkingcopy(op.repo)
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 clonenarrowcmd(orig, ui, repo, *args, **opts): """Wraps clone command, so 'hg clone' first wraps localrepo.clone().""" opts = pycompat.byteskwargs(opts) wrappedextraprepare = util.nullcontextmanager() narrowspecfile = opts[b'narrowspec'] if narrowspecfile: filepath = os.path.join(encoding.getcwd(), narrowspecfile) ui.status(_(b"reading narrowspec from '%s'\n") % filepath) try: fdata = util.readfile(filepath) except IOError as inst: raise error.Abort( _(b"cannot read narrowspecs from '%s': %s") % (filepath, encoding.strtolocal(inst.strerror))) includes, excludes, profiles = sparse.parseconfig(ui, fdata, b'narrow') if profiles: raise error.Abort( _(b"cannot specify other files using '%include' in" b" narrowspec")) narrowspec.validatepatterns(includes) narrowspec.validatepatterns(excludes) # narrowspec is passed so we should assume that user wants narrow clone opts[b'narrow'] = True opts[b'include'].extend(includes) opts[b'exclude'].extend(excludes) if opts[b'narrow']: def pullbundle2extraprepare_widen(orig, pullop, kwargs): orig(pullop, kwargs) if opts.get(b'depth'): kwargs[b'depth'] = opts[b'depth'] wrappedextraprepare = extensions.wrappedfunction( exchange, b'_pullbundle2extraprepare', pullbundle2extraprepare_widen) with wrappedextraprepare: return orig(ui, repo, *args, **pycompat.strkwargs(opts))