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

via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 4 13:49:27 PST 2023


Author: Owen Pan
Date: 2023-12-04T13:49:23-08:00
New Revision: 78940a4e1f7f484d8a2dd0c646e288d6a5bf2f81

URL: https://github.com/llvm/llvm-project/commit/78940a4e1f7f484d8a2dd0c646e288d6a5bf2f81
DIFF: https://github.com/llvm/llvm-project/commit/78940a4e1f7f484d8a2dd0c646e288d6a5bf2f81.diff

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

This is a rework of #74176, which erroneously changed the default
clang-format filename (`clang-format`, `clang-format.exe`, etc.) to an
absolute pathname. Instead, we should do that only if the name is a
pathname, e.g. `./clang-format`,
`llvm-project/build/bin/clang-format.exe`, etc. See also
https://github.com/llvm/llvm-project/pull/74176#issuecomment-1837921351.

Added: 
    

Modified: 
    clang/tools/clang-format/git-clang-format

Removed: 
    


################################################################################
diff  --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format
index 6e827e17b4ee2..f7b25b7deae2b 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -153,7 +153,10 @@ 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 os.path.dirname(opts.binary):
+    opts.binary = os.path.abspath(opts.binary)
+
   changed_lines = compute_
diff _and_extract_lines(commits, files, opts.staged)
   if opts.verbose >= 1:
     ignored_files = set(changed_lines)


        


More information about the cfe-commits mailing list