Skip to content

Commit

Permalink
Bug 1542629 - clang-format git hook: Ignore unsupported extensions di…
Browse files Browse the repository at this point in the history
…rectly in the hook r=sheehan

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
sylvestre committed Apr 8, 2019
1 parent 5312b75 commit ef3c576
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tools/lint/hooks_clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ef3c576

Please sign in to comment.