summaryrefslogtreecommitdiffstats
path: root/build-gluster-org
diff options
context:
space:
mode:
authorNigel Babu <nigelb@redhat.com>2019-02-03 16:51:29 +0530
committerNigel Babu <nigelb@redhat.com>2019-02-03 16:51:29 +0530
commitdfd0bd926b3aaf5ed7a66b201189289374a386cd (patch)
tree0f97b9e669b5d7bafc043b93e02105558bfca321 /build-gluster-org
parent76ff31ccfe6b4a3177c846b7596c08a4333449cb (diff)
Add a fix for clang-format to handle contrib
Change-Id: Id326a77b78ef3f8eec12ccd864c11457829e934b Fixes: bz#1671733
Diffstat (limited to 'build-gluster-org')
-rw-r--r--build-gluster-org/scripts/clang-format.py26
1 files changed, 19 insertions, 7 deletions
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")