2011-03-29 David Levin <levin@chromium.org>
[WebKit-https.git] / Tools / Scripts / webkitpy / style / checkers / changelog.py
index be279a7..75754fa 100644 (file)
@@ -34,12 +34,15 @@ class ChangeLogChecker(object):
 
     """Processes text lines for checking style."""
 
-    def __init__(self, file_path, handle_style_error):
+    def __init__(self, file_path, handle_style_error, should_line_be_checked):
         self.file_path = file_path
         self.handle_style_error = handle_style_error
+        self.should_line_be_checked = should_line_be_checked
         self._tab_checker = TabChecker(file_path, handle_style_error)
 
-    def check_entry(self, entry_line_number, entry_lines):
+    def check_entry(self, first_line_checked, entry_lines):
+        if not entry_lines:
+            return
         for line in entry_lines:
             if parse_bug_id_from_changelog(line):
                 break
@@ -48,26 +51,24 @@ class ChangeLogChecker(object):
             if re.search("build", line, re.IGNORECASE) and re.search("fix", line, re.IGNORECASE):
                 break
         else:
-            self.handle_style_error(entry_line_number + 1,
+            self.handle_style_error(first_line_checked,
                                     "changelog/bugnumber", 5,
                                     "ChangeLog entry has no bug number")
 
     def check(self, lines):
         self._tab_checker.check(lines)
-        entry_line_number = 0
+        first_line_checked = 0
         entry_lines = []
-        started_at_first_line = False
-
-        for line_number, line in enumerate(lines):
-            if re.match("^\d{4}-\d{2}-\d{2}", line):
-                if line_number:
-                    self.check_entry(entry_line_number, entry_lines)
-                else:
-                    started_at_first_line = True
-                entry_line_number = line_number
-                entry_lines = []
 
+        for line_index, line in enumerate(lines):
+            if not self.should_line_be_checked(line_index + 1):
+                # If we transitioned from finding changed lines to
+                # unchanged lines, then we are done.
+                if first_line_checked:
+                    break
+                continue
+            if not first_line_checked:
+                first_line_checked = line_index + 1
             entry_lines.append(line)
 
-        if started_at_first_line:
-            self.check_entry(entry_line_number, entry_lines)
+        self.check_entry(first_line_checked, entry_lines)