[clang] [git-clang-format] add fallback style argument option (PR #137609)
https://github.com/apdofficial created https://github.com/llvm/llvm-project/pull/137609 None From 3a6307266d0247ce65880786c82094350b6c6d8b Mon Sep 17 00:00:00 2001 From: Andrej Pistek Date: Mon, 7 Apr 2025 13:37:47 +0200 Subject: [PATCH] [git-clang-format] add fallback style arg --- clang/tools/clang-format/git-clang-format | 24 +-- 1 file changed, 22 insertions(+), 2 deletions(-) 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) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [git-clang-format] add fallback style argument option (PR #137609)
https://github.com/apdofficial edited https://github.com/llvm/llvm-project/pull/137609 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [git-clang-format] add fallback style argument option (PR #137609)
apdofficial wrote: > @llvm/pr-subscribers-clang-format > > Author: Andrej Pištek (apdofficial) > Changes Please let me know whether the updated description is sufficient. If noy, I can update it. Thank you. https://github.com/llvm/llvm-project/pull/137609 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [git-clang-format] add fallback style argument option (PR #137609)
https://github.com/apdofficial edited https://github.com/llvm/llvm-project/pull/137609 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [git-clang-format] add fallback style argument option (PR #137609)
https://github.com/apdofficial edited https://github.com/llvm/llvm-project/pull/137609 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [git-clang-format] add fallback style argument option (PR #137609)
https://github.com/apdofficial edited https://github.com/llvm/llvm-project/pull/137609 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [git-clang-format] add fallback style argument option (PR #137609)
https://github.com/apdofficial updated https://github.com/llvm/llvm-project/pull/137609 From 2e82063e9e2c159a7a713ecedbcc0bfbdbf66143 Mon Sep 17 00:00:00 2001 From: Andrej Pistek Date: Mon, 7 Apr 2025 13:37:47 +0200 Subject: [PATCH] [git-clang-format] add fallback style arg --- clang/tools/clang-format/git-clang-format | 23 +-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format index e709803d9a3f1..8a92853dc96c4 100755 --- a/clang/tools/clang-format/git-clang-format +++ b/clang/tools/clang-format/git-clang-format @@ -189,6 +189,13 @@ def main(): default=config.get("clangformat.style", None), help="passed to clang-format", ), +p.add_argument( +"--fallback-style", +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 +286,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 +542,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 +598,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 +632,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 +645,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) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [git-clang-format] add fallback style argument option (PR #137609)
https://github.com/apdofficial updated https://github.com/llvm/llvm-project/pull/137609 From 49c012fc5813867f56f3f9b3556dcb70a1985cfd Mon Sep 17 00:00:00 2001 From: Andrej Pistek Date: Mon, 7 Apr 2025 13:37:47 +0200 Subject: [PATCH] [git-clang-format] add fallback style arg --- clang/tools/clang-format/git-clang-format | 23 +-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format index e709803d9a3f1..3993687b3ad5c 100755 --- a/clang/tools/clang-format/git-clang-format +++ b/clang/tools/clang-format/git-clang-format @@ -189,6 +189,13 @@ def main(): default=config.get("clangformat.style", None), help="passed to clang-format", ), +p.add_argument( +"--fallback-style", +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 +286,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 +542,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 +598,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 +632,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 +645,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) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add --fallback-style to git-clang-format (PR #137609)
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 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 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 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) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add --fallback-style to git-clang-format (PR #137609)
apdofficial wrote: @mydeveloperday, that is a valid question. The reason is that we have many legacy repositories that do not have a `.clang-format file`. The legacy repositories are in a maintenance phase, and most importantly, they follow a custom code style. We want to implement a standard code style without refactoring the legacy code. This means adding a `.clang-format` file would not truthfully reflect the actual code style in the legacy repositories. This MR enables checking only the newly added code according to the new code style. https://github.com/llvm/llvm-project/pull/137609 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add --fallback-style to git-clang-format (PR #137609)
https://github.com/apdofficial updated https://github.com/llvm/llvm-project/pull/137609 From 2e82063e9e2c159a7a713ecedbcc0bfbdbf66143 Mon Sep 17 00:00:00 2001 From: Andrej Pistek Date: Mon, 7 Apr 2025 13:37:47 +0200 Subject: [PATCH 1/2] [git-clang-format] add fallback style arg --- clang/tools/clang-format/git-clang-format | 23 +-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format index e709803d9a3f1..8a92853dc96c4 100755 --- a/clang/tools/clang-format/git-clang-format +++ b/clang/tools/clang-format/git-clang-format @@ -189,6 +189,13 @@ def main(): default=config.get("clangformat.style", None), help="passed to clang-format", ), +p.add_argument( +"--fallback-style", +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 +286,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 +542,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 +598,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 +632,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 +645,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) From 534efbfc9ab956064e1a9aa72be40b2637456386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20Pi=C5=A1tek?= Date: Tue, 20 May 2025 08:57:45 +0200 Subject: [PATCH 2/2] Update clang/tools/clang-format/git-clang-format Co-authored-by: Owen Pan --- clang/tools/clang-format/git-clang-format | 5 + 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format index 8a92853dc96c4..23e15ee9a8fd3 100755 --- a/clang/tools/clang-format/git-clang-format +++ b/clang/tools/clang-format/git-clang-format @@ -191,10 +191,7 @@ def main(): ), p.add_argument( "--fallback-style", -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.", +help="passed to clang-format", ), p.add_argument( "-v", ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add --fallback-style to git-clang-format (PR #137609)
https://github.com/apdofficial updated https://github.com/llvm/llvm-project/pull/137609 From 6e23e19561cddc0e55e96cfd1ba9d27ddce853e3 Mon Sep 17 00:00:00 2001 From: Andrej Pistek Date: Mon, 7 Apr 2025 13:37:47 +0200 Subject: [PATCH] [git-clang-format] add fallback style arg --- clang/tools/clang-format/git-clang-format | 38 --- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format index e709803d9a3f1..e028853579fa7 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", @@ -162,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", @@ -196,15 +209,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 was present. # However, to print pretty messages, we make use of metavar and help. @@ -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) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add --fallback-style to git-clang-format (PR #137609)
@@ -189,6 +189,13 @@ def main(): default=config.get("clangformat.style", None), help="passed to clang-format", ), +p.add_argument( apdofficial wrote: Sure, no problem. I rebased the MR with all the changes. https://github.com/llvm/llvm-project/pull/137609 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits