Patchwork D4100: fix: compute changed lines lazily to make whole-file fixer tools faster

login
register
mail settings
Submitter phabricator
Date Aug. 4, 2018, 5:38 p.m.
Message ID <02b5302f9b71c8ba82d238f119079df2@localhost.localdomain>
Download mbox | patch
Permalink /patch/33240/
State Not Applicable
Headers show

Comments

phabricator - Aug. 4, 2018, 5:38 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG257c9846b532: fix: compute changed lines lazily to make whole-file fixer tools faster (authored by hooper, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4100?vs=9867&id=9904

REVISION DETAIL
  https://phab.mercurial-scm.org/D4100

AFFECTED FILES
  hgext/fix.py

CHANGE DETAILS




To: hooper, #hg-reviewers, pulkit
Cc: mercurial-devel

Patch

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