diff --git a/hgext/fix.py b/hgext/fix.py --- a/hgext/fix.py +++ b/hgext/fix.py @@ -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