Analysis task should look for a git commit based on abridged hashes
[WebKit-https.git] / Websites / perf.webkit.org / public / privileged-api / associate-commit.php
index 07c1ce01ce9bb011ac9130c50c3f82ef4a783427..30ec1161fb36d94a6cf4e33d0c2d3319792c6019 100644 (file)
@@ -29,12 +29,17 @@ function main() {
         require_format('Kind', $kind, '/^(cause|fix)$/');
 
         $commit_info = array('repository' => $repository_id, 'revision' => $revision);
-        $commit_row = $db->select_first_row('commits', 'commit', $commit_info);
-        if (!$commit_row) {
+        $commit_rows = $db->query_and_fetch_all('SELECT commit_id FROM commits WHERE commit_repository = $1 AND commit_revision LIKE $2 LIMIT 2',
+            array($repository_id, '%' . Database::escape_for_like($revision) . '%'));
+        if (count($commit_rows) > 1) {
+            $db->rollback_transaction();
+            exit_with_error('AmbiguousRevision', $commit_info);            
+        } else if (!$commit_rows) {
             $db->rollback_transaction();
             exit_with_error('CommitNotFound', $commit_info);
         }
-        $commit_id = $commit_row['commit_id'];
+
+        $commit_id = $commit_rows[0]['commit_id'];
 
         $association = array('task' => $analysis_task_id, 'commit' => $commit_id, 'is_fix' => Database::to_database_boolean($kind == 'fix'));
         $commit_id = $db->update_or_insert_row('task_commits', 'taskcommit',