Added clone for non-remote
authorPaul J R <me@pjr.cc>
Wed, 24 Oct 2012 18:48:50 +0000 (05:48 +1100)
committerPaul J R <me@pjr.cc>
Wed, 24 Oct 2012 18:48:50 +0000 (05:48 +1100)
TODO [new file with mode: 0644]
gwvpmini/gwvpmini.php
gwvpmini/gwvpmini_activity.php
gwvpmini/gwvpmini_db.php
gwvpmini/gwvpmini_debug.php [new file with mode: 0644]
gwvpmini/gwvpmini_gitbackend.php
gwvpmini/gwvpmini_gitrepo.php

diff --git a/TODO b/TODO
new file mode 100644 (file)
index 0000000..f7211b8
--- /dev/null
+++ b/TODO
@@ -0,0 +1,16 @@
+First (for beta release):
+
+need a standard git log parser/collector deal
+need to add activity for repo creation
+get clone working properly
+put "system'd" stuff into variables
+
+Next:
+
+ability to git-view a source code base?
+Chat between people on the site - simplistic chat (or maybe just a simple form that'll send an email)
+
+Long term:
+
+link multiple sites together
+deal with pull's between forks of a repo
\ No newline at end of file
index 25642cb..0abc29f 100644 (file)
@@ -11,6 +11,7 @@ require_once("gwvpmini_view.php");
 require_once("gwvpmini_activity.php");
 require_once("gwvpmini_register.php");
 require_once("gwvpmini_user.php");
+require_once("gwvpmini_debug.php");
 // require_once("gwvpmini_chat.php"); TODO: disabling chat for now to work on more important interfaces first
 if($IS_WEB_REQUEST) {
        if(gwvpmini_isLoggedIn()) if(gwvpmini_isUserAdmin()) {
index 107cb48..a81a522 100644 (file)
@@ -71,7 +71,8 @@ function gwvpmini_HomePageActivityLog()
 {
        global $BASE_URL;
        
-       $id = $_SESSION["id"];
+       $id = -1;
+       if(isset($_SESSION["id"])) $id = $_SESSION["id"];
        
        if($id < 0) {
                $ents = gwvpmini_GetActivityLog();
@@ -81,7 +82,7 @@ function gwvpmini_HomePageActivityLog()
        
        echo "<h2>News</h2>";
        echo "<table border=\"1\">";
-       foreach($ents as $vals) {
+       if($ents != null) foreach($ents as $vals) {
                /*
                 *              $ret[$nent]["type"] = $vals["activity_type"];
                $ret[$nent]["date"] = $vals["activity_date"];
index d3d1057..8b3fd26 100644 (file)
@@ -753,13 +753,13 @@ function gwvpmini_setConfigVal($confname, $confval)
        return $conn->query($sql);\r
 }
 
-function gwvpmini_AddRepo($name, $desc, $ownerid, $clonefrom)
+function gwvpmini_AddRepo($name, $desc, $ownerid, $defperms, $clonefrom)
 {
        
        // error_log("addrepo in db for $name, $desc, $ownerid");
        $conn = gwvpmini_ConnectDB();\r
        
-       $perms["b"] = "a";
+       $perms["b"] = $defperms;
        
        $encperms = base64_encode(serialize($perms));
        
diff --git a/gwvpmini/gwvpmini_debug.php b/gwvpmini/gwvpmini_debug.php
new file mode 100644 (file)
index 0000000..80cf2e0
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+$CALL_ME_FUNCTIONS["debug"] = "gwvpmini_DebugCallMe";
+
+$MENU_ITEMS["99debug"]["text"] = "Debug";\r
+$MENU_ITEMS["99debug"]["link"] = "$BASE_URL/debug";\r
+
+
+function gwvpmini_DebugCallMe()\r
+{\r
+\r
+       // error_log("in admin callme");\r
+       if(isset($_REQUEST["q"])) {\r
+               $query = $_REQUEST["q"];\r
+               $qspl = explode("/", $query);\r
+               if(isset($qspl[0])) {\r
+                       if($qspl[0] == "debug") {
+                               return "gwvpmini_DebugPage";
+                       }\r
+               }
+       }
+       
+       return false;
+}      \r
+\r
+function gwvpmini_DebugPage()
+{
+       gwvpmini_goMainPage("gwvpmini_DebugPageBody");
+}
+
+function gwvpmini_DebugPageBody()
+{
+       echo "Dumping perms data:";
+       
+       $db = gwvpmini_ConnectDB();
+       
+       $res = $db->query("select * from repos");
+       foreach($res as $row) {
+               $repo = $row["repos_name"];
+               $perms = $row["repos_perms"];
+               echo "<br>Repo: $repo: <pre>";
+               print_r(unserialize(base64_decode($perms)));
+               echo "</pre>";
+       }
+}
+?>
\ No newline at end of file
index 5aeedcf..5a6c055 100644 (file)
@@ -107,7 +107,8 @@ function gwvpmini_gitBackendInterface()
        
        // we do an update server cause its weird and i cant figure out when it actually needs to happen
        chdir("$repo_base/$repo.git");
-       exec("/usr/bin/git update-server-info");
+       // dont believe i have to do this
+       //exec("/usr/bin/git update-server-info");
        
        if(!file_exists("$repo_base/$repo.git/hooks/pre-receive") || !file_exists("$repo_base/$repo.git/hooks/update")) {
                // error_log("WRITING HOOKS");
@@ -413,22 +414,25 @@ function gwvpmini_repoExists($name)
 // 0 - anyone can clone/read, only owner can write
 // 1 - noone can clone/read, repo is visible (i.e. name), only owner can read/write repo
 // 2 - only owner can see anything
-function gwvpmini_createGitRepo($name, $ownerid, $desc, $clonefrom)
+function gwvpmini_createGitRepo($name, $ownerid, $desc, $defperms, $clonefrom, $isremoteclone)
 {
        $repo_base = gwvpmini_getConfigVal("repodir");
        
        if($clonefrom !== false) {
-               
+               error_log("how did i end up in clonefrom? $clonefrom");
+               if(!$isremoteclone) {
+                       exec("/usr/bin/git clone --bare $repo_base/$clonefrom.git $repo_base/$name.git >> /tmp/gitlog 2>&1");
+               }
        } else {
        
        // phew, this works, but i tell you this - bundles arent quite as nice as they should be
        // error_log("would create $repo_base/$name.git");
-               exec("/usr/bin/git init $repo_base/$name.git --bare > /tmp/gitlog 2>&1");
+               exec("/usr/bin/git init $repo_base/$name.git --bare >> /tmp/gitlog 2>&1");
                chdir("$repo_base/$name.git");
                exec("/usr/bin/git update-server-info");
        
                // gwvpmini_AddRepo($reponame, $repodesc, $repoowner, $defaultperms = 0)
-               gwvpmini_AddRepo($name, $desc, $ownerid, $clonefrom);
+               gwvpmini_AddRepo($name, $desc, $ownerid, $defperms, $clonefrom);
        }
        
        return true;
index d642c92..ba00862 100644 (file)
@@ -232,11 +232,30 @@ function gwvpmini_RepoCreate()
        if($clonefrom !== false && $fromremote == false) {
                // check the local repo exists
                $rn = gwvpmini_getRepo(null, $clonefrom, null);
+               $uid = $_SESSION["id"];
+               
                if($rn == false) {
-                       gwvpmini_SendMessage("error", "local repo $clonefrom given as upstream clone, however $clonefrom doesnt exist on this site");
+                       gwvpmini_SendMessage("error", "local repo $clonefrom given as upstream clone, however $clonefrom doesnt exist on this site (or you cant read it)");
                        header("Location: $BASE_URL/repos");
                        return;
                }
+               
+               // resolve repo permissions on the read/clone
+               if(gwvpmini_GetRepoPerm($rn, $uid) < 1) {
+                       gwvpmini_SendMessage("error", "local repo $clonefrom given as upstream clone, however $clonefrom doesnt exist on this site (or you cant read it)");
+                       header("Location: $BASE_URL/repos");
+                       return;
+               }
+       }
+       
+       $defperms = "a";
+       switch($_REQUEST["perms"]) {
+               case "perms-registered":
+                       $defperms = "r";
+                       break;
+               case "perms-onlywrite":
+                       $defperms = "x";
+                       break;
        }
        
        if(!$inputcheck) {
@@ -248,7 +267,7 @@ function gwvpmini_RepoCreate()
                        gwvpmini_SendMessage("error", "Repo ".$_REQUEST["reponame"]." already exists");\r
                        header("Location: $BASE_URL/repos");
                } else {
-                       gwvpmini_createGitRepo($_REQUEST["reponame"], $_SESSION["id"], $_REQUEST["repodesc"], $_REQUEST["perms"], $clonefrom);
+                       gwvpmini_createGitRepo($_REQUEST["reponame"], $_SESSION["id"], $_REQUEST["repodesc"], $defperms, $clonefrom, $fromremote);
                        gwvpmini_SendMessage("info", "Repo ".$_REQUEST["reponame"]." has been created");
                        header("Location: $BASE_URL/repos");
                }