Commit dc4d19ee authored by Jamie Madill's avatar Jamie Madill Committed by Commit Bot

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/+/1879148Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent de9e3cab
...@@ -830,6 +830,7 @@ class Settings(object): ...@@ -830,6 +830,7 @@ class Settings(object):
self.squash_gerrit_uploads = None self.squash_gerrit_uploads = None
self.gerrit_skip_ensure_authenticated = None self.gerrit_skip_ensure_authenticated = None
self.git_editor = None self.git_editor = None
self.format_full_by_default = None
def LazyUpdateIfNeeded(self): def LazyUpdateIfNeeded(self):
"""Updates the settings from a codereview.settings file, if available.""" """Updates the settings from a codereview.settings file, if available."""
...@@ -938,6 +939,14 @@ class Settings(object): ...@@ -938,6 +939,14 @@ class Settings(object):
return (self._GetConfig('rietveld.cpplint-ignore-regex', error_ok=True) or return (self._GetConfig('rietveld.cpplint-ignore-regex', error_ok=True) or
DEFAULT_LINT_IGNORE_REGEX) 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): def _GetConfig(self, param, **kwargs):
self.LazyUpdateIfNeeded() self.LazyUpdateIfNeeded()
return RunGit(['config', param], **kwargs).strip() return RunGit(['config', param], **kwargs).strip()
...@@ -3149,6 +3158,8 @@ def LoadCodereviewSettingsFromFile(fileobj): ...@@ -3149,6 +3158,8 @@ def LoadCodereviewSettingsFromFile(fileobj):
SetProperty('cpplint-ignore-regex', 'LINT_IGNORE_REGEX', unset_error_ok=True) SetProperty('cpplint-ignore-regex', 'LINT_IGNORE_REGEX', unset_error_ok=True)
SetProperty('run-post-upload-hook', 'RUN_POST_UPLOAD_HOOK', SetProperty('run-post-upload-hook', 'RUN_POST_UPLOAD_HOOK',
unset_error_ok=True) unset_error_ok=True)
SetProperty(
'format-full-by-default', 'FORMAT_FULL_BY_DEFAULT', unset_error_ok=True)
if 'GERRIT_HOST' in keyvals: if 'GERRIT_HOST' in keyvals:
RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']]) RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']])
...@@ -5162,7 +5173,7 @@ def CMDformat(parser, args): ...@@ -5162,7 +5173,7 @@ def CMDformat(parser, args):
except clang_format.NotFoundError as e: except clang_format.NotFoundError as e:
DieWithError(e) DieWithError(e)
if opts.full: if opts.full or settings.GetFormatFullByDefault():
cmd = [clang_format_tool] cmd = [clang_format_tool]
if not opts.dry_run and not opts.diff: if not opts.dry_run and not opts.diff:
cmd.append('-i') cmd.append('-i')
......
...@@ -724,6 +724,8 @@ class TestGitCl(TestCase): ...@@ -724,6 +724,8 @@ class TestGitCl(TestCase):
CERR1), CERR1),
((['git', 'config', '--unset-all', 'rietveld.run-post-upload-hook'],), ((['git', 'config', '--unset-all', 'rietveld.run-post-upload-hook'],),
CERR1), CERR1),
((['git', 'config', '--unset-all', 'rietveld.format-full-by-default'],),
CERR1),
((['git', 'config', 'gerrit.host', 'true'],), ''), ((['git', 'config', 'gerrit.host', 'true'],), ''),
] ]
self.assertIsNone(git_cl.LoadCodereviewSettingsFromFile(codereview_file)) self.assertIsNone(git_cl.LoadCodereviewSettingsFromFile(codereview_file))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment