Commit 68409634 authored by Yannic Bonenberger's avatar Yannic Bonenberger Committed by LUCI CQ

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: 's avatarDirk Pranke <dpranke@chromium.org>
parent bdd89366
......@@ -4530,8 +4530,10 @@ def CMDsplit(parser, args):
Creates a branch and uploads a CL for each group of files modified in the
current branch that share a common OWNERS file. In the CL description and
comment, the string '$directory', is replaced with the directory containing
the shared OWNERS file.
comment, '$directory' is replaced with the directory containing the changes
in this CL, '$cl_index' is replaced with the index of the CL we're currently
sending out, and '$num_cls' is replaced with the total number of CLs that
we're sending out in this split.
"""
parser.add_option('-d', '--description', dest='description_file',
help='A text file containing a CL description in which '
......
......@@ -880,6 +880,22 @@ class _GitDiffCache(_DiffCache):
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."""
......@@ -893,6 +909,7 @@ class AffectedFile(object):
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)
......@@ -969,9 +986,9 @@ class AffectedFile(object):
line_num = 0
for line in self.GenerateScmDiff().splitlines():
m = re.match(r'^@@ [0-9\,\+\-]+ \+([0-9]+)\,[0-9]+ @@', line)
if m:
line_num = int(m.groups(1)[0])
h = _ParseDiffHeader(line)
if h:
line_num = h[3]
continue
if line.startswith('+') and not line.startswith('++'):
self._cached_changed_contents.append((line_num, line[1:]))
......@@ -979,6 +996,25 @@ class AffectedFile(object):
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()
......
This diff is collapsed.
This diff is collapsed.
URL: https://github.com/google/pygtrie
Version: 64ee0836f41a59919ecf8a59b0c7e2f7f1b8c5ba
License: Apache 2.0
License File: LICENSE
Description:
This directory contains the Python pygtrie module.
Local Modifications:
None
This diff is collapsed.
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