Skip to content

Commit 49c012f

Browse files
author
Andrej Pistek
committed
[git-clang-format] add fallback style arg
1 parent 41c97af commit 49c012f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

clang/tools/clang-format/git-clang-format

+21-2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ def main():
189189
default=config.get("clangformat.style", None),
190190
help="passed to clang-format",
191191
),
192+
p.add_argument(
193+
"--fallback-style",
194+
help="The name of the predefined style used as a"
195+
"fallback in case clang-format is invoked with"
196+
"-style=file, but can not find the .clang-format"
197+
"file to use.",
198+
),
192199
p.add_argument(
193200
"-v",
194201
"--verbose",
@@ -279,7 +286,11 @@ def main():
279286
old_tree = create_tree_from_workdir(changed_lines)
280287
revision = None
281288
new_tree = run_clang_format_and_save_to_tree(
282-
changed_lines, revision, binary=opts.binary, style=opts.style
289+
changed_lines,
290+
revision,
291+
binary=opts.binary,
292+
style=opts.style,
293+
fallback_style=opts.fallback_style,
283294
)
284295
if opts.verbose >= 1:
285296
print("old tree: %s" % old_tree)
@@ -531,7 +542,11 @@ def create_tree_from_index(filenames):
531542

532543

533544
def run_clang_format_and_save_to_tree(
534-
changed_lines, revision=None, binary="clang-format", style=None
545+
changed_lines,
546+
revision=None,
547+
binary="clang-format",
548+
style=None,
549+
fallback_style=None,
535550
):
536551
"""Run clang-format on each file and save the result to a git tree.
537552
@@ -583,6 +598,7 @@ def run_clang_format_and_save_to_tree(
583598
revision=revision,
584599
binary=binary,
585600
style=style,
601+
fallback_style=fallback_style,
586602
env=env,
587603
)
588604
yield "%s %s\t%s" % (mode, blob_id, filename)
@@ -616,6 +632,7 @@ def clang_format_to_blob(
616632
revision=None,
617633
binary="clang-format",
618634
style=None,
635+
fallback_style=None,
619636
env=None,
620637
):
621638
"""Run clang-format on the given file and save the result to a git blob.
@@ -628,6 +645,8 @@ def clang_format_to_blob(
628645
clang_format_cmd = [binary]
629646
if style:
630647
clang_format_cmd.extend(["--style=" + style])
648+
if fallback_style:
649+
clang_format_cmd.extend(["--fallback-style=" + fallback_style])
631650
clang_format_cmd.extend(
632651
[
633652
"--lines=%s:%s" % (start_line, start_line + line_count - 1)

0 commit comments

Comments
 (0)