-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[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
base: main
Are you sure you want to change the base?
[git-clang-format] add fallback style argument option #137609
Conversation
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 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. |
@llvm/pr-subscribers-clang-format Author: Andrej Pištek (apdofficial) ChangesFull diff: https://github.com/llvm/llvm-project/pull/137609.diff 1 Files Affected:
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)
|
Please add a description so that we'll understand why you need this new option. |
Please let me know whether the updated description is sufficient. If not, I can update it. Thank you. |
3a63072
to
49c012f
Compare
49c012f
to
2e82063
Compare
This MR implements a fallback style option for the cases when no
.clang-format
is available.I need a pipeline workflow where some repositories don't have a
.clang-format
file. I want to allow specifying a fallback style so that formatting can still run consistently in those cases.