git_cl: sets opts.full if format-full-by-default is set

settings.GetFormatFullByDefault() looks up a git config to find if
format-full-by-default is set.

RunClangFormatDiff() and RunGoogleJavaFormat() uses the function to
determine whether it should format a given document full or not, and
it makes it difficult to make the wrapper functions git-op free.

To remove git dependencies from the Run functions, this CL simply sets
opts.full if the default is set.

Note that this CL makes a behaviour change to the Python Runner.

RunYapf() doesn't honor settings.GetFormatFullByDefault().
It just looks at opts.full only to determine how to format the file.
If this CL is landed, RunYapf() will take account of the git config to
determine whether it should format the full document or a part.

Bug: 386840832
Change-Id: Ibd7210e20897d354bd3eddf84927cf22105b7255
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6256552
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Scott Lee <ddoman@chromium.org>
changes/52/6256552/6
Scott Lee 5 days ago committed by LUCI CQ
parent e803e2cb4b
commit f945c74073

@ -6608,7 +6608,7 @@ def _RunClangFormatDiff(opts, clang_diff_files, top_dir, upstream_commit):
except clang_format.NotFoundError as e:
DieWithError(e)
if opts.full or settings.GetFormatFullByDefault():
if opts.full:
cmd = [clang_format_tool]
if not opts.dry_run and not opts.diff:
cmd.append('-i')
@ -6675,7 +6675,7 @@ def _RunGoogleJavaFormat(opts, paths, top_dir, upstream_commit):
else:
base_cmd += ['--replace']
changed_lines_only = not (opts.full or settings.GetFormatFullByDefault())
changed_lines_only = not opts.full
if changed_lines_only:
# Format two lines around each changed line so that the correct amount
# of blank lines will be added between symbols.
@ -7045,6 +7045,7 @@ def CMDformat(parser, args):
help='Enables formatting of .star files.')
opts, files = parser.parse_args(args)
opts.full = opts.full or settings.GetFormatFullByDefault()
# Normalize files against the current path, so paths relative to the
# current directory are still resolved as expected.

Loading…
Cancel
Save