Rewrite to use rather 'interesting' way to determine what has changes since the last build
This commit is contained in:
@@ -4,4 +4,4 @@ syntax: glob
|
||||
*~
|
||||
*.log
|
||||
lib/source/*
|
||||
lib/signularity_revisions*
|
||||
lib/singularity_revisions*
|
||||
50
index.php
50
index.php
@@ -13,16 +13,11 @@ function parse_email($email)
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function print_changes($current, $next)
|
||||
function print_changeset($row)
|
||||
{
|
||||
global $DB;
|
||||
if ($res = $DB->query(kl_str_sql("select * from revs where id<=!i and id>!i", $current->nr, $next->nr))) {
|
||||
print '<table style="width: 100%;">';
|
||||
|
||||
while ($row = $DB->fetchRow($res)) {
|
||||
$author = parse_email($row["author"]);
|
||||
$gid = md5($author["email"]);
|
||||
print '
|
||||
$author = parse_email($row["author"]);
|
||||
$gid = md5($author["email"]);
|
||||
print '
|
||||
<tr>
|
||||
<td rowspan="2" style="text-align: center;"><img src="http://www.gravatar.com/avatar/' . $gid . '?r=x&d=mm&s=64" alt="Avatar"/><br />' .
|
||||
htmlspecialchars($author["name"]) . '</td>
|
||||
@@ -33,8 +28,43 @@ function print_changes($current, $next)
|
||||
<tr>
|
||||
<td colspan="2" width="99%"><pre>' . htmlspecialchars($row["message"]) . '</pre></td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
# pre_dump($row);
|
||||
function sort_by_date($a, $b)
|
||||
{
|
||||
if ($a["time"] < $b["time"]) {
|
||||
return 1;
|
||||
} else if ($a["time"] > $b["time"]) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function print_changes($current, $next)
|
||||
{
|
||||
global $DB;
|
||||
$revs = array();
|
||||
if (!($res = $DB->query(kl_str_sql("select revisions from changes where build<=!i and build>!i order by build desc", $current->nr, $next->nr)))) {
|
||||
return;
|
||||
} else {
|
||||
while ($row = $DB->fetchRow($res)) {
|
||||
$revs = array_merge($revs, explode(",", $row["revisions"]));
|
||||
}
|
||||
}
|
||||
|
||||
if ($res = $DB->query("select * from revs where hash in ('" . implode("','", $revs) . "')")) {
|
||||
print '<table style="width: 100%;">';
|
||||
|
||||
$changesets = array();
|
||||
|
||||
while ($row = $DB->fetchRow($res)) {
|
||||
$changesets[] = $row;
|
||||
}
|
||||
|
||||
usort($changesets, "sort_by_date");
|
||||
|
||||
foreach ($changesets as $change) {
|
||||
print_changeset($change);
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
|
||||
@@ -38,7 +38,7 @@ class DBH
|
||||
$this->db_user = $db_user;
|
||||
$this->db_host = $db_host;
|
||||
|
||||
$this->dbh = @sqlite_popen($db_name, 0666, $error_msg);
|
||||
$this->dbh = @sqlite_open($db_name, 0666, $error_msg);
|
||||
|
||||
if (!$this->dbh) {
|
||||
DBH::log("[error] connection to database failed: $error_msg");
|
||||
|
||||
@@ -12,81 +12,111 @@ if (PHP_SAPI != "cli") {
|
||||
define("SITE_ROOT", realpath(dirname(__file__) . "/.."));
|
||||
require_once SITE_ROOT . "/lib/init.php";
|
||||
|
||||
function import_rev($id, $hash)
|
||||
function import_rev($raw)
|
||||
{
|
||||
global $DB;
|
||||
|
||||
print "Importing revision number $id with hash $hash\n";
|
||||
$log = explode("\n", rtrim(`git log -n1 $hash`));
|
||||
$log = explode("\n", rtrim($raw));
|
||||
|
||||
$hash = $log[0];
|
||||
$author = "";
|
||||
if (preg_match("|Author:\\s*(.*)|i", $log[1], $m)) {
|
||||
$author = $m[1];
|
||||
}
|
||||
|
||||
$date = "";
|
||||
if (preg_match("|Date:\\s*(.*)|i", $log[2], $m)) {
|
||||
$date = strtotime($m[1]);
|
||||
}
|
||||
|
||||
$msg = "";
|
||||
$inMsg = false;
|
||||
$nrLog = count($log);
|
||||
for ($i=4; $i<$nrLog; $i++) {
|
||||
$msg .= substr($log[$i], 4);
|
||||
if ($i<$nrLog-1) {
|
||||
$msg .= "\n";
|
||||
|
||||
for ($i=0; $i<$nrLog; $i++) {
|
||||
if ($inMsg) {
|
||||
$msg .= substr($log[$i], 4);
|
||||
if ($i<$nrLog-1) {
|
||||
$msg .= "\n";
|
||||
}
|
||||
} else {
|
||||
if (preg_match("|^author\\s*([^>]*>)\\s*([\\d]+)\\s*(.*)|i", $log[$i], $m)) {
|
||||
$author = $m[1];
|
||||
$date = (int)$m[2];
|
||||
} else if (!trim($log[$i])) {
|
||||
$inMsg = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$DB->query(
|
||||
kl_str_sql(
|
||||
"insert into revs (id, hash, author, time, message) values (!i, !s, !s, !t, !s)",
|
||||
$id, $hash, $author, $date, $msg));
|
||||
"insert into revs (hash, author, time, message) values (!s, !s, !t, !s)",
|
||||
$hash, $author, $date, $msg));
|
||||
|
||||
}
|
||||
|
||||
function update_source()
|
||||
function save_build_changes($changes)
|
||||
{
|
||||
exec("git reset --hard", $out, $res);
|
||||
if ($res) {
|
||||
DBH::log("Command failed: ", implode("\n", $out));
|
||||
return;
|
||||
}
|
||||
global $DB;
|
||||
|
||||
exec("git pull", $out, $res);
|
||||
if ($res) {
|
||||
DBH::log("Command failed: ", implode("\n", $out));
|
||||
return;
|
||||
$DB->query("begin transaction");
|
||||
if (!($res = $DB->query("delete from changes"))) {
|
||||
$DB->query("create table changes (build integer, revisions text, primary key(build))");
|
||||
}
|
||||
$DB->query("commit");
|
||||
|
||||
$DB->query("begin transaction");
|
||||
foreach ($changes as $buildNr => $revs) {
|
||||
$DB->query(kl_str_sql("insert into changes (build, revisions) values (!i, !s)", $buildNr, implode(",", $revs)));
|
||||
}
|
||||
$DB->query("commit");
|
||||
|
||||
print implode("\n", $out) . "\n";
|
||||
}
|
||||
|
||||
function update_revs()
|
||||
{
|
||||
global $DB;
|
||||
|
||||
$revsStr = rtrim(`git rev-list HEAD | tac`);
|
||||
$revs = explode("\n", $revsStr);
|
||||
$DB->query("begin transaction");
|
||||
if (!($res = $DB->query("delete from revs"))) {
|
||||
$DB->query("create table revs(hash varchar, author varchar, time timestamp, message text, diff text, primary key(hash))");
|
||||
}
|
||||
|
||||
$DB->query("commit");
|
||||
|
||||
$DB->query("begin transaction");
|
||||
$revs = array_reverse(explode(chr(0), rtrim(`git rev-list HEAD --header`)));
|
||||
$nrRevs = count($revs);
|
||||
|
||||
print "Importing $nrRevs revisions\n";
|
||||
|
||||
$latest = 0;
|
||||
$res = $DB->query("select max(id) as id from revs");
|
||||
if ($row = $DB->fetchRow($res)) {
|
||||
if ($DB->loadFromDbRow($dbLatest, $res, $row)) {
|
||||
$latest = (int)$dbLatest->id;
|
||||
for ($i=0; $i<$nrRevs; $i++) {
|
||||
import_rev($revs[$i]);
|
||||
}
|
||||
|
||||
$res = $DB->query("commit");
|
||||
|
||||
$revs = explode("\n", rtrim(`git rev-list HEAD`));
|
||||
|
||||
$res = 0;
|
||||
$c =0;
|
||||
$changesAt = array();
|
||||
|
||||
while (true) {
|
||||
exec("git reset --soft HEAD~ 2>&1", $out, $res);
|
||||
if ($res != 0) {
|
||||
break;
|
||||
} else {
|
||||
$c++;
|
||||
$newRevs = explode("\n", rtrim(`git rev-list HEAD`));
|
||||
$changes = array_diff($revs, $newRevs);
|
||||
$nrChanges = count($changes);
|
||||
$build = count($revs);
|
||||
$revs = $newRevs;
|
||||
$changesAt[$build] = $changes;
|
||||
print $nrChanges . " changes in build $build\n";
|
||||
if ($build < 2169) break; // this is when we started building
|
||||
}
|
||||
}
|
||||
|
||||
print "Found $nrRevs revisions\n";
|
||||
print "Latest revision in the database: $latest\n";
|
||||
save_build_changes($changesAt);
|
||||
|
||||
print "Number resets: $c\n";
|
||||
exec("git fetch --all 2>&1");
|
||||
|
||||
if ($latest < $nrRevs) {
|
||||
for ($rev = $latest + 1; $rev <= $nrRevs; $rev++) {
|
||||
import_rev($rev, $revs[$rev - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function update_builds()
|
||||
@@ -123,8 +153,9 @@ function update_builds()
|
||||
|
||||
}
|
||||
|
||||
$DB->query("PRAGMA synchronous = OFF");
|
||||
chdir(SITE_ROOT . "/lib/source");
|
||||
update_source();
|
||||
exec("git fetch --all");
|
||||
update_revs();
|
||||
|
||||
chdir(SITE_ROOT);
|
||||
|
||||
@@ -56,7 +56,7 @@ if (!defined('IMG_ROOT')) {
|
||||
|
||||
$DB = new DBH();
|
||||
|
||||
$DB_NAME = SITE_ROOT . '/lib/signularity_revisions.db';
|
||||
$DB_NAME = SITE_ROOT . '/lib/singularity_revisions.db';
|
||||
/* $DB_USER = 'gigaprims';
|
||||
$DB_PASS = 'secrit';
|
||||
$DB_HOST = 'localhost';
|
||||
|
||||
Reference in New Issue
Block a user