Analysis task should look for a git commit based on abridged hashes
[WebKit-https.git] / Websites / perf.webkit.org / public / include / commit-log-fetcher.php
index 2ae5e45bd4b08b92c09fca53bc882fe715aaa172..0bb73fb9d56fb6bd2cf183e666d306c4c1334a31 100644 (file)
@@ -4,7 +4,25 @@ class CommitLogFetcher {
 
     function __construct($db) {
         $this->db = $db;
-        $this->commits = array();
+    }
+
+    function fetch_for_tasks($task_id_list, $task_by_id)
+    {
+        $commit_rows = $this->db->query_and_fetch_all('SELECT task_commits.*, commits.*, committers.*
+            FROM task_commits, commits LEFT OUTER JOIN committers ON commit_committer = committer_id
+            WHERE taskcommit_commit = commit_id AND taskcommit_task = ANY ($1)', array('{' . implode(', ', $task_id_list) . '}'));
+        if (!is_array($commit_rows))
+            return NULL;
+
+        $commits = array();
+        foreach ($commit_rows as &$commit_row) {
+            $associated_task = &$task_by_id[$commit_row['taskcommit_task']];
+            $commit = $this->format_commit($commit_row, $commit_row);
+            $commit['repository'] = $commit_row['commit_repository'];
+            array_push($commits, $commit);
+            array_push($associated_task[Database::is_true($commit_row['taskcommit_is_fix']) ? 'fixes' : 'causes'], $commit_row['commit_id']);
+        }
+        return $commits;
     }
 
     function repository_id_from_name($name)
@@ -47,7 +65,7 @@ class CommitLogFetcher {
         }
 
         if ($keyword) {
-            array_push($values, '%' . str_replace(array('\\', '_', '%'), array('\\\\', '\\_', '\\%'), $keyword) . '%');
+            array_push($values, '%' . Database::escape_for_like($keyword) . '%');
             $keyword_index = '$' . count($values);
             array_push($values, ltrim($keyword, 'r'));
             $revision_index = '$' . count($values);
@@ -94,7 +112,7 @@ class CommitLogFetcher {
 
     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);
+        return array($this->format_commit($commit_row, $committer));
     }
 
     private function format_commit($commit_row, $committer_row) {