Revert "Improve git cl split"
This reverts commit 684096347b67b1663690c118785018258acd2e9b.
Reason for revert:
Breaks git-cl split.
https://bugs.chromium.org/p/chromium/issues/detail?id=1054888
Original change's description:
> Improve git cl split
>
> This CL changes the behavior of `git cl split` to split the change
> by the size of the resulting CLs. For now, this is based on the number
> of bytes changed, and not by the number of changed lines. Depending
> on the shape of change, this may still produce more CLs than expected
> (and possibly more than before).
>
> A future change will switch the split to be based on the number
> of affected lines, and also introduce a mode to base the split
> on the number of affected files.
>
> Bug: 998922
> Change-Id: I49f868972a61b89b426ef9e2ceedc733eacb4350
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1778744
> Commit-Queue: Yannic Bonenberger <yannic.bonenberger@gmail.com>
> Reviewed-by: Dirk Pranke <dpranke@chromium.org>
TBR=fdoray@chromium.org,dpranke@chromium.org,yannic.bonenberger@gmail.com,infra-scoped@luci-project-accounts.iam.gserviceaccount.com
Bug: 998922
Change-Id: I466e1245d5f1c934443d850c48c42d3e694e71c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2080205
Reviewed-by: Anthony Polito <apolito@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
diff --git a/presubmit_support.py b/presubmit_support.py
index cb02fb6..9f02e85 100755
--- a/presubmit_support.py
+++ b/presubmit_support.py
@@ -854,22 +854,6 @@
return scm.GIT.GetOldContents(local_root, path, branch=self._upstream)
-def _ParseDiffHeader(line):
- """Searches |line| for diff headers and returns a tuple
- (header, old_line, old_size, new_line, new_size), or None if line doesn't
- contain a diff header.
-
- This relies on the scm diff output describing each changed code section
- with a line of the form
-
- ^@@ <old line num>,<old size> <new line num>,<new size> @@$
- """
- m = re.match(r'^@@ \-([0-9]+)\,([0-9]+) \+([0-9]+)\,([0-9]+) @@', line)
- if m:
- return (m.group(0), int(m.group(1)), int(m.group(2)), int(m.group(3)),
- int(m.group(4)))
-
-
class AffectedFile(object):
"""Representation of a file in a change."""
@@ -883,7 +867,6 @@
self._local_root = repository_root
self._is_directory = None
self._cached_changed_contents = None
- self._cached_change_size_in_bytes = None
self._cached_new_contents = None
self._diff_cache = diff_cache
logging.debug('%s(%s)', self.__class__.__name__, self._path)
@@ -960,9 +943,9 @@
line_num = 0
for line in self.GenerateScmDiff().splitlines():
- h = _ParseDiffHeader(line)
- if h:
- line_num = h[3]
+ m = re.match(r'^@@ [0-9\,\+\-]+ \+([0-9]+)\,[0-9]+ @@', line)
+ if m:
+ line_num = int(m.groups(1)[0])
continue
if line.startswith('+') and not line.startswith('++'):
self._cached_changed_contents.append((line_num, line[1:]))
@@ -970,25 +953,6 @@
line_num += 1
return self._cached_changed_contents[:]
- def ChangeSizeInBytes(self):
- """Returns a list of tuples (deleted bytes, added bytes) of all changes
- in this file.
-
- This relies on the scm diff output describing each changed code section
- with a line of the form
-
- ^@@ <old line num>,<old size> <new line num>,<new size> @@$
- """
- if self._cached_change_size_in_bytes is not None:
- return self._cached_change_size_in_bytes[:]
- self._cached_change_size_in_bytes = []
-
- for line in self.GenerateScmDiff().splitlines():
- h = _ParseDiffHeader(line)
- if h:
- self._cached_change_size_in_bytes.append((h[2], h[4]))
- return self._cached_change_size_in_bytes[:]
-
def __str__(self):
return self.LocalPath()