Skip to content

Commit b3c450d

Browse files
authored
[CI][format] Explicitly pass extensions to git-clang-format (take 2) (#98227)
This patch 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 the tool as having an unrecognized extension. This is a second attempt to land 7620fe0, which was reverted in 9572388 because it caused formatting not to be enforced for several patches. The problem was that we'd incorrectly pass the extensions with additional quoting to git-clang-format. The incorrect quoting has been removed in this version of the patch.
1 parent 2fa1220 commit b3c450d

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(",".join(extensions))
229+
219230
cf_cmd.append("--")
220231
cf_cmd += cpp_files
221232

0 commit comments

Comments
 (0)