# HG changeset patch # User Danny Hooper # Date 1533339549 25200 # Node ID 257c9846b53265b52ba6f971e287be73c6459989 # Parent db03e5cefc824b2ee029164b92a59ff70bd1df82 fix: compute changed lines lazily to make whole-file fixer tools faster Differential Revision: https://phab.mercurial-scm.org/D4100 diff -r db03e5cefc82 -r 257c9846b532 hgext/fix.py --- a/hgext/fix.py Sat Aug 04 12:23:18 2018 +0530 +++ b/hgext/fix.py Fri Aug 03 16:39:09 2018 -0700 @@ -436,8 +436,8 @@ newdata = fixctx[path].data() for fixername, fixer in fixers.iteritems(): if fixer.affects(opts, fixctx, path): - ranges = lineranges(opts, path, basectxs, fixctx, newdata) - command = fixer.command(ui, path, ranges) + rangesfn = lambda: lineranges(opts, path, basectxs, fixctx, newdata) + command = fixer.command(ui, path, rangesfn) if command is None: continue ui.debug('subprocess: %s\n' % (command,)) @@ -582,7 +582,7 @@ """Should this fixer run on the file at the given path and context?""" return scmutil.match(fixctx, [self._fileset], opts)(path) - def command(self, ui, path, ranges): + def command(self, ui, path, rangesfn): """A shell command to use to invoke this fixer on the given file/lines May return None if there is no appropriate command to run for the given @@ -592,6 +592,7 @@ parts = [expand(ui, self._command, {'rootpath': path, 'basename': os.path.basename(path)})] if self._linerange: + ranges = rangesfn() if not ranges: # No line ranges to fix, so don't run the fixer. return None