diff options
author | Simone Rota <sip@crux.nu> | 2006-10-16 17:36:42 +0200 |
---|---|---|
committer | Simone Rota <sip@crux.nu> | 2006-10-16 17:36:42 +0200 |
commit | 2ed0d688f0f862a2ad70fc4e68ae2f39394eb6c3 (patch) | |
tree | ec31633f774d26b92b75b2442946547844c53f71 | |
parent | c64a840e6459a94542ee663685c194a02fe70ba3 (diff) | |
download | webtools-2ed0d688f0f862a2ad70fc4e68ae2f39394eb6c3.tar.gz webtools-2ed0d688f0f862a2ad70fc4e68ae2f39394eb6c3.tar.xz |
timeline: added caching for git repos
-rwxr-xr-x | timeline/tlcacher.php | 93 |
1 files changed, 92 insertions, 1 deletions
diff --git a/timeline/tlcacher.php b/timeline/tlcacher.php index dbc18b3..69dd30f 100755 --- a/timeline/tlcacher.php +++ b/timeline/tlcacher.php @@ -25,6 +25,14 @@ $svnlook_cmd = "/usr/bin/svnlook"; // Url of the online repo viewer $svn_url = "http://crux.nu/svnweb/CRUX/revision/?rev=%s"; +// Gitweb url for commits +$git_url = "http://crux.nu/gitweb/?p=%s.git;a=commitdiff;h=%s"; +// append "*" to the repo name to restrict logs to $crux_version +$git_repos = array("core","opt","webtools"); +$crux_version = "2.2"; +$git_root = "/home/crux/scm"; + + // Path of the recent changes pmwiki file $wiki_file = "/home/crux/public_html/wiki.d/Site.AllRecentChanges"; @@ -43,6 +51,20 @@ $username_map = array( "aon" => "AnttiNykänen", ); +// Map git authors to wiki profiles +$git_username_map = array( + "Per Lidén" => "PerLiden", + "Matt Housh" => "jaeger", + "Juergen Daubert" => "JuergenDaubert", + "Johannes Winkelmann" => "JohannesWinkelmann", + "Simone Rota" => "SimoneRota" , + "Jason Thomas Dolan" => "JasonThomasDolan", + "Jukka Heino" => "JukkaHeino", + "Tilman Sauerbeck" => "TilmanSauerbeck", + "Simon Gloßner" => "SimonGloßner", + "Nick Steeves" => "NickSteeves", + "Antti Nykänen" => "AnttiNykänen", +); // Event: cache_id, tstamp, type(icon), date, time, user, url, description, notes $events = array(); @@ -78,6 +100,21 @@ if ($res->numRows() === 0) { $row =& $res->fetchRow(); $last_wiki = $row['cache_id']; } + +function last_cached_git($repo) { + global $dbc; + $last_cached_sql = "select cache_id from events where event_type='git_commit_$repo' order by event_tstamp desc"; + $res =& $dbc->limitQuery($last_cached_sql,0,1); + if (DB::isError($res)) die("Query error"); + if ($res->numRows() === 0) { + $last_git = ""; + } else { + $row =& $res->fetchRow(); + $last_git = $row['cache_id']; + } + return $last_git; +} + /**************** Flyspray events ***********************/ $db =& DB::connect($dsn); @@ -216,11 +253,65 @@ if ($chline != "") { } } +/******************* Git events ***********************/ + +foreach ($git_repos as $repo) { + $last_git = last_cached_git(str_replace('*',"", $repo)); + $branch = ""; + $out = array(); + $res = 0; + $done = array(); + if (strpos('*', $repo) !== FALSE) + $branch = $crux_version; + $repo = str_replace('*', '', $repo); + exec("GIT_DIR=$git_root/$repo.git git log -n 1 $branch", $out, $res); + $git_latest = trim(str_replace("commit ", "", $out[0])); + unset($out); + $res = 0; + if ($git_latest != $last_git) { + if ($last_git == "") { + exec("GIT_DIR=$git_root/$repo.git git log $branch", $out, $res); + } else { + exec("GIT_DIR=$git_root/$repo.git git log $last_git..$git_latest $branch", $out, $res); + } + $last_git = $git_latest; + foreach ($out as $line) { + if (substr($line, 0, 7) == "commit ") { + $rev = substr($line, 7); + $url = sprintf($git_url, $repo, $rev); + $compact_rev = substr($rev,0,4)."..".substr($rev,-4,4); + $revurl = "[[$url|$compact_rev]]"; + } else if (substr($line, 0, 8) == "Author: ") { + $user = substr($line, 8); + $pos = strpos($user, "<"); + if ($pos !== FALSE) + $user = trim(substr($user,0,$pos)); + if (array_key_exists($user, $git_username_map)) { + $wikiname = $git_username_map[$user]; + $user = "[[~" . $wikiname . "|" . $user . "]]"; + } + $description = "$revurl committed by $user"; + } else if (substr($line, 0, 8) == "Date: ") { + $date = substr($line, 8); + $tstamp = strtotime($date); + $date = date("Y-m-d", $tstamp); + $time = date("H:i", $tstamp); + } else if (trim($line) != "" && !array_key_exists($rev, $done)) { + $icon = "git_commit_$repo"; + $notes = trim($line); + $events[] = array( 'cache_id' => $rev, 'tstamp' => $tstamp, 'icon' => $icon, 'date' => $date, + 'time' => $time, 'user' => $user, 'url'=>$url, 'description' => $description, 'notes' => $notes); + $done[$rev] = 1; + } + } + } +} + /*************** Finally, all events *********************/ $sth = $dbc->prepare("insert into events values (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); foreach ($events as $evt) { $res = $dbc->execute($sth, $evt); - if (DB::isError($res)) die("Query error"); + if (DB::isError($res)) die ("Query error"); } ?> |