[clang] [git-clang-format] Fix: make the tool backward compatible (PR #108721)

via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 14 15:28:05 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-format

Author: Eden Reich (edenreich)

<details>
<summary>Changes</summary>

## Summary

Currently it's not backward compatible, because the flag -list-ignored doesn't exists on older version of clang-format.

To make this tool still backward compatible, we can first check if the .clang-format-ignore file exists before we run clang-format with the -list-ignored flag.

---
Full diff: https://github.com/llvm/llvm-project/pull/108721.diff


1 Files Affected:

- (modified) clang/tools/clang-format/git-clang-format (+2) 


``````````diff
diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format
index bacbd8de245666..997644045c1f25 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -402,6 +402,8 @@ def filter_symlinks(dictionary):
 
 def filter_ignored_files(dictionary, binary):
   """Delete every key in `dictionary` that is ignored by clang-format."""
+  if not os.path.exists('.clang-format-ignore'):
+    return
   ignored_files = run(binary, '-list-ignored', *dictionary.keys())
   if not ignored_files:
     return

``````````

</details>


https://github.com/llvm/llvm-project/pull/108721


More information about the cfe-commits mailing list