From patchwork Wed Aug 14 20:29:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D6727: fix: pass line ranges as value instead of callback From: phabricator X-Patchwork-Id: 41269 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Wed, 14 Aug 2019 20:29:13 +0000 hooper created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY The callback no longer takes any arguments from the inner function, so we might as well call it sooner and pass the value instead. Note the value still needs to be recomputed every iteration to account for the previous iteration's changes to the file content. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D6727 AFFECTED FILES hgext/fix.py CHANGE DETAILS To: hooper, #hg-reviewers Cc: mercurial-devel diff --git a/hgext/fix.py b/hgext/fix.py --- a/hgext/fix.py +++ b/hgext/fix.py @@ -563,8 +563,8 @@ newdata = fixctx[path].data() for fixername, fixer in fixers.iteritems(): if fixer.affects(opts, fixctx, path): - rangesfn = lambda: lineranges(opts, path, basectxs, fixctx, newdata) - command = fixer.command(ui, path, rangesfn) + ranges = lineranges(opts, path, basectxs, fixctx, newdata) + command = fixer.command(ui, path, ranges) if command is None: continue ui.debug('subprocess: %s\n' % (command,)) @@ -758,7 +758,7 @@ """Should the stdout of this fixer start with JSON and a null byte?""" return self._metadata - def command(self, ui, path, rangesfn): + def command(self, ui, path, ranges): """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 @@ -768,7 +768,6 @@ parts = [expand(ui, self._command, {'rootpath': path, 'basename': os.path.basename(path)})] if self._linerange: - ranges = rangesfn() if self._skipclean and not ranges: # No line ranges to fix, so don't run the fixer. return None