Changeset 95549 in webkit


Ignore:
Timestamp:
Sep 20, 2011 9:45:34 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

Changelog class should have a method to return all entries
https://bugs.webkit.org/show_bug.cgi?id=68399

Implement ChangeLog.parse_entries_from_file(). This method returns a generator
of ChangeLogEntry objects, ordered from the latest to the oldest entry in the file.

Patch by Leandro Pereira <leandro@profusion.mobi> on 2011-09-20
Reviewed by Ryosuke Niwa.

  • Scripts/webkitpy/common/checkout/changelog.py: Copy parse_latest_entry_from_file()

and adapt it to become a generator.

  • Scripts/webkitpy/common/checkout/changelog_unittest.py: Add test case.
Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r95548 r95549  
     12011-09-20  Leandro Pereira  <leandro@profusion.mobi>
     2
     3        Changelog class should have a method to return all entries
     4        https://bugs.webkit.org/show_bug.cgi?id=68399
     5       
     6        Implement ChangeLog.parse_entries_from_file(). This method returns a generator
     7        of ChangeLogEntry objects, ordered from the latest to the oldest entry in the file.
     8
     9        Reviewed by Ryosuke Niwa.
     10
     11        * Scripts/webkitpy/common/checkout/changelog.py: Copy parse_latest_entry_from_file()
     12        and adapt it to become a generator.
     13        * Scripts/webkitpy/common/checkout/changelog_unittest.py: Add test case.
     14
    1152011-09-20  Jarred Nicholls  <jarred@sencha.com>
    216
  • trunk/Tools/Scripts/webkitpy/common/checkout/changelog.py

    r95547 r95549  
    160160            entry_lines.append(line)
    161161        return None # We never found a date line!
     162
     163    @staticmethod
     164    def parse_entries_from_file(changelog_file):
     165        """changelog_file must be a file-like object which returns
     166        unicode strings.  Use codecs.open or StringIO(unicode())
     167        to pass file objects to this class."""
     168        date_line_regexp = re.compile(ChangeLogEntry.date_line_regexp)
     169        rolled_over_regexp = re.compile(ChangeLogEntry.rolled_over_regexp)
     170        entry_lines = []
     171        # The first line should be a date line.
     172        first_line = changelog_file.readline()
     173        assert(isinstance(first_line, unicode))
     174        if not date_line_regexp.match(first_line):
     175            raise StopIteration
     176        entry_lines.append(first_line)
     177
     178        for line in changelog_file:
     179            if date_line_regexp.match(line) or rolled_over_regexp.match(line):
     180                # Remove the extra newline at the end
     181                yield ChangeLogEntry(''.join(entry_lines[:-1]))
     182                entry_lines = []
     183            entry_lines.append(line)
    162184
    163185    def latest_entry(self):
  • trunk/Tools/Scripts/webkitpy/common/checkout/changelog_unittest.py

    r95547 r95549  
    154154        self.assertEquals(57354, parse_bug_id_from_changelog(commit_text))
    155155
     156    def test_parse_log_entries_from_changelog(self):
     157        parsed_entries = list(ChangeLog.parse_entries_from_changelog(ChangeLogTest._example_changelog))
     158        self.assertEquals(len(parsed_entries), 3)
     159        self.assertEquals(parsed_entries[0].reviewer(), 'David Levin')
     160        self.assertEquals(parsed_entries[1].author_email(), 'ddkilzer@apple.com')
     161        self.assertEquals(parsed_entries[2].touched_files(), ['DumpRenderTree/mac/DumpRenderTreeWindow.mm'])
     162
    156163    def test_latest_entry_parse(self):
    157164        changelog_contents = u"%s\n%s" % (self._example_entry, self._example_changelog)
Note: See TracChangeset for help on using the changeset viewer.