Revert "git-cl: Add diff lines of context setting."

This reverts commit 812ac228e3.

Reason for revert: The fix was not sufficient to solve the git cl
format difference between 'git cl format' and 'git cl format --full'.
Looks like we'll need a different solution.

Original change's description:
> git-cl: Add diff lines of context setting.
> 
> Clients using some Clang-Format options can run into bugs when using
> 0 lines of context. AlignConsecutiveAssignments in particular is picky
> and behaves differently with 0 lines of context.
> 
> This behaviour lead to 'git cl format' behaving differently from
> 'git cl format --full'. That could also break presubmit format checks.
> Using >0 lines of context for 'git diff' fixes the inconsistency.
> 
> Add a setting 'DIFF_LINES_OF_CONTEXT' that can be controlled via
> codereview.settings. Defaults to zero to preserve the old behaviour.
> The setting allows the client to control the number of lines of context
> to use when running 'git cl format'.
> 
> Bug: angleproject:4003
> Change-Id: Ied2ebf23df4c41ba19bfbd5b8ddf526b56a20b31
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1864309
> Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
> Commit-Queue: Jamie Madill <jmadill@chromium.org>

TBR=agable@chromium.org,ehmaldonado@chromium.org,jmadill@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: angleproject:4003
Change-Id: Ib6b70969509a1e5446922d488f11d13a0c59c536
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1877003
Reviewed-by: Aaron Gable <agable@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
changes/03/1877003/2
Jamie Madill 6 years ago committed by Commit Bot
parent ad557c41da
commit 3671a6a217

@ -689,8 +689,7 @@ def _ComputeDiffLineRanges(files, upstream_commit):
return {}
# Take the git diff and find the line ranges where there are changes.
lines = '-U%s' % settings.GetDiffLinesOfContext()
diff_cmd = BuildGitDiffCmd(lines, upstream_commit, files, allow_prefix=True)
diff_cmd = BuildGitDiffCmd('-U0', upstream_commit, files, allow_prefix=True)
diff_output = RunGit(diff_cmd)
pattern = r'(?:^diff --git a/(?:.*) b/(.*))|(?:^@@.*\+(.*) @@)'
@ -939,10 +938,6 @@ class Settings(object):
return (self._GetConfig('rietveld.cpplint-ignore-regex', error_ok=True) or
DEFAULT_LINT_IGNORE_REGEX)
def GetDiffLinesOfContext(self):
return (self._GetConfig('rietveld.diff-lines-of-context', error_ok=True) or
"0")
def _GetConfig(self, param, **kwargs):
self.LazyUpdateIfNeeded()
return RunGit(['config', param], **kwargs).strip()
@ -3154,8 +3149,6 @@ 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(
'diff-lines-of-context', 'DIFF_LINES_OF_CONTEXT', unset_error_ok=True)
if 'GERRIT_HOST' in keyvals:
RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']])
@ -5189,8 +5182,7 @@ def CMDformat(parser, args):
if not opts.dry_run and not opts.diff:
cmd.append('-i')
lines = '-U%s' % settings.GetDiffLinesOfContext()
diff_cmd = BuildGitDiffCmd(lines, upstream_commit, clang_diff_files)
diff_cmd = BuildGitDiffCmd('-U0', upstream_commit, clang_diff_files)
diff_output = RunGit(diff_cmd)
stdout = RunCommand(cmd, stdin=diff_output, cwd=top_dir, env=env)

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

Loading…
Cancel
Save