git-cl: Add 'format-full-by-default' setting.

Lets the client repository make 'git cl format' use the
'--full' option by default. This solves issues when using less
common clang-format options that don't behave well with small
diffs. For example, AlignConsecutiveAssignments.

This is a replacement for the 'diff-lines-of-context' setting.

Bug: angleproject:4003
Change-Id: I81dc3b4992a7420e7235da88ec78e51ec4c0d24f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1879148
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
changes/48/1879148/2
Jamie Madill 6 years ago committed by Commit Bot
parent de9e3cabe6
commit dc4d19eeb6

@ -830,6 +830,7 @@ class Settings(object):
self.squash_gerrit_uploads = None
self.gerrit_skip_ensure_authenticated = None
self.git_editor = None
self.format_full_by_default = None
def LazyUpdateIfNeeded(self):
"""Updates the settings from a codereview.settings file, if available."""
@ -938,6 +939,14 @@ class Settings(object):
return (self._GetConfig('rietveld.cpplint-ignore-regex', error_ok=True) or
DEFAULT_LINT_IGNORE_REGEX)
def GetFormatFullByDefault(self):
if self.format_full_by_default is None:
result = (
RunGit(['config', '--bool', 'rietveld.format-full-by-default'],
error_ok=True).strip())
self.format_full_by_default = (result == 'true')
return self.format_full_by_default
def _GetConfig(self, param, **kwargs):
self.LazyUpdateIfNeeded()
return RunGit(['config', param], **kwargs).strip()
@ -3149,6 +3158,8 @@ def LoadCodereviewSettingsFromFile(fileobj):
SetProperty('cpplint-ignore-regex', 'LINT_IGNORE_REGEX', unset_error_ok=True)
SetProperty('run-post-upload-hook', 'RUN_POST_UPLOAD_HOOK',
unset_error_ok=True)
SetProperty(
'format-full-by-default', 'FORMAT_FULL_BY_DEFAULT', unset_error_ok=True)
if 'GERRIT_HOST' in keyvals:
RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']])
@ -5162,7 +5173,7 @@ def CMDformat(parser, args):
except clang_format.NotFoundError as e:
DieWithError(e)
if opts.full:
if opts.full or settings.GetFormatFullByDefault():
cmd = [clang_format_tool]
if not opts.dry_run and not opts.diff:
cmd.append('-i')

@ -724,6 +724,8 @@ class TestGitCl(TestCase):
CERR1),
((['git', 'config', '--unset-all', 'rietveld.run-post-upload-hook'],),
CERR1),
((['git', 'config', '--unset-all', 'rietveld.format-full-by-default'],),
CERR1),
((['git', 'config', 'gerrit.host', 'true'],), ''),
]
self.assertIsNone(git_cl.LoadCodereviewSettingsFromFile(codereview_file))

Loading…
Cancel
Save