Details
Details
- Reviewers
pulkit - Group Reviewers
hg-reviewers - Commits
- rHG257c9846b532: fix: compute changed lines lazily to make whole-file fixer tools faster
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
pulkit |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Returns the file content that results from applying the fixers in some order | Returns the file content that results from applying the fixers in some order | ||||
starting with the file's content in the fixctx. Fixers that support line | starting with the file's content in the fixctx. Fixers that support line | ||||
ranges will affect lines that have changed relative to any of the basectxs | ranges will affect lines that have changed relative to any of the basectxs | ||||
(i.e. they will only avoid lines that are common to all basectxs). | (i.e. they will only avoid lines that are common to all basectxs). | ||||
""" | """ | ||||
newdata = fixctx[path].data() | newdata = fixctx[path].data() | ||||
for fixername, fixer in fixers.iteritems(): | for fixername, fixer in fixers.iteritems(): | ||||
if fixer.affects(opts, fixctx, path): | if fixer.affects(opts, fixctx, path): | ||||
ranges = lineranges(opts, path, basectxs, fixctx, newdata) | rangesfn = lambda: lineranges(opts, path, basectxs, fixctx, newdata) | ||||
command = fixer.command(ui, path, ranges) | command = fixer.command(ui, path, rangesfn) | ||||
if command is None: | if command is None: | ||||
continue | continue | ||||
ui.debug('subprocess: %s\n' % (command,)) | ui.debug('subprocess: %s\n' % (command,)) | ||||
proc = subprocess.Popen( | proc = subprocess.Popen( | ||||
command, | command, | ||||
shell=True, | shell=True, | ||||
cwd='/', | cwd='/', | ||||
stdin=subprocess.PIPE, | stdin=subprocess.PIPE, | ||||
class Fixer(object): | class Fixer(object): | ||||
"""Wraps the raw config values for a fixer with methods""" | """Wraps the raw config values for a fixer with methods""" | ||||
def affects(self, opts, fixctx, path): | def affects(self, opts, fixctx, path): | ||||
"""Should this fixer run on the file at the given path and context?""" | """Should this fixer run on the file at the given path and context?""" | ||||
return scmutil.match(fixctx, [self._fileset], opts)(path) | 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 | """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 | May return None if there is no appropriate command to run for the given | ||||
parameters. | parameters. | ||||
""" | """ | ||||
expand = cmdutil.rendercommandtemplate | expand = cmdutil.rendercommandtemplate | ||||
parts = [expand(ui, self._command, | parts = [expand(ui, self._command, | ||||
{'rootpath': path, 'basename': os.path.basename(path)})] | {'rootpath': path, 'basename': os.path.basename(path)})] | ||||
if self._linerange: | if self._linerange: | ||||
ranges = rangesfn() | |||||
if not ranges: | if not ranges: | ||||
# No line ranges to fix, so don't run the fixer. | # No line ranges to fix, so don't run the fixer. | ||||
return None | return None | ||||
for first, last in ranges: | for first, last in ranges: | ||||
parts.append(expand(ui, self._linerange, | parts.append(expand(ui, self._linerange, | ||||
{'first': first, 'last': last})) | {'first': first, 'last': last})) | ||||
return ' '.join(parts) | return ' '.join(parts) |