Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-format] Fix a bug in git-clang-format --binary #74293

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

owenca
Copy link
Contributor

@owenca owenca commented Dec 4, 2023

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 #74176 (comment).

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 4, 2023

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

Changes

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 --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)

Copy link
Contributor

@jayfoad jayfoad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but the commit message should really explain what problem this fixes instead of just saying "rework".

@owenca owenca merged commit 78940a4 into llvm:main Dec 4, 2023
3 checks passed
@owenca owenca deleted the git-clang-format branch December 4, 2023 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants