[clang] [clang-format] Add --fallback-style to git-clang-format (PR #137609)
Andrej Pištek via cfe-commits
cfe-commits at lists.llvm.org
Tue May 20 01:17:00 PDT 2025
https://github.com/apdofficial updated https://github.com/llvm/llvm-project/pull/137609
>From e88b6c0ff69c1ce0679d4c5768c5608a344652e5 Mon Sep 17 00:00:00 2001
From: Andrej Pistek <a.pistek at cosine.nl>
Date: Tue, 20 May 2025 10:15:02 +0200
Subject: [PATCH 1/2] [git-clang-format] sort args in ASCII order
---
clang/tools/clang-format/git-clang-format | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format
index e709803d9a3f1..de63eaa13e62f 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -149,6 +149,15 @@ def main():
action="store_true",
help="print a diff instead of applying the changes",
)
+ p.add_argument(
+ "--diff_from_common_commit",
+ action="store_true",
+ help=(
+ "diff from the last common commit for commits in "
+ "separate branches rather than the exact point of the "
+ "commits"
+ ),
+ )
p.add_argument(
"--diffstat",
action="store_true",
@@ -196,15 +205,6 @@ def main():
default=0,
help="print extra information",
)
- p.add_argument(
- "--diff_from_common_commit",
- action="store_true",
- help=(
- "diff from the last common commit for commits in "
- "separate branches rather than the exact point of the "
- "commits"
- ),
- )
# We gather all the remaining positional arguments into 'args' since we need
# to use some heuristics to determine whether or not <commit> was present.
# However, to print pretty messages, we make use of metavar and help.
>From 502d5be0897b24fe298e22f7f34b32477bbf85dc Mon Sep 17 00:00:00 2001
From: Andrej Pistek <a.pistek at cosine.nl>
Date: Tue, 20 May 2025 10:15:34 +0200
Subject: [PATCH 2/2] [git-clang-format] add fallback style arg
---
clang/tools/clang-format/git-clang-format | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format
index de63eaa13e62f..e028853579fa7 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -171,6 +171,10 @@ def main():
"excluding the period and case-insensitive"
),
),
+ p.add_argument(
+ "--fallback-style",
+ help="passed to clang-format",
+ ),
p.add_argument(
"-f",
"--force",
@@ -279,7 +283,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 +539,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 +595,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 +629,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 +642,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)
More information about the cfe-commits
mailing list