Beispiel #1
0
    def check(self, patch_string, fs=None):
        """Check style in the given patch."""
        fs = fs or FileSystem()
        patch_files = DiffParser(patch_string.splitlines()).files

        # If the user uses git, checking subversion config file only once is enough.
        call_only_once = True

        for path, diff_file in patch_files.iteritems():
            line_numbers = diff_file.added_or_modified_line_numbers()
            _log.debug('Found %s new or modified lines in: %s' %
                       (len(line_numbers), path))

            if not line_numbers:
                match = re.search("\s*png$", path)
                if match and fs.exists(path):
                    if call_only_once:
                        self._text_file_reader.process_file(file_path=path,
                                                            line_numbers=None)
                        cwd = FileSystem().getcwd()
                        detection = SCMDetector(
                            fs, Executive()).detect_scm_system(cwd)
                        if detection.display_name() == "git":
                            call_only_once = False
                    continue
                # Don't check files which contain only deleted lines
                # as they can never add style errors. However, mark them as
                # processed so that we count up number of such files.
                self._text_file_reader.delete_file(path)
                continue

            self._text_file_reader.process_file(file_path=path,
                                                line_numbers=line_numbers)
        self._text_file_reader.do_association_check(fs.getcwd())
Beispiel #2
0
    def check(self, patch_string):
        """Check style in the given patch."""
        patch_files = DiffParser(patch_string.splitlines()).files

        # The diff variable is a DiffFile instance.
        for path, diff in patch_files.iteritems():
            line_numbers = set()
            for line in diff.lines:
                # When deleted line is not set, it means that
                # the line is newly added (or modified).
                if not line[0]:
                    line_numbers.add(line[1])

            _log.debug('Found %s new or modified lines in: %s'
                       % (len(line_numbers), path))

            # If line_numbers is empty, the file has no new or
            # modified lines.  In this case, we don't check the file
            # because we'll never output errors for the file.
            # This optimization also prevents the program from exiting
            # due to a deleted file.
            if line_numbers:
                self._text_file_reader.process_file(file_path=path,
                                                    line_numbers=line_numbers)
            else:
                # We don't check the file which contains deleted lines only
                # but would like to treat it as to be processed so that
                # we count up number of such files.
                self._text_file_reader.count_delete_only_file()
    def check(self, patch_string, fs=None):
        """Check style in the given patch."""
        fs = fs or FileSystem()
        patch_files = DiffParser(patch_string.splitlines()).files

        # If the user uses git, checking subversion config file only once is enough.
        call_only_once = True

        for path, diff_file in patch_files.iteritems():
            line_numbers = diff_file.added_or_modified_line_numbers()
            _log.debug('Found %s new or modified lines in: %s' % (len(line_numbers), path))

            if not line_numbers:
                match = re.search("\s*png$", path)
                if match and fs.exists(path):
                    if call_only_once:
                        self._text_file_reader.process_file(file_path=path, line_numbers=None)
                        cwd = FileSystem().getcwd()
                        detection = SCMDetector(fs, Executive()).detect_scm_system(cwd)
                        if detection.display_name() == "git":
                            call_only_once = False
                    continue
                # Don't check files which contain only deleted lines
                # as they can never add style errors. However, mark them as
                # processed so that we count up number of such files.
                self._text_file_reader.count_delete_only_file()
                continue

            self._text_file_reader.process_file(file_path=path, line_numbers=line_numbers)
Beispiel #4
0
    def check(self, patch_string, fs=None):
        """Check style in the given patch."""
        fs = fs or FileSystem()
        patch_files = DiffParser(patch_string.splitlines()).files

        # If the user uses git, checking subversion config file only once is enough.
        # TODO(qyearsley): Simplify this since git is now the only supported SCM system.
        call_only_once = True

        for path, diff_file in patch_files.iteritems():
            line_numbers = diff_file.added_or_modified_line_numbers()
            _log.debug('Found %s new or modified lines in: %s',
                       len(line_numbers), path)

            if not line_numbers:
                match = re.search(r"\s*png$", path)
                if match and fs.exists(path):
                    if call_only_once:
                        self._text_file_reader.process_file(file_path=path,
                                                            line_numbers=None)
                        call_only_once = False
                    continue
                # Don't check files which contain only deleted lines
                # as they can never add style errors. However, mark them as
                # processed so that we count up number of such files.
                self._text_file_reader.count_delete_only_file()
                continue

            self._text_file_reader.process_file(file_path=path,
                                                line_numbers=line_numbers)
