[clang] [git-clang-format] Fix: make the tool backward compatible (PR #108721)
Eden Reich via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 14 15:27:11 PDT 2024
https://github.com/edenreich created https://github.com/llvm/llvm-project/pull/108721
## 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.
>From 04bf30e5d21460d8ceef1e2ef514b3c4653530f4 Mon Sep 17 00:00:00 2001
From: Eden Reich <eden.reich at gmail.com>
Date: Sun, 15 Sep 2024 00:25:50 +0200
Subject: [PATCH] Fix git-clang-format
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.
---
clang/tools/clang-format/git-clang-format | 2 ++
1 file changed, 2 insertions(+)
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
More information about the cfe-commits
mailing list