Bug 1542629 - clang-format git hook: Ignore unsupported extensions directly in the hook r=sheehan

Differential Revision: https://phabricator.services.mozilla.com/D26445

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Sylvestre Ledru 2019-04-08 16:18:54 +00:00
parent 5312b75864
commit ef3c576ac4

View File

@ -27,7 +27,23 @@ def run_clang_format(hooktype, changedFiles):
# No files have been touched
return
arguments = ["clang-format", "-p"] + changedFiles
# We have also a copy of this list in:
# python/mozbuild/mozbuild/mach_commands.py
# version-control-tools/hgext/clang-format/__init__.py
# release-services/src/staticanalysis/bot/static_analysis_bot/config.py
# Too heavy to import the full class just for this variable
extensions = (".cpp", ".c", ".cc", ".h", ".m", ".mm")
path_list = []
for filename in sorted(changedFiles):
# Ignore files unsupported in clang-format
if filename.endswith(extensions):
path_list.append(filename)
if not path_list:
# No files have been touched
return
arguments = ["clang-format", "-p"] + path_list
# On windows we need this to call the command in a shell, see Bug 1511594
if os.name == "nt":
clang_format_cmd = ["sh", "mach"] + arguments
@ -39,7 +55,7 @@ def run_clang_format(hooktype, changedFiles):
# Add the modified files back to the repo (expect a string)
# one by one (fails otherwise, see bug #1541409)
for f in changedFiles:
for f in path_list:
vcs.add_remove_files(f)
return False