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
|
*.log
|
||||||
lib/source/*
|
lib/source/*
|
||||||
lib/signularity_revisions*
|
lib/singularity_revisions*
|
||||||
50
index.php
50
index.php
@@ -13,16 +13,11 @@ function parse_email($email)
|
|||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_changes($current, $next)
|
function print_changeset($row)
|
||||||
{
|
{
|
||||||
global $DB;
|
$author = parse_email($row["author"]);
|
||||||
if ($res = $DB->query(kl_str_sql("select * from revs where id<=!i and id>!i", $current->nr, $next->nr))) {
|
$gid = md5($author["email"]);
|
||||||
print '<table style="width: 100%;">';
|
print '
|
||||||
|
|
||||||
while ($row = $DB->fetchRow($res)) {
|
|
||||||
$author = parse_email($row["author"]);
|
|
||||||
$gid = md5($author["email"]);
|
|
||||||
print '
|
|
||||||
<tr>
|
<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 />' .
|
<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>
|
htmlspecialchars($author["name"]) . '</td>
|
||||||
@@ -33,8 +28,43 @@ function print_changes($current, $next)
|
|||||||
<tr>
|
<tr>
|
||||||
<td colspan="2" width="99%"><pre>' . htmlspecialchars($row["message"]) . '</pre></td>
|
<td colspan="2" width="99%"><pre>' . htmlspecialchars($row["message"]) . '</pre></td>
|
||||||
</tr>';
|
</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>';
|
print '</table>';
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class DBH
|
|||||||
$this->db_user = $db_user;
|
$this->db_user = $db_user;
|
||||||
$this->db_host = $db_host;
|
$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) {
|
if (!$this->dbh) {
|
||||||
DBH::log("[error] connection to database failed: $error_msg");
|
DBH::log("[error] connection to database failed: $error_msg");
|
||||||
|
|||||||
@@ -12,81 +12,111 @@ if (PHP_SAPI != "cli") {
|
|||||||
define("SITE_ROOT", realpath(dirname(__file__) . "/.."));
|
define("SITE_ROOT", realpath(dirname(__file__) . "/.."));
|
||||||
require_once SITE_ROOT . "/lib/init.php";
|
require_once SITE_ROOT . "/lib/init.php";
|
||||||
|
|
||||||
function import_rev($id, $hash)
|
function import_rev($raw)
|
||||||
{
|
{
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
print "Importing revision number $id with hash $hash\n";
|
$log = explode("\n", rtrim($raw));
|
||||||
$log = explode("\n", rtrim(`git log -n1 $hash`));
|
|
||||||
|
|
||||||
|
$hash = $log[0];
|
||||||
$author = "";
|
$author = "";
|
||||||
if (preg_match("|Author:\\s*(.*)|i", $log[1], $m)) {
|
|
||||||
$author = $m[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
$date = "";
|
$date = "";
|
||||||
if (preg_match("|Date:\\s*(.*)|i", $log[2], $m)) {
|
|
||||||
$date = strtotime($m[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$msg = "";
|
$msg = "";
|
||||||
|
$inMsg = false;
|
||||||
$nrLog = count($log);
|
$nrLog = count($log);
|
||||||
for ($i=4; $i<$nrLog; $i++) {
|
|
||||||
$msg .= substr($log[$i], 4);
|
for ($i=0; $i<$nrLog; $i++) {
|
||||||
if ($i<$nrLog-1) {
|
if ($inMsg) {
|
||||||
$msg .= "\n";
|
$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(
|
$DB->query(
|
||||||
kl_str_sql(
|
kl_str_sql(
|
||||||
"insert into revs (id, hash, author, time, message) values (!i, !s, !s, !t, !s)",
|
"insert into revs (hash, author, time, message) values (!s, !s, !t, !s)",
|
||||||
$id, $hash, $author, $date, $msg));
|
$hash, $author, $date, $msg));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_source()
|
function save_build_changes($changes)
|
||||||
{
|
{
|
||||||
exec("git reset --hard", $out, $res);
|
global $DB;
|
||||||
if ($res) {
|
|
||||||
DBH::log("Command failed: ", implode("\n", $out));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
exec("git pull", $out, $res);
|
$DB->query("begin transaction");
|
||||||
if ($res) {
|
if (!($res = $DB->query("delete from changes"))) {
|
||||||
DBH::log("Command failed: ", implode("\n", $out));
|
$DB->query("create table changes (build integer, revisions text, primary key(build))");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
$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()
|
function update_revs()
|
||||||
{
|
{
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$revsStr = rtrim(`git rev-list HEAD | tac`);
|
$DB->query("begin transaction");
|
||||||
$revs = explode("\n", $revsStr);
|
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);
|
$nrRevs = count($revs);
|
||||||
|
|
||||||
|
print "Importing $nrRevs revisions\n";
|
||||||
|
|
||||||
$latest = 0;
|
for ($i=0; $i<$nrRevs; $i++) {
|
||||||
$res = $DB->query("select max(id) as id from revs");
|
import_rev($revs[$i]);
|
||||||
if ($row = $DB->fetchRow($res)) {
|
}
|
||||||
if ($DB->loadFromDbRow($dbLatest, $res, $row)) {
|
|
||||||
$latest = (int)$dbLatest->id;
|
$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";
|
save_build_changes($changesAt);
|
||||||
print "Latest revision in the database: $latest\n";
|
|
||||||
|
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()
|
function update_builds()
|
||||||
@@ -123,8 +153,9 @@ function update_builds()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$DB->query("PRAGMA synchronous = OFF");
|
||||||
chdir(SITE_ROOT . "/lib/source");
|
chdir(SITE_ROOT . "/lib/source");
|
||||||
update_source();
|
exec("git fetch --all");
|
||||||
update_revs();
|
update_revs();
|
||||||
|
|
||||||
chdir(SITE_ROOT);
|
chdir(SITE_ROOT);
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ if (!defined('IMG_ROOT')) {
|
|||||||
|
|
||||||
$DB = new DBH();
|
$DB = new DBH();
|
||||||
|
|
||||||
$DB_NAME = SITE_ROOT . '/lib/signularity_revisions.db';
|
$DB_NAME = SITE_ROOT . '/lib/singularity_revisions.db';
|
||||||
/* $DB_USER = 'gigaprims';
|
/* $DB_USER = 'gigaprims';
|
||||||
$DB_PASS = 'secrit';
|
$DB_PASS = 'secrit';
|
||||||
$DB_HOST = 'localhost';
|
$DB_HOST = 'localhost';
|
||||||
|
|||||||
Reference in New Issue
Block a user