| OLD | NEW |
| 1 # Copyright (C) 2010 Google Inc. All rights reserved. | 1 # Copyright (C) 2010 Google Inc. All rights reserved. |
| 2 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com) | 2 # Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com) |
| 3 # Copyright (C) 2010 ProFUSION embedded systems | 3 # Copyright (C) 2010 ProFUSION embedded systems |
| 4 # | 4 # |
| 5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
| 6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
| 7 # met: | 7 # met: |
| 8 # | 8 # |
| 9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
| 10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | 30 |
| 31 import logging | 31 import logging |
| 32 import re | |
| 33 | 32 |
| 34 from webkitpy.common.checkout.diff_parser import DiffParser | 33 from webkitpy.common.checkout.diff_parser import DiffParser |
| 35 from webkitpy.common.system.filesystem import FileSystem | |
| 36 | 34 |
| 37 | 35 |
| 38 _log = logging.getLogger(__name__) | 36 _log = logging.getLogger(__name__) |
| 39 | 37 |
| 40 | 38 |
| 41 class PatchReader(object): | 39 class PatchReader(object): |
| 42 """Supports checking style in patches.""" | 40 """Supports checking style in patches.""" |
| 43 | 41 |
| 44 def __init__(self, text_file_reader): | 42 def __init__(self, text_file_reader): |
| 45 """Create a PatchReader instance. | 43 """Create a PatchReader instance. |
| 46 | 44 |
| 47 Args: | 45 Args: |
| 48 text_file_reader: A TextFileReader instance. | 46 text_file_reader: A TextFileReader instance. |
| 49 """ | 47 """ |
| 50 self._text_file_reader = text_file_reader | 48 self._text_file_reader = text_file_reader |
| 51 | 49 |
| 52 def check(self, patch_string, fs=None): | 50 def check(self, patch_string): |
| 53 """Check style in the given patch.""" | 51 """Checks style in the given patch.""" |
| 54 fs = fs or FileSystem() | |
| 55 patch_files = DiffParser(patch_string.splitlines()).files | 52 patch_files = DiffParser(patch_string.splitlines()).files |
| 56 | 53 |
| 57 # If the user uses git, checking subversion config file only once is eno
ugh. | |
| 58 # TODO(qyearsley): Simplify this since git is now the only supported SCM
system. | |
| 59 call_only_once = True | |
| 60 | |
| 61 for path, diff_file in patch_files.iteritems(): | 54 for path, diff_file in patch_files.iteritems(): |
| 62 line_numbers = diff_file.added_or_modified_line_numbers() | 55 line_numbers = diff_file.added_or_modified_line_numbers() |
| 63 _log.debug('Found %s new or modified lines in: %s', len(line_numbers
), path) | 56 _log.debug('Found %s new or modified lines in: %s', len(line_numbers
), path) |
| 64 | 57 |
| 65 if not line_numbers: | 58 if not line_numbers: |
| 66 match = re.search(r"\s*png$", path) | |
| 67 if match and fs.exists(path): | |
| 68 if call_only_once: | |
| 69 self._text_file_reader.process_file(file_path=path, line
_numbers=None) | |
| 70 call_only_once = False | |
| 71 continue | |
| 72 # Don't check files which contain only deleted lines | 59 # Don't check files which contain only deleted lines |
| 73 # as they can never add style errors. However, mark them as | 60 # as they can never add style errors. However, mark them as |
| 74 # processed so that we count up number of such files. | 61 # processed so that we count up number of such files. |
| 75 self._text_file_reader.count_delete_only_file() | 62 self._text_file_reader.count_delete_only_file() |
| 76 continue | 63 continue |
| 77 | 64 |
| 78 self._text_file_reader.process_file(file_path=path, line_numbers=lin
e_numbers) | 65 self._text_file_reader.process_file(file_path=path, line_numbers=lin
e_numbers) |
| OLD | NEW |