Beispiel #5
0
    def check(self, patch_string):
        """Check style in the given patch."""
        patch_files = DiffParser(patch_string.splitlines()).files

        # The diff variable is a DiffFile instance.
        for path, diff in patch_files.iteritems():
            line_numbers = set()
            for line in diff.lines:
                # When deleted line is not set, it means that
                # the line is newly added (or modified).
                if not line[0]:
                    line_numbers.add(line[1])

            _log.debug('Found %s new or modified lines in: %s'
                       % (len(line_numbers), path))

            # If line_numbers is empty, the file has no new or
            # modified lines.  In this case, we don't check the file
            # because we'll never output errors for the file.
            # This optimization also prevents the program from exiting
            # due to a deleted file.
            if line_numbers:
                self._text_file_reader.process_file(file_path=path,
                                                    line_numbers=line_numbers)
            else:
                # We don't check the file which contains deleted lines only
                # but would like to treat it as to be processed so that
                # we count up number of such files.
                self._text_file_reader.count_delete_only_file()
Beispiel #6
0
 def run(self, state):
     changed_files = self.cached_lookup(state, "changed_files")
     for filename in changed_files:
         if not self._tool.checkout().is_path_to_changelog(filename):
             continue
         # Diff ChangeLogs directly because svn-create-patch will move
         # ChangeLog entries to the # top automatically, defeating our
         # validation here.
         # FIXME: Should we diff all the ChangeLogs at once?
         diff = self._tool.scm().diff_for_file(filename)
         parsed_diff = DiffParser(diff.splitlines())
         for filename, diff_file in parsed_diff.files.items():
             if not self._tool.checkout().is_path_to_changelog(
                     diff_file.filename):
                 continue
             if not self._check_changelog_diff(diff_file):
                 _log.error(
                     "ChangeLog entry in %s is not at the top of the file."
                     % diff_file.filename)
                 sys.exit(1)
             if self._options.check_oops and self._changelog_contains_oops(
                     diff_file):
                 _log.error("ChangeLog entry in %s contains OOPS!." %
                            diff_file.filename)
                 sys.exit(1)
Beispiel #7
0
    def check(self, patch_string):
        """Check style in the given patch."""
        patch_files = DiffParser(patch_string.splitlines()).files

        for path, diff_file in patch_files.iteritems():
            line_numbers = diff_file.added_or_modified_line_numbers()
            _log.debug('Found %s new or modified lines in: %s' % (len(line_numbers), path))

            if not line_numbers:
                # Don't check files which contain only deleted lines
                # as they can never add style errors. However, mark them as
                # processed so that we count up number of such files.
                self._text_file_reader.count_delete_only_file()
                continue

            self._text_file_reader.process_file(file_path=path, line_numbers=line_numbers)
 def run(self, state):
     parsed_diff = DiffParser(
         self.cached_lookup(state, "diff").splitlines())
     for filename, diff_file in parsed_diff.files.items():
         if not self._check_changelog_diff(diff_file):
             error("ChangeLog entry in %s is not at the top of the file." %
                   diff_file.filename)
    def find_matching_definitions(self, diff):
        matching_definitions = set()
        patch_files = DiffParser(diff.splitlines()).files

        for path, diff_file in patch_files.iteritems():
            for definition in self.definitions:
                # If a definition has already matched, there is no need to process it.
                if definition in matching_definitions:
                    continue

                # See if the definition matches within one file.
                for pattern in self.definitions[definition]:
                    if not pattern.match(path, diff_file.lines):
                        break
                else:
                    matching_definitions.add(definition)
        return matching_definitions
Beispiel #10
0
    def find_matching_definitions(self, diff):
        matching_definitions = set()
        patch_files = DiffParser(diff.splitlines()).files

        for path, diff_file in patch_files.items():
            for definition in self.definitions:
                # If a definition has already matched, there is no need to process it.
                if definition in matching_definitions:
                    continue

                # See if the definition matches within one file.
                for pattern in self.definitions[definition]:
                    if not pattern.match(path, diff_file.lines):
                        break
                else:
                    matching_definitions.add(definition)
        return matching_definitions
