<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[69744] trunk/WebKitTools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/69744">69744</a></dd>
<dt>Author</dt> <dd>eric@webkit.org</dd>
<dt>Date</dt> <dd>2010-10-13 23:55:51 -0700 (Wed, 13 Oct 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>2010-10-13  Eric Seidel  &lt;eric@webkit.org&gt;

        Reviewed by Adam Barth.

        beat diff_parser with the ugly stick
        https://bugs.webkit.org/show_bug.cgi?id=47626

        * Scripts/webkitpy/common/checkout/diff_parser.py:
        * Scripts/webkitpy/style/patchreader.py:
        * Scripts/webkitpy/style/patchreader_unittest.py:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebKitToolsChangeLog">trunk/WebKitTools/ChangeLog</a></li>
<li><a href="#trunkWebKitToolsScriptswebkitpycommoncheckoutdiff_parserpy">trunk/WebKitTools/Scripts/webkitpy/common/checkout/diff_parser.py</a></li>
<li><a href="#trunkWebKitToolsScriptswebkitpystylepatchreaderpy">trunk/WebKitTools/Scripts/webkitpy/style/patchreader.py</a></li>
<li><a href="#trunkWebKitToolsScriptswebkitpystylepatchreader_unittestpy">trunk/WebKitTools/Scripts/webkitpy/style/patchreader_unittest.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebKitToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/ChangeLog (69743 => 69744)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/ChangeLog        2010-10-14 06:45:26 UTC (rev 69743)
+++ trunk/WebKitTools/ChangeLog        2010-10-14 06:55:51 UTC (rev 69744)
</span><span class="lines">@@ -2,6 +2,17 @@
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Adam Barth.
</span><span class="cx"> 
</span><ins>+        beat diff_parser with the ugly stick
+        https://bugs.webkit.org/show_bug.cgi?id=47626
+
+        * Scripts/webkitpy/common/checkout/diff_parser.py:
+        * Scripts/webkitpy/style/patchreader.py:
+        * Scripts/webkitpy/style/patchreader_unittest.py:
+
+2010-10-13  Eric Seidel  &lt;eric@webkit.org&gt;
+
+        Reviewed by Adam Barth.
+
</ins><span class="cx">         Break LayoutTestResults out into its own file
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=47637
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkWebKitToolsScriptswebkitpycommoncheckoutdiff_parserpy"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/Scripts/webkitpy/common/checkout/diff_parser.py (69743 => 69744)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/Scripts/webkitpy/common/checkout/diff_parser.py        2010-10-14 06:45:26 UTC (rev 69743)
+++ trunk/WebKitTools/Scripts/webkitpy/common/checkout/diff_parser.py        2010-10-14 06:55:51 UTC (rev 69744)
</span><span class="lines">@@ -33,9 +33,13 @@
</span><span class="cx"> 
</span><span class="cx"> _log = logging.getLogger(&quot;webkitpy.common.checkout.diff_parser&quot;)
</span><span class="cx"> 
</span><ins>+
+# FIXME: This is broken. We should compile our regexps up-front
+# instead of using a custom cache.
</ins><span class="cx"> _regexp_compile_cache = {}
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+# FIXME: This function should be removed.
</ins><span class="cx"> def match(pattern, string):
</span><span class="cx">     &quot;&quot;&quot;Matches the string with the pattern, caching the compiled regexp.&quot;&quot;&quot;
</span><span class="cx">     if not pattern in _regexp_compile_cache:
</span><span class="lines">@@ -43,12 +47,15 @@
</span><span class="cx">     return _regexp_compile_cache[pattern].match(string)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+# FIXME: This belongs on DiffParser (e.g. as to_svn_diff()).
</ins><span class="cx"> def git_diff_to_svn_diff(line):
</span><span class="cx">     &quot;&quot;&quot;Converts a git formatted diff line to a svn formatted line.
</span><span class="cx"> 
</span><span class="cx">     Args:
</span><span class="cx">       line: A string representing a line of the diff.
</span><span class="cx">     &quot;&quot;&quot;
</span><ins>+    # FIXME: This list should be a class member on DiffParser.
+    # These regexp patterns should be compiled once instead of every time.
</ins><span class="cx">     conversion_patterns = ((&quot;^diff --git \w/(.+) \w/(?P&lt;FilePath&gt;.+)&quot;, lambda matched: &quot;Index: &quot; + matched.group('FilePath') + &quot;\n&quot;),
</span><span class="cx">                            (&quot;^new file.*&quot;, lambda matched: &quot;\n&quot;),
</span><span class="cx">                            (&quot;^index [0-9a-f]{7}\.\.[0-9a-f]{7} [0-9]{6}&quot;, lambda matched: &quot;===================================================================\n&quot;),
</span><span class="lines">@@ -62,6 +69,7 @@
</span><span class="cx">     return line
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+# FIXME: This method belongs on DiffParser
</ins><span class="cx"> def get_diff_converter(first_diff_line):
</span><span class="cx">     &quot;&quot;&quot;Gets a converter function of diff lines.
</span><span class="cx"> 
</span><span class="lines">@@ -80,7 +88,7 @@
</span><span class="cx"> _PROCESSING_CHUNK = 3
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class DiffFile:
</del><ins>+class DiffFile(object):
</ins><span class="cx">     &quot;&quot;&quot;Contains the information for one file in a patch.
</span><span class="cx"> 
</span><span class="cx">     The field &quot;lines&quot; is a list which contains tuples in this format:
</span><span class="lines">@@ -88,7 +96,14 @@
</span><span class="cx">     If deleted_line_number is zero, it means this line is newly added.
</span><span class="cx">     If new_line_number is zero, it means this line is deleted.
</span><span class="cx">     &quot;&quot;&quot;
</span><ins>+    # FIXME: Tuples generally grow into classes.  We should consider
+    # adding a DiffLine object.
</ins><span class="cx"> 
</span><ins>+    def added_or_modified_line_numbers(self):
+        # This logic was moved from patchreader.py, but may not be
+        # the right API for this object long-term.
+        return [line[1] for line in self.lines if not line[0]]
+
</ins><span class="cx">     def __init__(self, filename):
</span><span class="cx">         self.filename = filename
</span><span class="cx">         self.lines = []
</span><span class="lines">@@ -103,13 +118,14 @@
</span><span class="cx">         self.lines.append((deleted_line_number, new_line_number, line))
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class DiffParser:
</del><ins>+class DiffParser(object):
</ins><span class="cx">     &quot;&quot;&quot;A parser for a patch file.
</span><span class="cx"> 
</span><span class="cx">     The field &quot;files&quot; is a dict whose key is the filename and value is
</span><span class="cx">     a DiffFile object.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><ins>+    # FIXME: This function is way too long and needs to be broken up.
</ins><span class="cx">     def __init__(self, diff_input):
</span><span class="cx">         &quot;&quot;&quot;Parses a diff.
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkWebKitToolsScriptswebkitpystylepatchreaderpy"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/Scripts/webkitpy/style/patchreader.py (69743 => 69744)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/Scripts/webkitpy/style/patchreader.py        2010-10-14 06:45:26 UTC (rev 69743)
+++ trunk/WebKitTools/Scripts/webkitpy/style/patchreader.py        2010-10-14 06:55:51 UTC (rev 69744)
</span><span class="lines">@@ -37,7 +37,6 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class PatchReader(object):
</span><del>-
</del><span class="cx">     &quot;&quot;&quot;Supports checking style in patches.&quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     def __init__(self, text_file_reader):
</span><span class="lines">@@ -53,28 +52,15 @@
</span><span class="cx">         &quot;&quot;&quot;Check style in the given patch.&quot;&quot;&quot;
</span><span class="cx">         patch_files = DiffParser(patch_string.splitlines()).files
</span><span class="cx"> 
</span><del>-        # 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])
</del><ins>+        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))
</ins><span class="cx"> 
</span><del>-            _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.
</del><ins>+            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.
</ins><span class="cx">                 self._text_file_reader.count_delete_only_file()
</span><ins>+                continue
+
+            self._text_file_reader.process_file(file_path=path, line_numbers=line_numbers)
</ins></span></pre></div>
<a id="trunkWebKitToolsScriptswebkitpystylepatchreader_unittestpy"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/Scripts/webkitpy/style/patchreader_unittest.py (69743 => 69744)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/Scripts/webkitpy/style/patchreader_unittest.py        2010-10-14 06:45:26 UTC (rev 69743)
+++ trunk/WebKitTools/Scripts/webkitpy/style/patchreader_unittest.py        2010-10-14 06:55:51 UTC (rev 69744)
</span><span class="lines">@@ -78,7 +78,7 @@
</span><span class="cx">  # Required for Python to search this directory for module files
</span><span class="cx"> +# New line
</span><span class="cx"> &quot;&quot;&quot;)
</span><del>-        self._assert_checked([(&quot;__init__.py&quot;, set([2]))], 0)
</del><ins>+        self._assert_checked([(&quot;__init__.py&quot;, [2])], 0)
</ins><span class="cx"> 
</span><span class="cx">     def test_check_patch_with_deletion(self):
</span><span class="cx">         self._call_check_patch(&quot;&quot;&quot;Index: __init__.py
</span></span></pre>
</div>
</div>

</body>
</html>