Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
mercurial
format-source
Commits
18c981b0090a
Commit
18c981b0
authored
Oct 14, 2018
by
Martijn Pieters
Browse files
format-source: run tools in parallel for better performance
parent
0f75915355fe
Changes
1
Hide whitespace changes
Inline
Side-by-side
hgext3rd/formatsource.py
View file @
18c981b0
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment