From dfd0bd926b3aaf5ed7a66b201189289374a386cd Mon Sep 17 00:00:00 2001 From: Nigel Babu Date: Sun, 3 Feb 2019 16:51:29 +0530 Subject: Add a fix for clang-format to handle contrib Change-Id: Id326a77b78ef3f8eec12ccd864c11457829e934b Fixes: bz#1671733 --- build-gluster-org/scripts/clang-format.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'build-gluster-org') diff --git a/build-gluster-org/scripts/clang-format.py b/build-gluster-org/scripts/clang-format.py index ebbd2c4..ba23b04 100644 --- a/build-gluster-org/scripts/clang-format.py +++ b/build-gluster-org/scripts/clang-format.py @@ -1,13 +1,25 @@ #!/usr/bin/env python import subprocess -output = subprocess.check_output(["git-clang-format", "HEAD~", "--diff"]) -if output not in ['no modified files to format\n', - 'clang-format did not modify any files\n']: - print(output) - print("The above patch to be applied to pass clang-format") + +changed_files = subprocess.check_output( + ["git", "diff-tree", "--no-commit-id", "--name-only", "-r", "HEAD"] +).split("\n") +list_of_files = [] +for file in changed_files: + if file.startswith("contrib/"): + continue + if file.endswith(".c") or file.endswith(".h"): + subprocess.call(['clang-format', '-i', file]) + +# Look for any changes applied by clang-format +changed = subprocess.check_output(['git', 'diff']) + +if changed: + print(changed) + print("The above patch needs to be applied to pass clang-format") exit(1) -else: - exit(0) +# No changes, pass +print("clang-format did not modify any files") -- cgit