diff --git a/hgext/narrow/narrowbundle2.py b/hgext/narrow/narrowbundle2.py --- a/hgext/narrow/narrowbundle2.py +++ b/hgext/narrow/narrowbundle2.py @@ -34,23 +34,23 @@ narrowspec, ) -narrowcap = 'narrow' -narrowacl_section = 'narrowhgacl' -changespecpart = narrowcap + ':changespec' -specpart = narrowcap + ':spec' -specpart_include = 'include' -specpart_exclude = 'exclude' -killnodesignal = 'KILL' -donesignal = 'DONE' -elidedcsheader = '>20s20s20sl' # cset id, p1, p2, len(text) -elidedmfheader = '>20s20s20s20sl' # manifest id, p1, p2, link id, len(text) -csheadersize = struct.calcsize(elidedcsheader) -mfheadersize = struct.calcsize(elidedmfheader) +NARROWCAP = 'narrow' +NARROWACL_SECTION = 'narrowhgacl' +CHANGESPECPART = NARROWCAP + ':changespec' +SPECPART = NARROWCAP + ':spec' +SPECPART_INCLUDE = 'include' +SPECPART_EXCLUDE = 'exclude' +KILLNODESIGNAL = 'KILL' +DONESIGNAL = 'DONE' +ELIDEDCSHEADER = '>20s20s20sl' # cset id, p1, p2, len(text) +ELIDEDMFHEADER = '>20s20s20s20sl' # manifest id, p1, p2, link id, len(text) +CSHEADERSIZE = struct.calcsize(ELIDEDCSHEADER) +MFHEADERSIZE = struct.calcsize(ELIDEDMFHEADER) # When advertising capabilities, always include narrow clone support. def getrepocaps_narrow(orig, repo, **kwargs): caps = orig(repo, **kwargs) - caps[narrowcap] = ['v0'] + caps[NARROWCAP] = ['v0'] return caps def _computeellipsis(repo, common, heads, known, match, depth=None): @@ -250,13 +250,13 @@ part.addparam('treemanifest', '1') if include or exclude: - narrowspecpart = bundler.newpart(specpart) + narrowspecpart = bundler.newpart(SPECPART) if include: narrowspecpart.addparam( - specpart_include, '\n'.join(include), mandatory=True) + SPECPART_INCLUDE, '\n'.join(include), mandatory=True) if exclude: narrowspecpart.addparam( - specpart_exclude, '\n'.join(exclude), mandatory=True) + SPECPART_EXCLUDE, '\n'.join(exclude), mandatory=True) return @@ -298,10 +298,10 @@ deadrevs = known def genkills(): for r in deadrevs: - yield killnodesignal + yield KILLNODESIGNAL yield repo.changelog.node(r) - yield donesignal - bundler.newpart(changespecpart, data=genkills()) + yield DONESIGNAL + bundler.newpart(CHANGESPECPART, data=genkills()) newvisit, newfull, newellipsis = _computeellipsis( repo, set(), common, known, newmatch) if newvisit: @@ -329,14 +329,14 @@ def applyacl_narrow(repo, kwargs): username = repo.ui.shortuser(repo.ui.username()) user_includes = repo.ui.configlist( - narrowacl_section, username + '.includes', - repo.ui.configlist(narrowacl_section, 'default.includes')) + NARROWACL_SECTION, username + '.includes', + repo.ui.configlist(NARROWACL_SECTION, 'default.includes')) user_excludes = repo.ui.configlist( - narrowacl_section, username + '.excludes', - repo.ui.configlist(narrowacl_section, 'default.excludes')) + NARROWACL_SECTION, username + '.excludes', + repo.ui.configlist(NARROWACL_SECTION, 'default.excludes')) if not user_includes: raise error.Abort(_("{} configuration for user {} is empty") - .format(narrowacl_section, username)) + .format(NARROWACL_SECTION, username)) user_includes = [ 'path:.' if p == '*' else 'path:' + p for p in user_includes] @@ -363,17 +363,17 @@ new_args['excludepats'] = req_excludes return new_args -@bundle2.parthandler(specpart, (specpart_include, specpart_exclude)) +@bundle2.parthandler(SPECPART, (SPECPART_INCLUDE, SPECPART_EXCLUDE)) def _handlechangespec_2(op, inpart): - includepats = set(inpart.params.get(specpart_include, '').splitlines()) - excludepats = set(inpart.params.get(specpart_exclude, '').splitlines()) + includepats = set(inpart.params.get(SPECPART_INCLUDE, '').splitlines()) + excludepats = set(inpart.params.get(SPECPART_EXCLUDE, '').splitlines()) narrowspec.save(op.repo, includepats, excludepats) if not narrowrepo.requirement in op.repo.requirements: op.repo.requirements.add(narrowrepo.requirement) op.repo._writerequirements() op.repo.invalidate(clearfilecache=True) -@bundle2.parthandler(changespecpart) +@bundle2.parthandler(CHANGESPECPART) def _handlechangespec(op, inpart): repo = op.repo cl = repo.changelog @@ -388,8 +388,8 @@ # repo. All the changes that this block encounters are ellipsis # nodes or flags to kill an existing ellipsis. chunksignal = changegroup.readexactly(inpart, 4) - while chunksignal != donesignal: - if chunksignal == killnodesignal: + while chunksignal != DONESIGNAL: + if chunksignal == KILLNODESIGNAL: # a node used to be an ellipsis but isn't anymore ck = changegroup.readexactly(inpart, 20) if cl.hasnode(ck): @@ -477,7 +477,7 @@ origcgfn = exchange.getbundle2partsmapping['changegroup'] def wrappedcgfn(*args, **kwargs): repo = args[1] - if repo.ui.has_section(narrowacl_section): + if repo.ui.has_section(NARROWACL_SECTION): getbundlechangegrouppart_narrow( *args, **applyacl_narrow(repo, kwargs)) elif kwargs.get('narrow', False): diff --git a/hgext/narrow/narrowcommands.py b/hgext/narrow/narrowcommands.py --- a/hgext/narrow/narrowcommands.py +++ b/hgext/narrow/narrowcommands.py @@ -147,7 +147,7 @@ if narrowrepo.requirement not in repo.requirements: return orig(pullop, kwargs) - if narrowbundle2.narrowcap not in pullop.remotebundle2caps: + if narrowbundle2.NARROWCAP not in pullop.remotebundle2caps: raise error.Abort(_("server doesn't support narrow clones")) orig(pullop, kwargs) kwargs['narrow'] = True