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>
diff --git a/git_cl.py b/git_cl.py
index 72bc192..b2eef88 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -830,6 +830,7 @@
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 @@
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 @@
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 @@
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')