Fix for single line file modification

When a file contains a single line of text, svn diff will generate an odd hunk
header. Modify the hunk parsing code to accept this format.

R=dpranke@chromium.org
BUG=
TEST=


Review URL: http://codereview.chromium.org/9147056

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@117143 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
maruel@chromium.org 14 years ago
parent 9799a079c5
commit db1fd78fcb

@ -219,19 +219,24 @@ class FilePatchDiff(FilePatchBase):
hunks = []
for line in self.diff_hunks.splitlines(True):
if line.startswith('@@'):
match = re.match(r'^@@ -(\d+),(\d+) \+([\d,]+) @@.*$', line)
match = re.match(r'^@@ -([\d,]+) \+([\d,]+) @@.*$', line)
# File add will result in "-0,0 +1" but file deletion will result in
# "-1,N +0,0" where N is the number of lines deleted. That's from diff
# and svn diff. git diff doesn't exhibit this behavior.
# svn diff for a single line file rewrite "@@ -1 +1 @@". Fun.
if not match:
self._fail('Hunk header is unparsable')
if ',' in match.group(3):
start_dst, lines_dst = map(int, match.group(3).split(',', 1))
if ',' in match.group(1):
start_src, lines_src = map(int, match.group(1).split(',', 1))
else:
start_dst = int(match.group(3))
start_src = int(match.group(1))
lines_src = 0
if ',' in match.group(2):
start_dst, lines_dst = map(int, match.group(2).split(',', 1))
else:
start_dst = int(match.group(2))
lines_dst = 0
new_hunk = Hunk(int(match.group(1)), int(match.group(2)),
start_dst, lines_dst)
new_hunk = Hunk(start_src, lines_src, start_dst, lines_dst)
if hunks:
if new_hunk.start_src <= hunks[-1].start_src:
self._fail('Hunks source lines are not ordered')

@ -112,6 +112,17 @@ class RAW(object):
' <!-- Browser Hung Plugin Detector -->\n'
' <message name="IDS_UNKNOWN_PLUGIN_NAME" ...\n')
# http://codereview.chromium.org/download/issue9091003_9005_8009.diff
DIFFERENT = (
'Index: master/unittests/data/processes-summary.dat\n'
'===================================================================\n'
'--- master/unittests/data/processes-summary.dat\t(revision 116240)\n'
'+++ master/unittests/data/processes-summary.dat\t(working copy)\n'
'@@ -1 +1 @@\n'
'-{"traces": {"1t_proc": ["2.0", "0.0"], "1t_proc_ref": ["1.0", ...\n'
'+{"traces": {"1t_proc": ["2.0", "0.0"], "1t_proc_ref": ["1.0", ...\n')
class GIT(object):
"""Sample patches generated by git diff."""
PATCH = (

@ -71,6 +71,11 @@ class PatchTest(unittest.TestCase):
p = patch.FilePatchDiff('chrome/file.cc', RAW.PATCH, [])
self._check_patch(p, 'chrome/file.cc', RAW.PATCH, nb_hunks=1)
def testDifferent(self):
name = 'master/unittests/data/processes-summary.dat'
p = patch.FilePatchDiff(name, RAW.DIFFERENT, [])
self._check_patch(p, name, RAW.DIFFERENT, nb_hunks=1)
def testFilePatchDiffHeaderMode(self):
p = patch.FilePatchDiff('git_cl/git-cl', GIT.MODE_EXE, [])
self._check_patch(

Loading…
Cancel
Save