Mercurial > evolve
diff hgext3rd/pullbundle.py @ 4814:48b30ff742cb
python3: use format-source to run byteify-strings in .py files
Using the format-source extension smooth out the pain of merging after
auto-formatting.
This change makes all of the Evolve test suite pass under python3 and has
added benefit of being 100% automated using mercurial's `byteify-strings`
script version 1.0 (revision 11498aa91c036c6d70f7ac5ee5af2664a84a1130).
How to benefit from the help of format-source is explained in the README.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Tue, 06 Aug 2019 15:06:38 +0200 |
parents | ea8da5aa23c6 |
children | bb2b4f6c99dc |
line wrap: on
line diff
--- a/hgext3rd/pullbundle.py Tue Aug 06 15:06:27 2019 +0200 +++ b/hgext3rd/pullbundle.py Tue Aug 06 15:06:38 2019 +0200 @@ -92,10 +92,10 @@ from mercurial.i18n import _ -__version__ = '0.1.1' -testedwith = '4.4 4.5 4.6 4.7.1' -minimumhgversion = '4.4' -buglink = 'https://bz.mercurial-scm.org/' +__version__ = b'0.1.1' +testedwith = b'4.4 4.5 4.6 4.7.1' +minimumhgversion = b'4.4' +buglink = b'https://bz.mercurial-scm.org/' cmdtable = {} command = registrar.command(cmdtable) @@ -103,14 +103,14 @@ configtable = {} configitem = registrar.configitem(configtable) -configitem('pullbundle', 'cache-directory', +configitem(b'pullbundle', b'cache-directory', default=None, ) # generic wrapping def uisetup(ui): - exchange.getbundle2partsmapping['changegroup'] = _getbundlechangegrouppart + exchange.getbundle2partsmapping[b'changegroup'] = _getbundlechangegrouppart def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None, b2caps=None, heads=None, common=None, **kwargs): @@ -118,13 +118,13 @@ if not kwargs.get(r'cg', True): return - version = '01' - cgversions = b2caps.get('changegroup') + version = b'01' + cgversions = b2caps.get(b'changegroup') if cgversions: # 3.1 and 3.2 ship with an empty value cgversions = [v for v in cgversions if v in changegroup.supportedoutgoingversions(repo)] if not cgversions: - raise ValueError(_('no common changegroup version')) + raise ValueError(_(b'no common changegroup version')) version = max(cgversions) outgoing = exchange._computeoutgoing(repo, heads, common) @@ -145,20 +145,20 @@ # END OF ALTERED PART if kwargs.get(r'narrow', False) and (include or exclude): - narrowspecpart = bundler.newpart('narrow:spec') + narrowspecpart = bundler.newpart(b'narrow:spec') if include: narrowspecpart.addparam( - 'include', '\n'.join(include), mandatory=True) + b'include', b'\n'.join(include), mandatory=True) if exclude: narrowspecpart.addparam( - 'exclude', '\n'.join(exclude), mandatory=True) + b'exclude', b'\n'.join(exclude), mandatory=True) def makeallcgpart(newpart, repo, outgoing, version, source, bundlecaps, filematcher, cgversions): pullbundle = not filematcher if pullbundle and not util.safehasattr(repo, 'stablerange'): - repo.ui.warn('pullbundle: required extension "evolve" are missing, skipping pullbundle\n') + repo.ui.warn(b'pullbundle: required extension "evolve" are missing, skipping pullbundle\n') pullbundle = False if filematcher: makeonecgpart(newpart, repo, None, outgoing, version, source, bundlecaps, @@ -167,8 +167,8 @@ start = util.timer() slices = sliceoutgoing(repo, outgoing) end = util.timer() - msg = _('pullbundle-cache: "missing" set sliced into %d subranges ' - 'in %f seconds\n') + msg = _(b'pullbundle-cache: "missing" set sliced into %d subranges ' + b'in %f seconds\n') repo.ui.write(msg % (len(slices), end - start)) for sliceid, sliceout in slices: makeonecgpart(newpart, repo, sliceid, sliceout, version, source, bundlecaps, @@ -192,7 +192,7 @@ missingheads = [rev(n) for n in sorted(outgoing.missingheads, reverse=True)] for head in missingheads: localslices = [] - localmissing = set(repo.revs('%ld and ::%d', missingrevs, head)) + localmissing = set(repo.revs(b'%ld and ::%d', missingrevs, head)) thisrunmissing = localmissing.copy() while localmissing: slicerevs = [] @@ -207,11 +207,11 @@ missingrevs.difference_update(slicerevs) localmissing.difference_update(slicerevs) if localmissing: - heads = list(repo.revs('heads(%ld)', localmissing)) + heads = list(repo.revs(b'heads(%ld)', localmissing)) heads.sort(key=node) head = heads.pop() if heads: - thisrunmissing = repo.revs('%ld and only(%d, %ld)', + thisrunmissing = repo.revs(b'%ld and only(%d, %ld)', localmissing, head, heads) @@ -220,15 +220,15 @@ if DEBUG: for s in reversed(ss): ms -= set(s) - missingbase = repo.revs('parents(%ld) and %ld', s, ms) + missingbase = repo.revs(b'parents(%ld) and %ld', s, ms) if missingbase: - repo.ui.write_err('!!! rev bundled while parents missing\n') - repo.ui.write_err(' parent: %s\n' % list(missingbase)) - pb = repo.revs('%ld and children(%ld)', s, missingbase) - repo.ui.write_err(' children: %s\n' % list(pb)) - h = repo.revs('heads(%ld)', s) - repo.ui.write_err(' heads: %s\n' % list(h)) - raise error.ProgrammingError('issuing a range before its parents') + repo.ui.write_err(b'!!! rev bundled while parents missing\n') + repo.ui.write_err(b' parent: %s\n' % list(missingbase)) + pb = repo.revs(b'%ld and children(%ld)', s, missingbase) + repo.ui.write_err(b' children: %s\n' % list(pb)) + h = repo.revs(b'heads(%ld)', s) + repo.ui.write_err(b' heads: %s\n' % list(h)) + raise error.ProgrammingError(b'issuing a range before its parents') for s in reversed(localslices): allslices.extend(s) @@ -381,8 +381,8 @@ # changegroup part construction def _changegroupinfo(repo, nodes, source): - if repo.ui.verbose or source == 'bundle': - repo.ui.status(_("%d changesets found\n") % len(nodes)) + if repo.ui.verbose or source == b'bundle': + repo.ui.status(_(b"%d changesets found\n") % len(nodes)) def _makenewstream(newpart, repo, outgoing, version, source, bundlecaps, filematcher, cgversions): @@ -408,23 +408,23 @@ def _makepartfromstream(newpart, repo, cgstream, nbchanges, version): # same as upstream code - part = newpart('changegroup', data=cgstream) + part = newpart(b'changegroup', data=cgstream) if version: - part.addparam('version', version) + part.addparam(b'version', version) - part.addparam('nbchanges', '%d' % nbchanges, + part.addparam(b'nbchanges', b'%d' % nbchanges, mandatory=False) - if 'treemanifest' in repo.requirements: - part.addparam('treemanifest', '1') + if b'treemanifest' in repo.requirements: + part.addparam(b'treemanifest', b'1') # cache management def cachedir(repo): - cachedir = repo.ui.config('pullbundle', 'cache-directory') + cachedir = repo.ui.config(b'pullbundle', b'cache-directory') if cachedir is not None: return cachedir - return repo.cachevfs.join('pullbundles') + return repo.cachevfs.join(b'pullbundles') def getcache(repo, bundlename): cdir = cachedir(repo) @@ -454,7 +454,7 @@ cachefile.write(chunk) yield chunk -BUNDLEMASK = "%s-%s-%010iskip-%010isize.hg" +BUNDLEMASK = b"%s-%s-%010iskip-%010isize.hg" def makeonecgpart(newpart, repo, rangeid, outgoing, version, source, bundlecaps, filematcher, cgversions): @@ -472,19 +472,19 @@ cgstream = cachewriter(repo, bundlename, partdata[0]) partdata = (cgstream,) + partdata[1:] else: - if repo.ui.verbose or source == 'bundle': - repo.ui.status(_("%d changesets found in caches\n") % nbchanges) + if repo.ui.verbose or source == b'bundle': + repo.ui.status(_(b"%d changesets found in caches\n") % nbchanges) pversion = None if cgversions: pversion = version partdata = (cachedata, nbchanges, pversion) return _makepartfromstream(newpart, repo, *partdata) -@command('debugpullbundlecacheoverlap', - [('', 'count', 100, _('of "client" pulling')), - ('', 'min-cache', 1, _('minimum size of cached bundle')), - ], - _('hg debugpullbundlecacheoverlap [--client 100] REVSET')) +@command(b'debugpullbundlecacheoverlap', + [(b'', b'count', 100, _(b'of "client" pulling')), + (b'', b'min-cache', 1, _(b'minimum size of cached bundle')), + ], + _(b'hg debugpullbundlecacheoverlap [--client 100] REVSET')) def debugpullbundlecacheoverlap(ui, repo, *revs, **opts): '''Display statistic on bundle cache hit @@ -494,7 +494,7 @@ ''' actionrevs = scmutil.revrange(repo, revs) if not revs: - raise error.Abort('No revision selected') + raise error.Abort(b'No revision selected') count = opts['count'] min_cache = opts['min_cache'] @@ -503,12 +503,12 @@ rlen = lambda rangeid: repo.stablerange.rangelength(repo, rangeid) - repo.ui.write("gathering %d sample pulls within %d revisions\n" + repo.ui.write(b"gathering %d sample pulls within %d revisions\n" % (count, len(actionrevs))) if 1 < min_cache: - repo.ui.write(" not caching ranges smaller than %d changesets\n" % min_cache) + repo.ui.write(b" not caching ranges smaller than %d changesets\n" % min_cache) for i in range(count): - repo.ui.progress('gathering data', i, total=count) + repo.ui.progress(b'gathering data', i, total=count) outgoing = takeonesample(repo, actionrevs) ranges = sliceoutgoing(repo, outgoing) hitranges = 0 @@ -532,7 +532,7 @@ hitranges, ) pullstats.append(stats) - repo.ui.progress('gathering data', None) + repo.ui.progress(b'gathering data', None) sizes = [] changesmissing = [] @@ -563,36 +563,36 @@ cachedhits.append(hits) sizesdist = distribution(sizes) - repo.ui.write(fmtdist('pull size', sizesdist)) + repo.ui.write(fmtdist(b'pull size', sizesdist)) changesmissingdist = distribution(changesmissing) - repo.ui.write(fmtdist('non-cached changesets', changesmissingdist)) + repo.ui.write(fmtdist(b'non-cached changesets', changesmissingdist)) changesratiodist = distribution(changesratio) - repo.ui.write(fmtdist('ratio of cached changesets', changesratiodist)) + repo.ui.write(fmtdist(b'ratio of cached changesets', changesratiodist)) bundlecountdist = distribution(bundlecount) - repo.ui.write(fmtdist('bundle count', bundlecountdist)) + repo.ui.write(fmtdist(b'bundle count', bundlecountdist)) rangesratiodist = distribution(rangesratio) - repo.ui.write(fmtdist('ratio of cached bundles', rangesratiodist)) + repo.ui.write(fmtdist(b'ratio of cached bundles', rangesratiodist)) - repo.ui.write('changesets served:\n') - repo.ui.write(' total: %7d\n' % totalchanges) - repo.ui.write(' from cache: %7d (%2d%%)\n' + repo.ui.write(b'changesets served:\n') + repo.ui.write(b' total: %7d\n' % totalchanges) + repo.ui.write(b' from cache: %7d (%2d%%)\n' % (totalcached, (totalcached * 100 // totalchanges))) - repo.ui.write(' bundle: %7d\n' % sum(bundlecount)) + repo.ui.write(b' bundle: %7d\n' % sum(bundlecount)) cachedsizesdist = distribution(cachedsizes) - repo.ui.write(fmtdist('size of cached bundles', cachedsizesdist)) + repo.ui.write(fmtdist(b'size of cached bundles', cachedsizesdist)) cachedhitsdist = distribution(cachedhits) - repo.ui.write(fmtdist('hit on cached bundles', cachedhitsdist)) + repo.ui.write(fmtdist(b'hit on cached bundles', cachedhitsdist)) def takeonesample(repo, revs): node = repo.changelog.node pulled = random.sample(revs, max(4, len(revs) // 1000)) - pulled = repo.revs('%ld::%ld', pulled, pulled) + pulled = repo.revs(b'%ld::%ld', pulled, pulled) nodes = [node(r) for r in pulled] return outgoingfromnodes(repo, nodes) @@ -600,17 +600,17 @@ data.sort() length = len(data) return { - 'min': data[0], - '10%': data[length // 10], - '25%': data[length // 4], - '50%': data[length // 2], - '75%': data[(length // 4) * 3], - '90%': data[(length // 10) * 9], - '95%': data[(length // 20) * 19], - 'max': data[-1], + b'min': data[0], + b'10%': data[length // 10], + b'25%': data[length // 4], + b'50%': data[length // 2], + b'75%': data[(length // 4) * 3], + b'90%': data[(length // 10) * 9], + b'95%': data[(length // 20) * 19], + b'max': data[-1], } -STATSFORMAT = """{name}: +STATSFORMAT = b"""{name}: min: {min} 10%: {10%} 25%: {25%}