<!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>[198234] trunk/Websites/perf.webkit.org</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/198234">198234</a></dd>
<dt>Author</dt> <dd>rniwa@webkit.org</dd>
<dt>Date</dt> <dd>2016-03-15 15:42:15 -0700 (Tue, 15 Mar 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Extract the code to format commit logs into its own PHP file
https://bugs.webkit.org/show_bug.cgi?id=155514
Rubber-stamped by Chris Dumez.
Extracted CommitLogFetcher out of /api/commits so that it could be used in analysis-tasks.php
in the future to support associating cause/fix for each analysis task.
* public/api/commits.php:
* public/include/commit-log-fetcher.php: Added.
(CommitLogFetcher)
(CommitLogFetcher::__construct): Added.
(CommitLogFetcher::repository_id_from_name): Added.
(CommitLogFetcher::fetch_between): Added.
(CommitLogFetcher::fetch_oldest): Added.
(CommitLogFetcher::fetch_latest): Added.
(CommitLogFetcher::fetch_last_reported): Added.
(CommitLogFetcher::fetch_revision): Added.
(CommitLogFetcher::commit_for_revision): Added.
(CommitLogFetcher::format_single_commit): Added.
(CommitLogFetcher::format_commit): Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebsitesperfwebkitorgChangeLog">trunk/Websites/perf.webkit.org/ChangeLog</a></li>
<li><a href="#trunkWebsitesperfwebkitorgpublicapicommitsphp">trunk/Websites/perf.webkit.org/public/api/commits.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkWebsitesperfwebkitorgpublicincludecommitlogfetcherphp">trunk/Websites/perf.webkit.org/public/include/commit-log-fetcher.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebsitesperfwebkitorgChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Websites/perf.webkit.org/ChangeLog (198233 => 198234)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/perf.webkit.org/ChangeLog        2016-03-15 22:38:29 UTC (rev 198233)
+++ trunk/Websites/perf.webkit.org/ChangeLog        2016-03-15 22:42:15 UTC (rev 198234)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2016-03-15 Ryosuke Niwa <rniwa@webkit.org>
+
+ Extract the code to format commit logs into its own PHP file
+ https://bugs.webkit.org/show_bug.cgi?id=155514
+
+ Rubber-stamped by Chris Dumez.
+
+ Extracted CommitLogFetcher out of /api/commits so that it could be used in analysis-tasks.php
+ in the future to support associating cause/fix for each analysis task.
+
+ * public/api/commits.php:
+ * public/include/commit-log-fetcher.php: Added.
+ (CommitLogFetcher)
+ (CommitLogFetcher::__construct): Added.
+ (CommitLogFetcher::repository_id_from_name): Added.
+ (CommitLogFetcher::fetch_between): Added.
+ (CommitLogFetcher::fetch_oldest): Added.
+ (CommitLogFetcher::fetch_latest): Added.
+ (CommitLogFetcher::fetch_last_reported): Added.
+ (CommitLogFetcher::fetch_revision): Added.
+ (CommitLogFetcher::commit_for_revision): Added.
+ (CommitLogFetcher::format_single_commit): Added.
+ (CommitLogFetcher::format_commit): Added.
+
</ins><span class="cx"> 2016-03-09 Ryosuke Niwa <rniwa@webkit.org>
</span><span class="cx">
</span><span class="cx"> Build fix after r196870.
</span></span></pre></div>
<a id="trunkWebsitesperfwebkitorgpublicapicommitsphp"></a>
<div class="modfile"><h4>Modified: trunk/Websites/perf.webkit.org/public/api/commits.php (198233 => 198234)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/perf.webkit.org/public/api/commits.php        2016-03-15 22:38:29 UTC (rev 198233)
+++ trunk/Websites/perf.webkit.org/public/api/commits.php        2016-03-15 22:42:15 UTC (rev 198234)
</span><span class="lines">@@ -1,6 +1,7 @@
</span><span class="cx"> <?php
</span><span class="cx">
</span><span class="cx"> require_once('../include/json-header.php');
</span><ins>+require_once('../include/commit-log-fetcher.php');
</ins><span class="cx">
</span><span class="cx"> function main($paths) {
</span><span class="cx"> if (count($paths) < 1 || count($paths) > 2)
</span><span class="lines">@@ -10,119 +11,43 @@
</span><span class="cx"> if (!$db->connect())
</span><span class="cx"> exit_with_error('DatabaseConnectionFailure');
</span><span class="cx">
</span><ins>+ $fetcher = new CommitLogFetcher($db);
+
</ins><span class="cx"> if (!is_numeric($paths[0])) {
</span><del>- $repository_name = $paths[0];
- $repository_row = $db->select_first_row('repositories', 'repository', array('name' => $repository_name));
- if (!$repository_row)
- exit_with_error('RepositoryNotFound', array('repositoryName' => $repository_name));
- $repository_id = $repository_row['repository_id'];
</del><ins>+ $repository_id = $fetcher->repository_id_from_name($paths[0]);
+ if (!$repository_id)
+ exit_with_error('RepositoryNotFound', array('repositoryName' => $paths[0]));
</ins><span class="cx"> } else
</span><span class="cx"> $repository_id = intval($paths[0]);
</span><span class="cx">
</span><span class="cx"> $filter = array_get($paths, 1);
</span><del>- $single_commit = NULL;
</del><span class="cx"> $commits = array();
</span><span class="cx"> if (!$filter) {
</span><span class="cx"> $keyword = array_get($_GET, 'keyword');
</span><span class="cx"> $from = array_get($_GET, 'from');
</span><span class="cx"> $to = array_get($_GET, 'to');
</span><del>- $commits = fetch_commits_between($db, $repository_id, $from, $to, $keyword);
</del><ins>+ $commits = $fetcher->fetch_between($repository_id, $from, $to, $keyword);
</ins><span class="cx"> } else if ($filter == 'oldest') {
</span><del>- $single_commit = $db->select_first_row('commits', 'commit', array('repository' => $repository_id), 'time');
</del><ins>+ $commits = $fetcher->fetch_oldest($repository_id);
</ins><span class="cx"> } else if ($filter == 'latest') {
</span><del>- $single_commit = $db->select_last_row('commits', 'commit', array('repository' => $repository_id), 'time');
</del><ins>+ $commits = $fetcher->fetch_latest($repository_id);
</ins><span class="cx"> } else if ($filter == 'last-reported') {
</span><del>- $single_commit = $db->select_last_row('commits', 'commit', array('repository' => $repository_id, 'reported' => true), 'time');
</del><ins>+ $commits = $fetcher->fetch_latest_reported($repository_id);
</ins><span class="cx"> } else if (ctype_alnum($filter)) {
</span><del>- $single_commit = commit_from_revision($db, $repository_id, $filter);
</del><ins>+ $commits = $fetcher->fetch_revision($repository_id, $filter);
</ins><span class="cx"> } else {
</span><span class="cx"> $matches = array();
</span><span class="cx"> if (!preg_match('/([A-Za-z0-9]+)[\:\-]([A-Za-z0-9]+)/', $filter, $matches))
</span><span class="cx"> exit_with_error('UnknownFilter', array('repositoryName' => $repository_name, 'filter' => $filter));
</span><del>-
- $commits = fetch_commits_between($db, $repository_id, $matches[1], $matches[2]);
</del><ins>+ $commits = $fetcher->fetch_between($repository_id, $matches[1], $matches[2]);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- if ($single_commit) {
- $committer = $db->select_first_row('committers', 'committer', array('id' => $single_commit['commit_committer']));
- exit_with_success(array('commits' => array(format_commit($single_commit, $committer))));
- }
</del><ins>+ if (!is_array($commits))
+ exit_with_error('FailedToFetchCommits', array('repository' => $repository_id, 'filter' => $filter));
</ins><span class="cx">
</span><span class="cx"> exit_with_success(array('commits' => $commits));
</span><span class="cx"> }
</span><span class="cx">
</span><del>-function commit_from_revision($db, $repository_id, $revision) {
- $all_but_first = substr($revision, 1);
- if ($revision[0] == 'r' && ctype_digit($all_but_first))
- $revision = $all_but_first;
- $commit_info = array('repository' => $repository_id, 'revision' => $revision);
- $row = $db->select_last_row('commits', 'commit', $commit_info);
- if (!$row)
- exit_with_error('UnknownCommit', $commit_info);
- return $row;
-}
-
-function fetch_commits_between($db, $repository_id, $first, $second, $keyword = NULL) {
- $statements = 'SELECT commit_id as "id",
- commit_revision as "revision",
- commit_parent as "parent",
- commit_time as "time",
- committer_name as "authorName",
- committer_account as "authorEmail",
- commit_message as "message"
- FROM commits LEFT OUTER JOIN committers ON commit_committer = committer_id
- WHERE commit_repository = $1 AND commit_reported = true';
- $values = array($repository_id);
-
- if ($first && $second) {
- $first_commit = commit_from_revision($db, $repository_id, $first);
- $second_commit = commit_from_revision($db, $repository_id, $second);
- $first = $first_commit['commit_time'];
- $second = $second_commit['commit_time'];
- $column_name = 'commit_time';
- if (!$first || !$second) {
- $first = $first_commit['commit_order'];
- $second = $second_commit['commit_order'];
- $column_name = 'commit_order';
- }
-
- $in_order = $first < $second;
- array_push($values, $in_order ? $first : $second);
- $statements .= ' AND ' . $column_name . ' >= $' . count($values);
- array_push($values, $in_order ? $second : $first);
- $statements .= ' AND ' . $column_name . ' <= $' . count($values);
- }
-
- if ($keyword) {
- array_push($values, '%' . str_replace(array('\\', '_', '%'), array('\\\\', '\\_', '\\%'), $keyword) . '%');
- $keyword_index = '$' . count($values);
- array_push($values, ltrim($keyword, 'r'));
- $revision_index = '$' . count($values);
- $statements .= "
- AND ((committer_name LIKE $keyword_index OR committer_account LIKE $keyword_index) OR commit_revision = $revision_index)";
- }
-
- $commits = $db->query_and_fetch_all($statements . ' ORDER BY commit_time, commit_order', $values);
- if (!is_array($commits))
- exit_with_error('FailedToFetchCommits', array('repository' => $repository_id, 'first' => $first, 'second' => $second));
- foreach ($commits as &$commit)
- $commit['time'] = Database::to_js_time($commit['time']);
- return $commits;
-}
-
-function format_commit($commit_row, $committer_row) {
- return array(
- 'id' => $commit_row['commit_id'],
- 'revision' => $commit_row['commit_revision'],
- 'parent' => $commit_row['commit_parent'],
- 'time' => Database::to_js_time($commit_row['commit_time']),
- 'order' => $commit_row['commit_order'],
- 'authorName' => $committer_row ? $committer_row['committer_name'] : null,
- 'authorEmail' => $committer_row ? $committer_row['committer_account'] : null,
- 'message' => $commit_row['commit_message']
- );
-}
-
</del><span class="cx"> main(array_key_exists('PATH_INFO', $_SERVER) ? explode('/', trim($_SERVER['PATH_INFO'], '/')) : array());
</span><span class="cx">
</span><span class="cx"> ?>
</span></span></pre></div>
<a id="trunkWebsitesperfwebkitorgpublicincludecommitlogfetcherphp"></a>
<div class="addfile"><h4>Added: trunk/Websites/perf.webkit.org/public/include/commit-log-fetcher.php (0 => 198234)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/perf.webkit.org/public/include/commit-log-fetcher.php         (rev 0)
+++ trunk/Websites/perf.webkit.org/public/include/commit-log-fetcher.php        2016-03-15 22:42:15 UTC (rev 198234)
</span><span class="lines">@@ -0,0 +1,114 @@
</span><ins>+<?php
+
+class CommitLogFetcher {
+
+ function __construct($db) {
+ $this->db = $db;
+ $this->commits = array();
+ }
+
+ function repository_id_from_name($name)
+ {
+ $repository_row = $this->db->select_first_row('repositories', 'repository', array('name' => $name));
+ if (!$repository_row)
+ return NULL;
+ return $repository_row['repository_id'];
+ }
+
+ function fetch_between($repository_id, $first, $second, $keyword = NULL) {
+ $statements = 'SELECT commit_id as "id",
+ commit_revision as "revision",
+ commit_parent as "parent",
+ commit_time as "time",
+ committer_name as "authorName",
+ committer_account as "authorEmail",
+ commit_message as "message"
+ FROM commits LEFT OUTER JOIN committers ON commit_committer = committer_id
+ WHERE commit_repository = $1 AND commit_reported = true';
+ $values = array($repository_id);
+
+ if ($first && $second) {
+ $first_commit = $this->commit_for_revision($repository_id, $first);
+ $second_commit = $this->commit_for_revision($repository_id, $second);
+ $first = $first_commit['commit_time'];
+ $second = $second_commit['commit_time'];
+ $column_name = 'commit_time';
+ if (!$first || !$second) {
+ $first = $first_commit['commit_order'];
+ $second = $second_commit['commit_order'];
+ $column_name = 'commit_order';
+ }
+
+ $in_order = $first < $second;
+ array_push($values, $in_order ? $first : $second);
+ $statements .= ' AND ' . $column_name . ' >= $' . count($values);
+ array_push($values, $in_order ? $second : $first);
+ $statements .= ' AND ' . $column_name . ' <= $' . count($values);
+ }
+
+ if ($keyword) {
+ array_push($values, '%' . str_replace(array('\\', '_', '%'), array('\\\\', '\\_', '\\%'), $keyword) . '%');
+ $keyword_index = '$' . count($values);
+ array_push($values, ltrim($keyword, 'r'));
+ $revision_index = '$' . count($values);
+ $statements .= "
+ AND ((committer_name LIKE $keyword_index OR committer_account LIKE $keyword_index) OR commit_revision = $revision_index)";
+ }
+
+ $commits = $this->db->query_and_fetch_all($statements . ' ORDER BY commit_time, commit_order', $values);
+ if (!is_array($commits))
+ return NULL;
+
+ foreach ($commits as &$commit)
+ $commit['time'] = Database::to_js_time($commit['time']);
+
+ return $commits;
+ }
+
+ function fetch_oldest($repository_id) {
+ return $this->format_single_commit($this->db->select_first_row('commits', 'commit', array('repository' => $repository_id), 'time'));
+ }
+
+ function fetch_latest($repository_id) {
+ return $this->format_single_commit($this->db->select_first_row('commits', 'commit', array('repository' => $repository_id), 'time'));
+ }
+
+ function fetch_last_reported($repository_id) {
+ return $this->format_single_commit($this->db->select_last_row('commits', 'commit', array('repository' => $repository_id, 'reported' => true), 'time'));
+ }
+
+ function fetch_revision($repository_id, $revision) {
+ return $this->format_single_commit($this->db->commit_for_revision($repository_id, $revision));
+ }
+
+ private function commit_for_revision($repository_id, $revision) {
+ $all_but_first = substr($revision, 1);
+ if ($revision[0] == 'r' && ctype_digit($all_but_first))
+ $revision = $all_but_first;
+ $commit_info = array('repository' => $repository_id, 'revision' => $revision);
+ $row = $this->db->select_last_row('commits', 'commit', $commit_info);
+ if (!$row)
+ exit_with_error('UnknownCommit', $commit_info);
+ return $row;
+ }
+
+ private function format_single_commit($commit_row) {
+ $committer = $this->db->select_first_row('committers', 'committer', array('id' => $commit_row['commit_committer']));
+ return $this->format_commit($commit_row, $committer);
+ }
+
+ private function format_commit($commit_row, $committer_row) {
+ return array(
+ 'id' => $commit_row['commit_id'],
+ 'revision' => $commit_row['commit_revision'],
+ 'parent' => $commit_row['commit_parent'],
+ 'time' => Database::to_js_time($commit_row['commit_time']),
+ 'order' => $commit_row['commit_order'],
+ 'authorName' => $committer_row ? $committer_row['committer_name'] : null,
+ 'authorEmail' => $committer_row ? $committer_row['committer_account'] : null,
+ 'message' => $commit_row['commit_message']
+ );
+ }
+}
+
+?>
</ins><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>