Commit 18c981b0 authored by Martijn Pieters's avatar Martijn Pieters
Browse files

format-source: run tools in parallel for better performance

parent 0f75915355fe
......@@ -58,6 +58,7 @@
registrar,
scmutil,
util,
worker,
)
from mercurial.i18n import _
......@@ -126,7 +127,10 @@
wctx = repo[None]
# files to be formatted
matcher = scmutil.match(wctx, pats, opts)
# perform actual formatting
with ui.makeprogress(_('formatting'), unit=_('files')) as progress:
for filepath in wctx.matches(matcher):
files = list(wctx.matches(matcher))
# perform actual formatting, using parellel workers where possible
with ui.makeprogress(_('formatting'), unit=_('files'), total=len(files)) as progress:
proc = worker.worker(ui, 0.1, batchformat, (repo, wctx, tool, shell_tool), files)
for filepath in proc:
progress.increment(item=filepath)
......@@ -132,14 +136,4 @@
progress.increment(item=filepath)
flags = wctx.flags(filepath)
if 'l' in flags:
# links should just be skipped
ui.warn(_('Skipping symlink, %s\n') % filepath)
continue
newcontent = run_tools(ui, repo.root, tool, shell_tool, filepath, filepath)
# XXX we could do the whole commit in memory
with repo.wvfs(filepath, 'wb') as formatted_file:
formatted_file.write(newcontent)
wctx.filectx(filepath).setflags(False, 'x' in flags)
# update the storage to mark formated file as formatted
with repo.wvfs(file_storage_path, mode='ab') as storage:
......@@ -166,6 +160,20 @@
commit_patterns.extend(pats)
return commands._docommit(ui, repo, *commit_patterns, **opts)
def batchformat(repo, wctx, tool, shell_tool, files):
for filepath in files:
flags = wctx.flags(filepath)
if 'l' in flags:
# links should just be skipped
repo.ui.warn(_('Skipping symlink, %s\n') % filepath)
continue
newcontent = run_tools(repo.ui, repo.root, tool, shell_tool, filepath, filepath)
# XXX we could do the whole commit in memory
with repo.wvfs(filepath, 'wb') as formatted_file:
formatted_file.write(newcontent)
wctx.filectx(filepath).setflags(False, 'x' in flags)
yield filepath
def run_tools(ui, root, tool, cmd, filepath, filename):
"""Run the a formatter tool on a specific file"""
env = encoding.environ.copy()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment