Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[git-clang-format] add fallback style argument option #137609

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

apdofficial
Copy link

No description provided.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Apr 28, 2025

@llvm/pr-subscribers-clang-format

Author: Andrej Pištek (apdofficial)

Changes

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

1 Files Affected:

  • (modified) clang/tools/clang-format/git-clang-format (+22-2)
diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format
index e709803d9a3f1..99373630d59f5 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -189,6 +189,14 @@ def main():
         default=config.get("clangformat.style", None),
         help="passed to clang-format",
     ),
+    p.add_argument(
+        "--fallback-style",
+        default=None,
+        help="The name of the predefined style used as a"
+        "fallback in case clang-format is invoked with"
+        "-style=file, but can not find the .clang-format"
+        "file to use.",
+    ),
     p.add_argument(
         "-v",
         "--verbose",
@@ -279,7 +287,11 @@ def main():
         old_tree = create_tree_from_workdir(changed_lines)
         revision = None
     new_tree = run_clang_format_and_save_to_tree(
-        changed_lines, revision, binary=opts.binary, style=opts.style
+        changed_lines,
+        revision,
+        binary=opts.binary,
+        style=opts.style,
+        fallback_style=opts.fallback_style,
     )
     if opts.verbose >= 1:
         print("old tree: %s" % old_tree)
@@ -531,7 +543,11 @@ def create_tree_from_index(filenames):
 
 
 def run_clang_format_and_save_to_tree(
-    changed_lines, revision=None, binary="clang-format", style=None
+    changed_lines,
+    revision=None,
+    binary="clang-format",
+    style=None,
+    fallback_style=None,
 ):
     """Run clang-format on each file and save the result to a git tree.
 
@@ -583,6 +599,7 @@ def run_clang_format_and_save_to_tree(
                 revision=revision,
                 binary=binary,
                 style=style,
+                fallback_style=fallback_style,
                 env=env,
             )
             yield "%s %s\t%s" % (mode, blob_id, filename)
@@ -616,6 +633,7 @@ def clang_format_to_blob(
     revision=None,
     binary="clang-format",
     style=None,
+    fallback_style=None,
     env=None,
 ):
     """Run clang-format on the given file and save the result to a git blob.
@@ -628,6 +646,8 @@ def clang_format_to_blob(
     clang_format_cmd = [binary]
     if style:
         clang_format_cmd.extend(["--style=" + style])
+    if fallback_style:
+        clang_format_cmd.extend(["--fallback-style=" + fallback_style])
     clang_format_cmd.extend(
         [
             "--lines=%s:%s" % (start_line, start_line + line_count - 1)

@owenca
Copy link
Contributor

owenca commented May 1, 2025

Please add a description so that we'll understand why you need this new option.

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.

3 participants