if(file_exists("$WEB_ROOT_FS/../gwvpmini/gwvpmini.php")) require_once("$WEB_ROOT_FS/../gwvpmini/gwvpmini.php");
else if(file_exists("/usr/share/gwvpmini/lib/gwvpmini/gwvpmini.php")) require_once("/usr/share/gwvpmini/lib/gwvpmini/gwvpmini.php");
-if(isset($argv["1"])) {
- switch($argv["1"]) {
+
+echo "ARGS: ".print_r($argv,true);
+echo "CWD: ".getcwd()."\n";
+
+if(isset($argv["3"])) {
+ switch($argv["3"]) {
case "update":
gwvpcmdtool_UpdateHook();
break;
return;
+/*
+ * remote: ARGS: Array
+remote: (
+remote: [0] => /nfs/export/src/local/eclipse-workspace/gwvp-mini/bin/gwvpminicmdtool.php
+remote: [1] => asfd
+remote: [2] => admin
+remote: [3] => pre-receive
+remote: [4] => fc781c4ef5bfeae8ec01bb527db1b6ce6f65d03c
+remote: [5] => 7d45d43f04276fc9addb77ba8bf753329eab018d
+remote: [6] => refs/heads/master
+remote: )
+remote: ARGS: Array
+remote: (
+remote: [0] => /nfs/export/src/local/eclipse-workspace/gwvp-mini/bin/gwvpminicmdtool.php
+remote: [1] => asfd
+remote: [2] => admin
+remote: [3] => pre-receive
+remote: [4] => /nfs/export/src/local/eclipse-workspace/gwvp-mini/bin/gwvpminicmdtool.php
+remote: [5] => asfd
+remote: [6] => admin
+remote: [7] => update
+remote: [8] => refs/heads/master
+remote: [9] => fc781c4ef5bfeae8ec01bb527db1b6ce6f65d03c
+remote: [10] => 7d45d43f04276fc9addb77ba8bf753329eab018d
+
+ */
+
function gwvpcmdtool_Usage()
{
global $argv;
- echo "Usage: ".$argv[0]."\n";
- echo "\tupdatehook <user> <ref> <firstupdate> <lastupdate>\n";
+ echo "Usage: ".$argv[0]." this tool should not be called directly by user\n";
}
{
global $argv;
//echo "got ".$argv[2].", ".$argv[3].", ".$argv[4]."\n";
- if(preg_match("/^000000+$/", $argv[3])) {
+ if(preg_match("/^000000+$/", $argv[5])) {
// createion of tag or branch
- $vals = explode("/", $argv[2]);
+ $vals = explode("/", $argv[4]);
$type = "unknowncreate";
- if($vals == "heads") $type = "branchcreate";
- if($vals == "tags") $type = "tagcreate";
- gwvpmini_AddActivityLog("$type", "1", "1", $argv[4], "somelogs");
+ if($vals[1] == "heads") $type = "branchcreate";
+ if($vals[1] == "tags") $type = "tagcreate";
+
+ //gwvpmini_AddRefActivityForRepo();
+ gwvpmini_AddRefActivityForRepo($argv[1], $argv[2], $vals[2], $type);
+ echo "REFSUP: ".$vals[2].", $type\n";\r
+
}
//gwvpmini_AddActivityLog($type, $userid, $repoid, $commitid, $commitlog)
+ //gwvpmini_AddRefActivityForRepo($reponame, $byusername, $branchname, $acttype="branch")
}
// pre-receive logs all commit info
//echo "got from prereceive ".$argv[2].", ".$argv[3].", ".$argv[4]."\n";\r
- //passthru("git rev-list --reverse ".$argv[3]." --not --all ");
+ $lns = 0;
+ $ref = $argv[6];
+
+ $regspl = explode("/", $ref);
+ $branch = $regspl[2];
+
+ $fp = popen("git rev-list --reverse ".$argv[5]." --not --all ", "r");
+ if($fp) while(!feof($fp)) {
+ $line = trim(fgets($fp));
+ if($line != "") {
+ $cdd[$lns] = gwvpcmdtool_getCommitIdDetails($line);
+ echo "FORCID $line we get \n".print_r($cdd[$lns], true);
+ gwvpmini_AddCommitActivityForRepo($argv[1], $argv[2], $line, $cdd[$lns]["log"], $branch);
+ $lns++;
+ }
+ }
+
+
+ //echo "Called git rev-list --reverse ".$argv[5]." --not --all\n\n";
+ //gwvpmini_AddCommitActivityForRepo($reponame, $byusername, $commitid, $desc)
+}
+
+function gwvpcmdtool_getCommitIdDetails($commitid)
+{
+ $rs = popen("git log --pretty=format:\"%at%n%ce%n%an%n%s\" $commitid -1 2> /dev/null", "r");
+ $ret = array();\r
+ if($rs) {\r
+ $ret["date"] = trim(fgets($rs));\r
+ $ret["email"] = trim(fgets($rs));\r
+ $ret["fullname"] = trim(fgets($rs));
+ $ret["log"] = "";\r
+ while(!feof($rs)) {\r
+ $ret["log"] .= fread($rs, 8192);\r
+ }\r
+ } else {
+ $ret = false;
+ }
+
+ return $ret;
}
?>
\ No newline at end of file
<?php
+global $HOME_PAGE_PROVIDERS;\r
+\r
+\r
+$HOME_PAGE_PROVIDERS["10activity"] = "gwvpmini_HomePageActivityLog";\r
if($IS_WEB_REQUEST) {
$activityloglength = true;\r
} else {\r
$activityloglength = false;\r
- }\r
+ }
+
+ global $activity_log_length;\r
} \r
// this will add a repo activity (a commit for eg)
// and auto populate the field in the activity
// log
-function gwvpmini_AddActivityForRepo($desc, $userbyid)
+function gwvpmini_AddCommitActivityForRepo($reponame, $byusername, $commitid, $desc, $branch)
{
+ // gwvpmini_AddActivityLog($type, $userid, $repoid, $commitid, $commitlog, $visibleto="a")
+ $rid = gwvpmini_GetRepoId($reponame);
+ $uid = gwvpmini_GetUserId($byusername);
+
+ if($rid < 1 || $uid < 1) return false;
+
+ $vis = gwvpmini_GetVisibilityForRepo($rid);
+ gwvpmini_AddActivityLog("commit", $uid, $rid, "$branch:$commitid", $desc, $vis);
+}
+
+function gwvpmini_AddRefActivityForRepo($reponame, $byusername, $branchname, $acttype="branch")
+{
+ $rid = gwvpmini_GetRepoId($reponame);\r
+ $uid = gwvpmini_GetUserId($byusername);\r
+ \r
+ if($rid < 1 || $uid < 1) return false;
+
+ $vis = gwvpmini_GetVisibilityForRepo($rid);
+ \r
+ gwvpmini_AddActivityLog("refs", $uid, $rid, "$acttype:$branchname", "", $vis);
+}
+
+function gwvpmini_GetVisibilityForRepo($repoid)
+{
+ $perms = gwvpmini_GetRepoPerms($repoid);
+ $dets = gwvpmini_getRepo($repoid);
+ $oid = $dets["ownerid"];
+
+ if($perms["b"] == "a") return "a";
+ if($perms["b"] == "r") return "r";
+
+ $st = ":$oid:";
+ foreach($perms as $key => $val) {
+ if($key!="b") $st .= "$key:";
+ }
+ return $st;
}
// gets the activity log as it would be viewed by
// the user id of "$forid"
-function gwvpmini_GetActivityLogFor($forid)
+function gwvpmini_HomePageActivityLog()
+{
+ global $BASE_URL;
+
+ $id = $_SESSION["id"];
+
+ if($id < 0) {
+ $ents = gwvpmini_GetActivityLog();
+ } else {
+ $ents = gwvpmini_GetActivityLog(20, $id);
+ }
+
+ echo "<h2>News</h2>";
+ echo "<table border=\"1\">";
+ foreach($ents as $vals) {
+ /*
+ * $ret[$nent]["type"] = $vals["activity_type"];
+ $ret[$nent]["date"] = $vals["activity_date"];
+ $ret[$nent]["userid"] = $vals["activity_user"];
+ $ret[$nent]["repoid"] = $vals["activity_repo"];
+ $ret[$nent]["commitid"] = $vals["activity_commitid"];
+ $ret[$nent]["commitlog"] = $vals["activitiy_commitlog"];
+
+ */
+ $type = $vals["type"];
+ //$rest = $vals["date"].", ".$vals["userid"].", ".$vals["repoid"].", ".$vals["commitid"].", ".$vals["commitlog"];
+
+ if($vals["type"] == "commit") {
+ $udets = gwvpmini_getUser(null, null, $vals["userid"]);
+ $rdets = gwvpmini_getRepo(null, null, $vals["repoid"]);
+ $reponame = $rdets["name"];
+ $uname = $udets["username"];
+ $fname = $udets["fullname"];
+ $br_spl = explode(":", $vals["commitid"]);
+ $branch = $br_spl[0];
+ $cid = $br_spl[1];
+ $compressedcid = gwvpmini_CompressCommitId($cid);
+ $log = $vals["commitlog"];
+ $tdiff = gwvpmini_TimeDiffText($vals["date"]);
+ $col1 = "<font size=\"+1\"><a href=\"$BASE_URL/view/$reponame\">$reponame</a></font><br>".gwvpmini_HtmlGravatar($udets["email"], 30, "<br>")."<a href=\"$BASE_URL/user/$uname\">$uname</a>";
+ $col2 = $tdiff."<br>Commited change <b>$compressedcid</b><br><table border=\"1\"><tr><td bgcolor=\"#eeeeee\"><pre>$log</pre></td></tr></table><br>";
+ } else if($vals["type"] == "refs") {
+ $udets = gwvpmini_getUser(null, null, $vals["userid"]);\r
+ $rdets = gwvpmini_getRepo(null, null, $vals["repoid"]);\r
+ $reponame = $rdets["name"];\r
+ $uname = $udets["username"];\r
+ $fname = $udets["fullname"];
+ $tdiff = gwvpmini_TimeDiffText($vals["date"]);
+ $tp_spl = explode(":", $vals["commitid"]);
+ $col1 = "<font size=\"+1\"><a href=\"$BASE_URL/view/$reponame\">$reponame</a></font><br>".gwvpmini_HtmlGravatar($udets["email"], 30, "<br>")."<a href=\"$BASE_URL/user/$uname\">$uname</a>";
+ if($tp_spl[0] == "tagcreate") {
+ $colapp = "$tdiff<br>Created Tag <b>".$tp_spl[1]."</b>";
+ } else if($tp_spl[0] == "branchcreate") {
+ $colapp = "$tdiff<br>Created Branch <b>".$tp_spl[1]."</b>";
+ } else {
+ $colapp = "$tdiff<br>Performed some unknown action.";
+ }
+ $col2 = $colapp;
+
+ }
+
+ echo "<tr><td>$col1</td><td>$col2</td></tr>";
+ }
+ echo "</table>";
+}
+
+function gwvpmini_TimeDiffText($time)
{
+ $tdiff = time() - $time;
+ if($tdiff < 10) return "Now";
+ if($tdiff < 60) return "$tdiff Seconds Ago";
+ if($tdiff < 3600) return "".(int)($tdiff/60)." Minutes Ago";
+ if($tdiff < 86400) return "".(int)($tdiff/3600)." Hours Ago";
+ return "".(int)($tdiff/86400)." Days Ago";
}
?>
\ No newline at end of file
\r
}
+function gwvpmini_GetActivityLog($nentries = 20, $forid=-1)
+{
+ /*
+ * "activity_id" INTEGER PRIMARY KEY AUTOINCREMENT,
+ "activity_type" TEXT,
+ "activity_date" TEXT,
+ "activity_user" TEXT,
+ "activity_repo" TEXT,
+ "activity_commitid" TEXT,
+ "activity_commitlog" TEXT,
+ "activity_visibleto" TEXT
+
+ */
+ $conn = gwvpmini_ConnectDB();\r
+
+ if($forid == -1) {
+ // we're searching for anonymous ones
+ $sql = "select * from activity where activity_visibleto='a' order by activity_date desc limit $nentries";
+ } else {
+ $sql = "select * from activity where activity_visibleto='a' or activity_visibleto='r' or activity_visibleto like '%:$forid:%' order by activity_date desc limit $nentries";
+ }
+
+ $vls = $conn->query($sql);
+
+ $nent = 0;
+ $ret = array();
+ if($vls !== false) foreach($vls as $vals) {
+ $ret[$nent]["type"] = $vals["activity_type"];
+ $ret[$nent]["date"] = $vals["activity_date"];
+ $ret[$nent]["userid"] = $vals["activity_user"];
+ $ret[$nent]["repoid"] = $vals["activity_repo"];
+ $ret[$nent]["commitid"] = $vals["activity_commitid"];
+ $ret[$nent]["commitlog"] = $vals["activity_commitlog"];
+ $nent++;
+ }
+
+ if($nent == 0) return false;
+ else return $ret;
+}
+
function gwvpmini_getRepo($ownerid=null, $name=null, $id=null)\r
{\r
return $retval;
}\r
-function gwvpmini_GetActivityLog($nentries = 100)
-{
- $conn = gwvpmini_ConnectDB();\r
-
- $sql = "select * from activity order by activity_date desc limit 100";
-
- $res = $conn->query($sql);
-
- $logs = null;
- $i = 0;
- foreach($res as $row) {
- $logs[$i]["type"] = $row["activity_type"];
- $logs[$i]["date"] = $row["activity_date"];
- $logs[$i]["userid"] = $row["activity_user"];
- $logs[$i]["repoid"] = $row["activity_repo"];
- $logs[$i]["commitid"] = $row["activity_commitid"];
- $logs[$i]["commitlog"] = $row["activity_commitlog"];
- $logs[$i]["visibleto"] = $row["activity_visibleto"];
- $i++;
- }
-
- return $logs;
-}
-
-function gwvpmini_AddActivityLog($type, $userid, $repoid, $commitid, $commitlog)
+function gwvpmini_AddActivityLog($type, $userid, $repoid, $commitid, $commitlog, $visibleto="a")
{
/*
* CREATE TABLE "activity" (
$conn = gwvpmini_ConnectDB();
// TODO: implement visibility
- $visibleto = "a";\r
+ //$visibleto = "a";\r
\r
$sql = "insert into 'activity' values ( null, '$type', '".time()."', '$userid', '$repoid', '$commitid', '$commitlog', '$visibleto')";
}
-function gwvpmini_CreateRepoHooks($repopath, $cmdpath)
+function gwvpmini_CreateRepoHooks($repopath, $cmdpath, $reponame)
{
$fp = fopen("$repopath/hooks/pre-receive", "w");
- if(!$fp) // error_log("could not create pre-receive hook");
+ if(!$fp) error_log("could not create pre-receive hook");
// TODO: think about this one
- $script = '#!/bin/bash'."\n\n".'DCOMMIT=`cat`'."\n".'START=`echo $DCOMMIT|cut -d " " -f 1`'."\n".'END=`echo $DCOMMIT|cut -d " " -f 2`'."\n".'REF=`echo $DCOMMIT|cut -d " " -f 3`'."\n\n";
- $script .= "php $cmdpath pre-receive ";
- $script .= '$START $END $REF'."\n\n";
+ //$script = '#!/bin/bash'."\n\n".'DCOMMIT=`cat`'."\n".'START=`echo $DCOMMIT|cut -d " " -f 1`'."\n".'END=`echo $DCOMMIT|cut -d " " -f 2`'."\n".'REF=`echo $DCOMMIT|cut -d " " -f 3`'."\n\n";
+ $script = "#!/bin/bash\n\nDCOMMIT=".'`cat`'."\n\nphp $cmdpath $reponame \$REMOTE_USER pre-receive \$DCOMMIT\n\n";
fwrite($fp, $script);
fclose($fp);
$fp = fopen("$repopath/hooks/update", "w");
- if(!$fp) // error_log("could not create update hook");
+ if(!$fp) error_log("could not create update hook");
// TODO: think about this one
- $script = "#!/bin/bash\n\n";
- $script .= "php $cmdpath update ";
- $script .= '$1 $2 $3'."\n\n";
+ unset($script);
+ $script = "#!/bin/bash\n\nphp $cmdpath $reponame \$REMOTE_USER update \$1 \$2 \$3\n\n";
fwrite($fp, $script);
fclose($fp);
// error_log("FLAP: donut hole");
}*/
-
+ error_log("REQUESTINBACKEND: ".print_r($_REQUEST, true));
$repo = "";
$repoid = false;
if(!file_exists("$repo_base/$repo.git/hooks/pre-receive") || !file_exists("$repo_base/$repo.git/hooks/update")) {
// error_log("WRITING HOOKS");
- gwvpmini_CreateRepoHooks("$repo_base/$repo.git", $cmd_line_tool);
+ gwvpmini_CreateRepoHooks("$repo_base/$repo.git", $cmd_line_tool, $repo);
}
$write = true;
}
}
-
+ if(preg_match("/.*git-receive-pack$/", $_REQUEST["q"])) $write = true;
//$write = true;
// THIS MAY CAUSE ISSUES LATER ON but we do it cause the git client ignores our 403 when it uses git-receive-pack after an auth
// no, this isnt a solution cause auth'd read attempts will come up as writes...
}
// if its a write, we check (before and after) the branch/tag info to see if they were updated
- //if($write) {
- //}
+ if($write) {
+ error_log("REQUESTINBACKEND: processed as write");
+ } else {
+ error_log("REQUESTINBACKEND: processed as read");
+ }
gwvpmini_callGitBackend($person, $repo);
$CALL_ME_FUNCTIONS["repoadmin"] = "gwvpmini_RepoCallMe";
-$HOME_PAGE_PROVIDERS["gitlog"] = "gwvpmini_GitLogProvider";\r
+$HOME_PAGE_PROVIDERS["00gitlog"] = "gwvpmini_GitLogProvider";\r
\r
\r
// the home_page_provders bit is an array\r
echo "</table>";
}\r
}
-
- $logs = gwvpmini_GetActivityLog();
- if($logs !== null) {
- echo "<h2>Global Log</h2><table>";
- foreach($logs as $ents) {
- echo "<tr><td>".$ents["type"]."</td><td>".$ents["commitid"]."</td></tr>";
- }
- echo "</table>";
- }
}
function gwvpmini_GitCreateRepoForm()
return @rmdir($fpath);\r
}
}
+
+function gwvpmini_CompressCommitId($cid)
+{
+ $compressedcid = substr($cid, 0, 5)."...".substr($cid, strlen($cid)-5, strlen($cid));
+
+ return $compressedcid;
+}
?>
\ No newline at end of file