[clang] Add option to format a whole file using git-clang-format (PR #204336)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 19 00:39:54 PDT 2026


================
@@ -456,11 +461,23 @@ def extract_lines(patch_file):
     zero lines of context.  The return value is a dict mapping filename to a
     list of line `Range`s."""
     matches = {}
+
+    if whole_file:
----------------
eoineoineoin wrote:

The diff output from compute_diff() contains filenames relative to the root of the git repository. If the user runs `git clang-format` in a directory other than the root of the repository, those filenames don't exist relative to your $PWD, so we can't `open()` them to build the `Range` on lines 478,479.

This code gets the absolute path to the git repository so we can join it with those relative names, which makes the script invariant with respect to whatever directory it's run in.

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


More information about the cfe-commits mailing list