From 264952ad00cb0ddb271094d9fc49017b96e8a138 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Tue, 1 May 2012 18:32:47 +0000 Subject: [PATCH] There is no reason to not assume that status:null isn't 'M'. Rietveld self-corrupts its status all the time, there is not point in bailing just because of that. So just assume it's an 'M' and it'll work fine. In any case, the diff is properly parsed to detect what was the real operation. Add unit test that correctly process a deleted file with status:null. TBR=nsylvain@chromium.org BUG= TEST=A corrupted patchset can still be committed with the Commit Queue. Review URL: http://codereview.chromium.org/10272024 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@134733 0039d316-1c4b-4281-b951-d872f2087c98 --- rietveld.py | 7 +++---- tests/rietveld_test.py | 23 +++++++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/rietveld.py b/rietveld.py index 6fc5796323..70c64441fc 100644 --- a/rietveld.py +++ b/rietveld.py @@ -109,10 +109,9 @@ class Rietveld(object): out = [] for filename, state in props.get('files', {}).iteritems(): logging.debug('%s' % filename) - status = state.get('status') - if not status: - raise patch.UnsupportedPatchFormat( - filename, 'File\'s status is None, patchset upload is incomplete.') + # If not status, just assume it's a 'M'. Rietveld often gets it wrong and + # just has status: null. Oh well. + status = state.get('status') or 'M' if status[0] not in ('A', 'D', 'M'): raise patch.UnsupportedPatchFormat( filename, 'Change with status \'%s\' is not supported.' % status) diff --git a/tests/rietveld_test.py b/tests/rietveld_test.py index 70bb320bd7..582361b7bd 100755 --- a/tests/rietveld_test.py +++ b/tests/rietveld_test.py @@ -88,12 +88,23 @@ class RietveldTest(unittest.TestCase): self.assertEquals(p.svn_properties, svn_properties) def test_get_patch_no_status(self): - self.requests = [('/api/123/456', _api({'file_a': {}}))] - try: - self.rietveld.get_patch(123, 456) - self.fail() - except patch.UnsupportedPatchFormat, e: - self.assertEquals('file_a', e.filename) + self.requests = [ + ( '/api/123/456', + _api( + { + 'tools/clang_check/README.chromium': { + 'status': None, + 'id': 789, + }})), + ('/download/issue123_456_789.diff', RAW.DELETE), + ] + patches = self.rietveld.get_patch(123, 456) + self.assertEquals(1, len(patches.patches)) + self._check_patch( + patches.patches[0], + 'tools/clang_check/README.chromium', + RAW.DELETE, + is_delete=True) def test_get_patch_2_files(self): self.requests = [