| OLD | NEW |
| 1 # Copyright (C) 2009 Google Inc. All rights reserved. | 1 # Copyright (C) 2009 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 """WebKit's Python module for interacting with patches.""" | 29 """WebKit's Python module for interacting with patches.""" |
| 30 | 30 |
| 31 import logging | 31 import logging |
| 32 import re | 32 import re |
| 33 | 33 |
| 34 _log = logging.getLogger(__name__) | 34 _log = logging.getLogger(__name__) |
| 35 | 35 |
| 36 conversion_patterns = ( | 36 conversion_patterns = ( |
| 37 (re.compile("^diff --git \w/(.+) \w/(?P<FilePath>.+)"), lambda matched: "Ind
ex: " + matched.group('FilePath') + "\n"), | 37 (re.compile(r"^diff --git \w/(.+) \w/(?P<FilePath>.+)"), lambda matched: "In
dex: " + matched.group('FilePath') + "\n"), |
| 38 (re.compile("^new file.*"), lambda matched: "\n"), | 38 (re.compile(r"^new file.*"), lambda matched: "\n"), |
| 39 (re.compile("^index (([0-9a-f]{7}\.\.[0-9a-f]{7})|([0-9a-f]{40}\.\.[0-9a-f]{
40})) [0-9]{6}"), | 39 (re.compile(r"^index (([0-9a-f]{7}\.\.[0-9a-f]{7})|([0-9a-f]{40}\.\.[0-9a-f]
{40})) [0-9]{6}"), |
| 40 lambda matched: ("=" * 67) + "\n"), | 40 lambda matched: ("=" * 67) + "\n"), |
| 41 (re.compile("^--- \w/(?P<FilePath>.+)"), lambda matched: "--- " + matched.gr
oup('FilePath') + "\n"), | 41 (re.compile(r"^--- \w/(?P<FilePath>.+)"), lambda matched: "--- " + matched.g
roup('FilePath') + "\n"), |
| 42 (re.compile("^\+\+\+ \w/(?P<FilePath>.+)"), lambda matched: "+++ " + matched
.group('FilePath') + "\n"), | 42 (re.compile(r"^\+\+\+ \w/(?P<FilePath>.+)"), lambda matched: "+++ " + matche
d.group('FilePath') + "\n"), |
| 43 ) | 43 ) |
| 44 | 44 |
| 45 index_pattern = re.compile(r"^Index: (?P<FilePath>.+)") | 45 index_pattern = re.compile(r"^Index: (?P<FilePath>.+)") |
| 46 lines_changed_pattern = re.compile(r"^@@ -(?P<OldStartLine>\d+)(,\d+)? \+(?P<New
StartLine>\d+)(,\d+)? @@") | 46 lines_changed_pattern = re.compile(r"^@@ -(?P<OldStartLine>\d+)(,\d+)? \+(?P<New
StartLine>\d+)(,\d+)? @@") |
| 47 diff_git_pattern = re.compile(r"^diff --git \w/") | 47 diff_git_pattern = re.compile(r"^diff --git \w/") |
| 48 | 48 |
| 49 | 49 |
| 50 def git_diff_to_svn_diff(line): | 50 def git_diff_to_svn_diff(line): |
| 51 """Converts a git formatted diff line to a svn formatted line. | 51 """Converts a git formatted diff line to a svn formatted line. |
| 52 | 52 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 elif line.startswith(' '): | 172 elif line.startswith(' '): |
| 173 current_file.add_unchanged_line(old_diff_line, new_diff_line
, line[1:]) | 173 current_file.add_unchanged_line(old_diff_line, new_diff_line
, line[1:]) |
| 174 old_diff_line += 1 | 174 old_diff_line += 1 |
| 175 new_diff_line += 1 | 175 new_diff_line += 1 |
| 176 elif line == '\\ No newline at end of file': | 176 elif line == '\\ No newline at end of file': |
| 177 # Nothing to do. We may still have some added lines. | 177 # Nothing to do. We may still have some added lines. |
| 178 pass | 178 pass |
| 179 else: | 179 else: |
| 180 _log.error('Unexpected diff format when parsing a chunk: %r'
, line) | 180 _log.error('Unexpected diff format when parsing a chunk: %r'
, line) |
| 181 return files | 181 return files |
| OLD | NEW |