@@ -189,6 +189,13 @@ def main():
189
189
default = config .get ("clangformat.style" , None ),
190
190
help = "passed to clang-format" ,
191
191
),
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
+ ),
192
199
p .add_argument (
193
200
"-v" ,
194
201
"--verbose" ,
@@ -279,7 +286,11 @@ def main():
279
286
old_tree = create_tree_from_workdir (changed_lines )
280
287
revision = None
281
288
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 ,
283
294
)
284
295
if opts .verbose >= 1 :
285
296
print ("old tree: %s" % old_tree )
@@ -531,7 +542,11 @@ def create_tree_from_index(filenames):
531
542
532
543
533
544
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 ,
535
550
):
536
551
"""Run clang-format on each file and save the result to a git tree.
537
552
@@ -583,6 +598,7 @@ def run_clang_format_and_save_to_tree(
583
598
revision = revision ,
584
599
binary = binary ,
585
600
style = style ,
601
+ fallback_style = fallback_style ,
586
602
env = env ,
587
603
)
588
604
yield "%s %s\t %s" % (mode , blob_id , filename )
@@ -616,6 +632,7 @@ def clang_format_to_blob(
616
632
revision = None ,
617
633
binary = "clang-format" ,
618
634
style = None ,
635
+ fallback_style = None ,
619
636
env = None ,
620
637
):
621
638
"""Run clang-format on the given file and save the result to a git blob.
@@ -628,6 +645,8 @@ def clang_format_to_blob(
628
645
clang_format_cmd = [binary ]
629
646
if style :
630
647
clang_format_cmd .extend (["--style=" + style ])
648
+ if fallback_style :
649
+ clang_format_cmd .extend (["--fallback-style=" + fallback_style ])
631
650
clang_format_cmd .extend (
632
651
[
633
652
"--lines=%s:%s" % (start_line , start_line + line_count - 1 )
0 commit comments