Commit 087066c5 authored by maruel@chromium.org's avatar maruel@chromium.org

Make the rietveld client code ignore file status more often.

It's proved to be unreliable.

R=dpranke@chromium.org
BUG=
TEST=


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@100236 0039d316-1c4b-4281-b951-d872f2087c98
parent 57bf78d8
...@@ -121,53 +121,49 @@ class Rietveld(object): ...@@ -121,53 +121,49 @@ class Rietveld(object):
for filename, state in props.get('files', {}).iteritems(): for filename, state in props.get('files', {}).iteritems():
logging.debug('%s' % filename) logging.debug('%s' % filename)
status = state.get('status') status = state.get('status')
if status is None: if not status:
raise patch.UnsupportedPatchFormat( raise patch.UnsupportedPatchFormat(
filename, 'File\'s status is None, patchset upload is incomplete.') filename, 'File\'s status is None, patchset upload is incomplete.')
if status[0] not in ('A', 'D', 'M'):
raise patch.UnsupportedPatchFormat(
filename, 'Change with status \'%s\' is not supported.' % status)
if status[0] == 'D': svn_props = self.parse_svn_properties(
if status[0] != status.strip(): state.get('property_changes', ''), filename)
raise patch.UnsupportedPatchFormat(
filename, 'Deleted file shouldn\'t have property change.') if state.get('is_binary'):
# Ignore the diff. if status[0] == 'D':
out.append(patch.FilePatchDelete(filename, state['is_binary'])) if status[0] != status.strip():
elif status[0] in ('A', 'M'): raise patch.UnsupportedPatchFormat(
svn_props = self.parse_svn_properties( filename, 'Deleted file shouldn\'t have property change.')
state.get('property_changes', ''), filename) out.append(patch.FilePatchDelete(filename, state['is_binary']))
if state['is_binary']: else:
out.append(patch.FilePatchBinary( out.append(patch.FilePatchBinary(
filename, filename,
self.get_file_content(issue, patchset, state['id']), self.get_file_content(issue, patchset, state['id']),
svn_props, svn_props,
is_new=(status[0] == 'A'))) is_new=(status[0] == 'A')))
else: continue
# Ignores num_chunks since it may only contain an header.
diff = None try:
try: diff = self.get_file_diff(issue, patchset, state['id'])
diff = self.get_file_diff(issue, patchset, state['id']) except urllib2.HTTPError, e:
except urllib2.HTTPError, e: if e.code == 404:
if e.code == 404: raise patch.UnsupportedPatchFormat(
raise patch.UnsupportedPatchFormat( filename, 'File doesn\'t have a diff.')
filename, 'File doesn\'t have a diff.') raise
raise
# It may happen on property-only change or svn copy without diff. # FilePatchDiff() will detect file deletion automatically.
if not diff: p = patch.FilePatchDiff(filename, diff, svn_props)
# Support this use case if it ever happen. out.append(p)
raise patch.UnsupportedPatchFormat( if status[0] == 'A':
filename, 'Empty diff is not supported yet.\n') # It won't be set for empty file.
p = patch.FilePatchDiff(filename, diff, svn_props) p.is_new = True
out.append(p) if (len(status) > 1 and
if status[0] == 'A': status[1] == '+' and
# It won't be set for empty file. not (p.source_filename or p.svn_properties)):
p.is_new = True
if (len(status) > 1 and
status[1] == '+' and
not (p.source_filename or p.svn_properties)):
raise patch.UnsupportedPatchFormat(
filename, 'Failed to process the svn properties')
else:
raise patch.UnsupportedPatchFormat( raise patch.UnsupportedPatchFormat(
filename, 'Change with status \'%s\' is not supported.' % status) filename, 'Failed to process the svn properties')
return patch.PatchSet(out) return patch.PatchSet(out)
......
...@@ -180,12 +180,14 @@ class RietveldTest(unittest.TestCase): ...@@ -180,12 +180,14 @@ class RietveldTest(unittest.TestCase):
is_new=True) is_new=True)
def test_delete(self): def test_delete(self):
name = 'tools/clang_check/README.chromium'
self.requests = [ self.requests = [
('/api/123/456', _api({'file_a': _file('D')})), ('/api/123/456', _api({name: _file('D')})),
('/download/issue123_456_789.diff', RAW.DELETE),
] ]
patches = self.rietveld.get_patch(123, 456) patches = self.rietveld.get_patch(123, 456)
self.assertEquals(1, len(patches.patches)) self.assertEquals(1, len(patches.patches))
self._check_patch(patches.patches[0], 'file_a', None, is_delete=True) self._check_patch(patches.patches[0], name, None, is_delete=True)
def test_m_plus(self): def test_m_plus(self):
properties = '\nAdded: svn:eol-style\n + LF\n' properties = '\nAdded: svn:eol-style\n + LF\n'
......
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