[clang] [clang-format] Fix a bug in `git-clang-format --binary` (PR #74293)

via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 4 01:11:39 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

<details>
<summary>Changes</summary>

This is a rework of #<!-- -->74176.

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


1 Files Affected:

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


``````````diff
diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format
index 6e827e17b4ee2..1a4d7670bcf79 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -105,7 +105,7 @@ def main():
     usage=usage, formatter_class=argparse.RawDescriptionHelpFormatter,
     description=desc)
   p.add_argument('--binary',
-                 default=config.get('clangformat.binary', 'clang-format'),
+                 type=os.path.abspath,
                  help='path to clang-format'),
   p.add_argument('--commit',
                  default=config.get('clangformat.commit', 'HEAD'),
@@ -153,7 +153,8 @@ def main():
   else:
     if len(commits) > 2:
       die('at most two commits allowed; %d given' % len(commits))
-  opts.binary=os.path.abspath(opts.binary)
+  if opts.binary is None:
+    opts.binary = config.get('clangformat.binary', 'clang-format')
   changed_lines = compute_diff_and_extract_lines(commits, files, opts.staged)
   if opts.verbose >= 1:
     ignored_files = set(changed_lines)

``````````

</details>


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


More information about the cfe-commits mailing list