# HG changeset patch # User Rodrigo Damazio Bovendorp # Date 2020-07-10 03:46:52 # Node ID 263cf0f60b70aa62cf81a45c6012afe531dd8c62 # Parent f204ba74004bbcd7d7ba7ab6586d16a95ddd4733 fix: prefetch file contents This prevents the worker subprocesses from contacting the server individually, which is either inefficient, or leads to problems if the connection is shared among them. Differential Revision: https://phab.mercurial-scm.org/D8723 diff --git a/hgext/fix.py b/hgext/fix.py --- a/hgext/fix.py +++ b/hgext/fix.py @@ -271,6 +271,11 @@ def fix(ui, repo, *pats, **opts): basepaths = getbasepaths(repo, opts, workqueue, basectxs) fixers = getfixers(ui) + # Rather than letting each worker independently fetch the files + # (which also would add complications for shared/keepalive + # connections), prefetch them all first. + _prefetchfiles(repo, workqueue, basepaths) + # There are no data dependencies between the workers fixing each file # revision, so we can use all available parallelism. def getfixes(items): @@ -630,6 +635,24 @@ def getbasectxs(repo, opts, revstofix): basectxs[rev].add(pctx) return basectxs +def _prefetchfiles(repo, workqueue, basepaths): + toprefetch = set() + + # Prefetch the files that will be fixed. + for rev, path in workqueue: + if rev == wdirrev: + continue + toprefetch.add((rev, path)) + + # Prefetch the base contents for lineranges(). + for (baserev, fixrev, path), basepath in basepaths.items(): + toprefetch.add((baserev, basepath)) + + if toprefetch: + scmutil.prefetchfiles(repo, [ + (rev, scmutil.matchfiles(repo, [path])) for rev, path in toprefetch + ]) + def fixfile(ui, repo, opts, fixers, fixctx, path, basepaths, basectxs): """Run any configured fixers that should affect the file in this context