Beispiel #11
0
    def check(self, patch_string):
        """Check style in the given patch."""
        patch_files = DiffParser(patch_string.splitlines()).files

        for path, diff_file in patch_files.iteritems():
            line_numbers = diff_file.added_or_modified_line_numbers()
            _log.debug('Found %s new or modified lines in: %s' %
                       (len(line_numbers), path))

            if not line_numbers:
                # Don't check files which contain only deleted lines
                # as they can never add style errors. However, mark them as
                # processed so that we count up number of such files.
                self._text_file_reader.count_delete_only_file()
                continue

            self._text_file_reader.process_file(file_path=path,
                                                line_numbers=line_numbers)
    def test_diff_parser(self, parser=None):
        if not parser:
            parser = DiffParser(DIFF_TEST_DATA.splitlines())
        self.assertEqual(3, len(parser.files))

        self.assertIn('WebCore/style/StyleFlexibleBoxData.h', parser.files)
        diff = parser.files['WebCore/style/StyleFlexibleBoxData.h']
        self.assertEqual(7, len(diff.lines))

        # The first two unchanged lines.
        self.assertEqual((47, 47), diff.lines[0][0:2])
        self.assertEqual('', diff.lines[0][2])
        self.assertEqual((48, 48), diff.lines[1][0:2])
        self.assertEqual('    unsigned align : 3; // EBoxAlignment',
                         diff.lines[1][2])

        # The deleted line.
        self.assertEqual((50, 0), diff.lines[3][0:2])
        self.assertEqual('    unsigned orient: 1; // EBoxOrient',
                         diff.lines[3][2])

        # The first file looks OK. Let's check the next, more complicated file.
        self.assertIn('WebCore/style/StyleRareInheritedData.cpp', parser.files)
        diff = parser.files['WebCore/style/StyleRareInheritedData.cpp']

        # There are 3 chunks.
        self.assertEqual(7 + 7 + 9, len(diff.lines))

        # Around an added line.
        self.assertEqual((60, 61), diff.lines[9][0:2])
        self.assertEqual((0, 62), diff.lines[10][0:2])
        self.assertEqual((61, 63), diff.lines[11][0:2])

        # Look through the last chunk, which contains both adds and deletes.
        self.assertEqual((81, 83), diff.lines[14][0:2])
        self.assertEqual((82, 84), diff.lines[15][0:2])
        self.assertEqual((83, 85), diff.lines[16][0:2])
        self.assertEqual((84, 0), diff.lines[17][0:2])
        self.assertEqual((0, 86), diff.lines[18][0:2])
        self.assertEqual((0, 87), diff.lines[19][0:2])
        self.assertEqual((85, 88), diff.lines[20][0:2])
        self.assertEqual((86, 89), diff.lines[21][0:2])
        self.assertEqual((87, 90), diff.lines[22][0:2])

        # Check if a newly added file is correctly handled.
        diff = parser.files[
            'LayoutTests/platform/mac/fast/flexbox/box-orient-button-expected.checksum']
        self.assertEqual(1, len(diff.lines))
        self.assertEqual((0, 1), diff.lines[0][0:2])
 def test_diff_parser_with_different_mnemonic_prefixes(self):
     # This repeats test_diff_parser but with different versions
     # of DIFF_TEST_DATA that use other prefixes instead of a/b.
     prefixes = (
         ('i', 'w'),  # git-diff (compares the (i)ndex and the (w)ork tree)
         ('c',
          'w'),  # git-diff HEAD (compares a (c)ommit and the (w)ork tree)
         ('c',
          'i'),  # git diff --cached (compares a (c)ommit and the (i)ndex)
         (
             'o', 'w'
         ),  # git-diff HEAD:file1 file2 (compares an (o)bject and a (w)ork tree entity)
         (
             '1', '2'
         ),  # git diff --no-index a b (compares two non-git things (1) and (2))
     )
     for a_replacement, b_replacement in prefixes:
         patch = self._patch(a_replacement, b_replacement)
         self.test_diff_parser(DiffParser(patch.splitlines()))
Beispiel #14
0
def parse_patch(patch_string):
    """Parse a patch string and return the affected files."""

    patch = DiffParser(patch_string.splitlines())
    return patch.files