From b6ffdaf3c01127f766ea553f7500d7000f7b2bc8 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Fri, 3 Jun 2011 19:23:16 +0000 Subject: [PATCH] Add support for executables in git-svn patches applied on svn. R=dpranke@chromium.org BUG= TEST= Review URL: http://codereview.chromium.org/7056045 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@87827 0039d316-1c4b-4281-b951-d872f2087c98 --- patch.py | 32 ++++++++++++++++++++------------ tests/patch_test.py | 12 ++++++++++++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/patch.py b/patch.py index bac992d43..c627f48c8 100644 --- a/patch.py +++ b/patch.py @@ -97,7 +97,6 @@ class FilePatchDiff(FilePatchBase): self.patchlevel = 0 if self.is_git_diff: self._verify_git_header() - assert not svn_properties else: self._verify_svn_header() @@ -197,6 +196,7 @@ class FilePatchDiff(FilePatchBase): self._fail('Unexpected git diff; couldn\'t find git header.') # Handle these: + # new file mode \d{6} # rename from <> # rename to <> # copy from <> @@ -204,18 +204,26 @@ class FilePatchDiff(FilePatchBase): while lines: if lines[0].startswith('--- '): break - match = re.match(r'^(rename|copy) from (.+)$', lines.pop(0)) - if not match: + line = lines.pop(0) + match = re.match(r'^(rename|copy) from (.+)$', line) + if match: + if old != match.group(2): + self._fail('Unexpected git diff input name for %s.' % match.group(1)) + if not lines: + self._fail('Missing git diff output name for %s.' % match.group(1)) + match = re.match(r'^(rename|copy) to (.+)$', lines.pop(0)) + if not match: + self._fail('Missing git diff output name for %s.' % match.group(1)) + if new != match.group(2): + self._fail('Unexpected git diff output name for %s.' % match.group(1)) continue - if old != match.group(2): - self._fail('Unexpected git diff input name for %s.' % match.group(1)) - if not lines: - self._fail('Missing git diff output name for %s.' % match.group(1)) - match = re.match(r'^(rename|copy) to (.+)$', lines.pop(0)) - if not match: - self._fail('Missing git diff output name for %s.' % match.group(1)) - if new != match.group(2): - self._fail('Unexpected git diff output name for %s.' % match.group(1)) + + match = re.match(r'^new file mode (\d{6})$', line) + if match: + mode = match.group(1) + # Only look at owner ACL for executable. + if bool(int(mode[4]) & 4): + self.svn_properties.append(('svn:executable', '*')) # Handle ---/+++ while lines: diff --git a/tests/patch_test.py b/tests/patch_test.py index 945d5d5e0..4ca45e7e5 100755 --- a/tests/patch_test.py +++ b/tests/patch_test.py @@ -393,6 +393,18 @@ class PatchTest(unittest.TestCase): p = patch.FilePatchDiff('wtf2', diff, []) self.assertTrue(p) + def testGitExe(self): + diff = ( + 'diff --git a/natsort_test.py b/natsort_test.py\n' + 'new file mode 100755\n' + '--- /dev/null\n' + '+++ b/natsort_test.py\n' + '@@ -0,0 +1,1 @@\n' + '+#!/usr/bin/env python\n') + self.assertEquals( + [('svn:executable', '*')], + patch.FilePatchDiff('natsort_test.py', diff, []).svn_properties) + if __name__ == '__main__': unittest.main()