<!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>[45940] 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/45940">45940</a></dd>
<dt>Author</dt> <dd>bfulgham@webkit.org</dd>
<dt>Date</dt> <dd>2009-07-15 13:15:32 -0700 (Wed, 15 Jul 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>2009-07-10  David Kilzer  &lt;ddkilzer@apple.com&gt;

        bugzilla-tool: create CommitMessage class

        Reviewed by Eric Seidel.

        Create a CommitMessage class to encapsulate related code.

        * Scripts/bugzilla-tool:
         (bug_id_from_commit_message): Moved to
         CommitMessage.parse_bug_id().
         (commit_message_for_this_commit): Return a CommitMessage.
         (ApplyPatchesFromBug.apply_patches): Use CommitMessage.message().
         (LandPatchesFromBugs.build_and_commit): Ditto.
         (CommitMessageForCurrentDiff.execute): Ditto.
         (PostCommitsAsPatchesToBug.execute): Switched from
         Git.commit_message_for_commit() to
         Git.commit_message_for_local_commit().  Switched from
         bug_id_from_commit_message() to CommitMessage.parse_bug_id().

         * Scripts/modules/scm.py:
         (first_non_empty_line_after_index): Added.
         (CommitMessage.__init__): Added.
         (CommitMessage.body): Added.
         (CommitMessage.description): Added.
         (CommitMessage.message): Added.
         (CommitMessage.parse_bug_id): Added.  Moved from
         bug_id_from_commit_message() in bugzilla-tool.
         (Git.commit_message_for_local_commit): Renamed from
         commit_message_for_commit().  Return a CommitMessage.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebKitToolsChangeLog">trunk/WebKitTools/ChangeLog</a></li>
<li><a href="#trunkWebKitToolsScriptsbugzillatool">trunk/WebKitTools/Scripts/bugzilla-tool</a></li>
<li><a href="#trunkWebKitToolsScriptsmodulesscmpy">trunk/WebKitTools/Scripts/modules/scm.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebKitToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/ChangeLog (45939 => 45940)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/ChangeLog        2009-07-15 20:11:01 UTC (rev 45939)
+++ trunk/WebKitTools/ChangeLog        2009-07-15 20:15:32 UTC (rev 45940)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2009-07-10  David Kilzer  &lt;ddkilzer@apple.com&gt;
+
+        bugzilla-tool: create CommitMessage class
+
+        Reviewed by Eric Seidel.
+
+        Create a CommitMessage class to encapsulate related code.
+
+        * Scripts/bugzilla-tool:
+         (bug_id_from_commit_message): Moved to
+         CommitMessage.parse_bug_id().
+         (commit_message_for_this_commit): Return a CommitMessage.
+         (ApplyPatchesFromBug.apply_patches): Use CommitMessage.message().
+         (LandPatchesFromBugs.build_and_commit): Ditto.
+         (CommitMessageForCurrentDiff.execute): Ditto.
+         (PostCommitsAsPatchesToBug.execute): Switched from
+         Git.commit_message_for_commit() to
+         Git.commit_message_for_local_commit().  Switched from
+         bug_id_from_commit_message() to CommitMessage.parse_bug_id().
+
+         * Scripts/modules/scm.py:
+         (first_non_empty_line_after_index): Added.
+         (CommitMessage.__init__): Added.
+         (CommitMessage.body): Added.
+         (CommitMessage.description): Added.
+         (CommitMessage.message): Added.
+         (CommitMessage.parse_bug_id): Added.  Moved from
+         bug_id_from_commit_message() in bugzilla-tool.
+         (Git.commit_message_for_local_commit): Renamed from
+         commit_message_for_commit().  Return a CommitMessage.
+
</ins><span class="cx"> 2009-07-15  Joseph Pecoraro  &lt;joepeck02@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Reviewed by David Kilzer.
</span></span></pre></div>
<a id="trunkWebKitToolsScriptsbugzillatool"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/Scripts/bugzilla-tool (45939 => 45940)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/Scripts/bugzilla-tool        2009-07-15 20:11:01 UTC (rev 45939)
+++ trunk/WebKitTools/Scripts/bugzilla-tool        2009-07-15 20:15:32 UTC (rev 45940)
</span><span class="lines">@@ -96,15 +96,6 @@
</span><span class="cx">             changelog_paths.append(path)
</span><span class="cx">     return changelog_paths
</span><span class="cx"> 
</span><del>-def bug_id_from_commit_message(commit_message):
-    match = re.search(&quot;http\://webkit\.org/b/(?P&lt;bug_id&gt;\d+)&quot;, commit_message, re.MULTILINE)
-    if match:
-        return match.group('bug_id')
-    match = re.search(Bugzilla.bug_server_regex + &quot;show_bug\.cgi\?id=(?P&lt;bug_id&gt;\d+)&quot;, commit_message, re.MULTILINE)
-    if match:
-        return match.group('bug_id')
-    return None
-
</del><span class="cx"> def commit_message_for_this_commit(scm):
</span><span class="cx">     changelog_paths = modified_changelogs(scm)
</span><span class="cx">     if not len(changelog_paths):
</span><span class="lines">@@ -120,7 +111,7 @@
</span><span class="cx">         changelog_messages.append(changelog_entry)
</span><span class="cx">     
</span><span class="cx">     # FIXME: We should sort and label the ChangeLog messages like commit-log-editor does.
</span><del>-    return ''.join(changelog_messages)
</del><ins>+    return CommitMessage(''.join(changelog_messages).splitlines())
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class Command:
</span><span class="lines">@@ -194,7 +185,7 @@
</span><span class="cx">             scm.apply_patch(patch)
</span><span class="cx">             if commit_each:
</span><span class="cx">                 commit_message = commit_message_for_this_commit(scm)
</span><del>-                scm.commit_locally_with_message(commit_message or patch['name'])
</del><ins>+                scm.commit_locally_with_message(commit_message.message() or patch['name'])
</ins><span class="cx"> 
</span><span class="cx">     def execute(self, options, args, tool):
</span><span class="cx">         bug_id = args[0]
</span><span class="lines">@@ -317,7 +308,7 @@
</span><span class="cx">             if options.test:
</span><span class="cx">                 cls.run_webkit_tests()
</span><span class="cx">         commit_message = commit_message_for_this_commit(scm)
</span><del>-        commit_log = scm.commit_with_message(commit_message)
</del><ins>+        commit_log = scm.commit_with_message(commit_message.message())
</ins><span class="cx">         return bug_comment_from_commit_text(scm, commit_log)
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><span class="lines">@@ -368,7 +359,7 @@
</span><span class="cx"> 
</span><span class="cx">     def execute(self, options, args, tool):
</span><span class="cx">         os.chdir(tool.scm().checkout_root)
</span><del>-        print &quot;%s&quot; % commit_message_for_this_commit(tool.scm())
</del><ins>+        print &quot;%s&quot; % commit_message_for_this_commit(tool.scm()).message()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class ObsoleteAttachmentsOnBug(Command):
</span><span class="lines">@@ -432,10 +423,9 @@
</span><span class="cx"> 
</span><span class="cx">         have_obsoleted_patches = set()
</span><span class="cx">         for commit_id in commit_ids:
</span><del>-            commit_message = tool.scm().commit_message_for_commit(commit_id)
-            commit_lines = commit_message.splitlines()
</del><ins>+            commit_message = tool.scm().commit_message_for_local_commit(commit_id)
</ins><span class="cx"> 
</span><del>-            bug_id = options.bug_id or bug_id_from_commit_message(commit_message)
</del><ins>+            bug_id = options.bug_id or commit_message.parse_bug_id()
</ins><span class="cx">             if not bug_id:
</span><span class="cx">                 log(&quot;Skipping %s: No bug id found in commit log or specified with --bug-id.&quot; % commit_id)
</span><span class="cx">                 continue
</span><span class="lines">@@ -444,11 +434,11 @@
</span><span class="cx">                 PostDiffAsPatchToBug.obsolete_patches_on_bug(bug_id, tool.bugs)
</span><span class="cx">                 have_obsoleted_patches.update(bug_id)
</span><span class="cx"> 
</span><del>-            description = commit_lines[0]
</del><ins>+            description = commit_message.description(lstrip=True, strip_url=True)
</ins><span class="cx">             comment_text = None
</span><span class="cx">             if (options.comment):
</span><del>-                comment_text = &quot;\n&quot;.join(commit_lines[1:])
-                comment_text += &quot;\n---\n&quot;
</del><ins>+                comment_text = commit_message.body(lstrip=True)
+                comment_text += &quot;---\n&quot;
</ins><span class="cx">                 comment_text += tool.scm().files_changed_summary_for_commit(commit_id)
</span><span class="cx"> 
</span><span class="cx">             diff = tool.scm().create_patch_from_local_commit(commit_id)
</span></span></pre></div>
<a id="trunkWebKitToolsScriptsmodulesscmpy"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/Scripts/modules/scm.py (45939 => 45940)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/Scripts/modules/scm.py        2009-07-15 20:11:01 UTC (rev 45939)
+++ trunk/WebKitTools/Scripts/modules/scm.py        2009-07-15 20:15:32 UTC (rev 45940)
</span><span class="lines">@@ -45,9 +45,52 @@
</span><span class="cx">     
</span><span class="cx">     return None
</span><span class="cx"> 
</span><ins>+def first_non_empty_line_after_index(lines, index=0):
+    first_non_empty_line = index
+    for line in lines[index:]:
+        if re.match(&quot;^\s*$&quot;, line):
+            first_non_empty_line += 1
+        else:
+            break
+    return first_non_empty_line
+
+
+class CommitMessage:
+    def __init__(self, message):
+        self.message = message[first_non_empty_line_after_index(message, 0):]
+
+    def body(self, lstrip=False):
+        lines = self.message[first_non_empty_line_after_index(self.message, 1):]
+        if lstrip:
+            lines = [line.lstrip() for line in lines]
+        return &quot;\n&quot;.join(lines) + &quot;\n&quot;
+
+    def description(self, lstrip=False, strip_url=False):
+        line = self.message[0]
+        if lstrip:
+            line = line.lstrip()
+        if strip_url:
+            line = re.sub(&quot;^(\s*)&lt;.+&gt; &quot;, &quot;\1&quot;, line)
+        return line
+
+    def message(self):
+        return &quot;\n&quot;.join(self.message) + &quot;\n&quot;
+
+    def parse_bug_id(self):
+        for line in self.message:
+            match = re.search(&quot;http\://webkit\.org/b/(?P&lt;bug_id&gt;\d+)&quot;, line)
+            if match:
+                return match.group('bug_id')
+            match = re.search(Bugzilla.bug_server_regex + &quot;show_bug\.cgi\?id=(?P&lt;bug_id&gt;\d+)&quot;, line)
+            if match:
+                return match.group('bug_id')
+        return None
+
+
</ins><span class="cx"> class ScriptError(Exception):
</span><span class="cx">     pass
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> class SCM:
</span><span class="cx">     def __init__(self, cwd, dryrun=False):
</span><span class="cx">         self.cwd = cwd
</span><span class="lines">@@ -162,6 +205,7 @@
</span><span class="cx">     def local_commits(self):
</span><span class="cx">         return []
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> class SVN(SCM):
</span><span class="cx">     def __init__(self, cwd, dryrun=False):
</span><span class="cx">         SCM.__init__(self, cwd, dryrun)
</span><span class="lines">@@ -226,6 +270,7 @@
</span><span class="cx">             return &quot;Dry run, no remote commit.&quot;
</span><span class="cx">         return self.run_command(['svn', 'commit', '-m', message])
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> # All git-specific logic should go here.
</span><span class="cx"> class Git(SCM):
</span><span class="cx">     def __init__(self, cwd, dryrun=False):
</span><span class="lines">@@ -315,7 +360,7 @@
</span><span class="cx"> 
</span><span class="cx">         return self.run_command(['git', 'rev-list'] + revisions).splitlines()
</span><span class="cx"> 
</span><del>-    def commit_message_for_commit(self, commit_id):
</del><ins>+    def commit_message_for_local_commit(self, commit_id):
</ins><span class="cx">         commit_lines = self.run_command(['git', 'cat-file', 'commit', commit_id]).splitlines()
</span><span class="cx"> 
</span><span class="cx">         # Skip the git headers.
</span><span class="lines">@@ -324,7 +369,7 @@
</span><span class="cx">             first_line_after_headers += 1
</span><span class="cx">             if line == &quot;&quot;:
</span><span class="cx">                 break
</span><del>-        return &quot;\n&quot;.join(commit_lines[first_line_after_headers:])
</del><ins>+        return CommitMessage(commit_lines[first_line_after_headers:])
</ins><span class="cx"> 
</span><span class="cx">     def files_changed_summary_for_commit(self, commit_id):
</span><span class="cx">         return self.run_command(['git', 'diff-tree', '--shortstat', '--no-commit-id', commit_id])
</span></span></pre>
</div>
</div>

</body>
</html>