Skip to content

Commit 7620fe0

Browse files
authored
[CI][format] Explicitly pass extensions to git-clang-format (llvm#95794)
This ensures that the CI script controls which file extensions are considered instead of letting git-clang-format apply its own filtering rules. In particular, this properly handles libc++ extension-less headers which were passed to git-clang-format, but then dropped by that tool as having an unrecognized extension.
1 parent 7ddff3a commit 7620fe0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

llvm/utils/git/code-format-helper.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,17 @@ def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str
216216
cf_cmd.append(args.start_rev)
217217
cf_cmd.append(args.end_rev)
218218

219+
# Gather the extension of all modified files and pass them explicitly to git-clang-format.
220+
# This prevents git-clang-format from applying its own filtering rules on top of ours.
221+
extensions = set()
222+
for file in cpp_files:
223+
_, ext = os.path.splitext(file)
224+
extensions.add(
225+
ext.strip(".")
226+
) # Exclude periods since git-clang-format takes extensions without them
227+
cf_cmd.append("--extensions")
228+
cf_cmd.append("'{}'".format(",".join(extensions)))
229+
219230
cf_cmd.append("--")
220231
cf_cmd += cpp_files
221232

0 commit comments

Comments
 (0)