# HG changeset patch # User Rodrigo Damazio Bovendorp # Date 1594352735 25200 # Node ID 54009f8c3e25198711d4c30fff1846ee6da300fc # Parent a56ba57c837df9aab1675f44fd0cb221522715b1 fix: obtain base paths before starting workers This moves calculation of base paths to before work is dispatched. While this does mean that copy tracing will be serialized instead of parallel, it is necessary to be able to prefetch the base contents in a batch, which will likely be more efficient. Differential Revision: https://phab.mercurial-scm.org/D8722 diff -r a56ba57c837d -r 54009f8c3e25 hgext/fix.py --- a/hgext/fix.py Thu Jul 09 18:48:55 2020 -0700 +++ b/hgext/fix.py Thu Jul 09 20:45:35 2020 -0700 @@ -268,6 +268,7 @@ workqueue, numitems = getworkqueue( ui, repo, pats, opts, revstofix, basectxs ) + basepaths = getbasepaths(repo, opts, workqueue, basectxs) fixers = getfixers(ui) # There are no data dependencies between the workers fixing each file @@ -277,7 +278,7 @@ ctx = repo[rev] olddata = ctx[path].data() metadata, newdata = fixfile( - ui, repo, opts, fixers, ctx, path, basectxs[rev] + ui, repo, opts, fixers, ctx, path, basepaths, basectxs[rev] ) # Don't waste memory/time passing unchanged content back, but # produce one result per item either way. @@ -473,7 +474,7 @@ return files -def lineranges(opts, path, basectxs, fixctx, content2): +def lineranges(opts, path, basepaths, basectxs, fixctx, content2): """Returns the set of line ranges that should be fixed in a file Of the form [(10, 20), (30, 40)]. @@ -492,7 +493,8 @@ rangeslist = [] for basectx in basectxs: - basepath = copies.pathcopies(basectx, fixctx).get(path, path) + basepath = basepaths.get((basectx.rev(), fixctx.rev(), path), path) + if basepath in basectx: content1 = basectx[basepath].data() else: @@ -501,6 +503,21 @@ return unionranges(rangeslist) +def getbasepaths(repo, opts, workqueue, basectxs): + if opts.get(b'whole'): + # Base paths will never be fetched for line range determination. + return {} + + basepaths = {} + for rev, path in workqueue: + fixctx = repo[rev] + for basectx in basectxs[rev]: + basepath = copies.pathcopies(basectx, fixctx).get(path, path) + if basepath in basectx: + basepaths[(basectx.rev(), fixctx.rev(), path)] = basepath + return basepaths + + def unionranges(rangeslist): """Return the union of some closed intervals @@ -613,7 +630,7 @@ return basectxs -def fixfile(ui, repo, opts, fixers, fixctx, path, basectxs): +def fixfile(ui, repo, opts, fixers, fixctx, path, basepaths, basectxs): """Run any configured fixers that should affect the file in this context Returns the file content that results from applying the fixers in some order @@ -629,7 +646,9 @@ newdata = fixctx[path].data() for fixername, fixer in pycompat.iteritems(fixers): if fixer.affects(opts, fixctx, path): - ranges = lineranges(opts, path, basectxs, fixctx, newdata) + ranges = lineranges( + opts, path, basepaths, basectxs, fixctx, newdata + ) command = fixer.command(ui, path, ranges) if command is None: continue