adding the ability to clone from an existing source to create a new repo
authorPaul J R <me@pjr.cc>
Tue, 2 Oct 2012 03:51:59 +0000 (13:51 +1000)
committerPaul J R <me@pjr.cc>
Tue, 2 Oct 2012 03:51:59 +0000 (13:51 +1000)
gwvpmini/gwvpmini_db.php
gwvpmini/gwvpmini_gitbackend.php
gwvpmini/gwvpmini_gitrepo.php

index 82abfda..d3d1057 100644 (file)
@@ -532,6 +532,7 @@ function gwvpmini_dbCreateSQLiteStructure($dbloc)
        "repos_owner" INTEGER,
        "repos_perms" TEXT,
        "repos_status" TEXT,
+       "repos_origin" TEXT,
        UNIQUE(repos_name)\r
        )';\r
 \r
@@ -752,7 +753,7 @@ function gwvpmini_setConfigVal($confname, $confval)
        return $conn->query($sql);\r
 }
 
-function gwvpmini_AddRepo($name, $desc, $ownerid)
+function gwvpmini_AddRepo($name, $desc, $ownerid, $clonefrom)
 {
        
        // error_log("addrepo in db for $name, $desc, $ownerid");
@@ -761,8 +762,10 @@ function gwvpmini_AddRepo($name, $desc, $ownerid)
        $perms["b"] = "a";
        
        $encperms = base64_encode(serialize($perms));
+       
+       if($clonefrom === false) $clonefrom = "";
        \r
-       $sql = "insert into repos values (null, '$name', '$desc', '$ownerid', '$encperms', 0)";\r
+       $sql = "insert into repos values (null, '$name', '$desc', '$ownerid', '$encperms', 0, '$clonefrom')";\r
        \r
        $conn->query($sql);\r
 }
index 8e4dc5f..f55038c 100644 (file)
@@ -413,7 +413,7 @@ 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)
+function gwvpmini_createGitRepo($name, $ownerid, $desc, $clonefrom)
 {
        $repo_base = gwvpmini_getConfigVal("repodir");
        
@@ -424,7 +424,7 @@ function gwvpmini_createGitRepo($name, $ownerid, $desc)
        exec("/usr/bin/git update-server-info");
 
        // gwvpmini_AddRepo($reponame, $repodesc, $repoowner, $defaultperms = 0)
-       gwvpmini_AddRepo($name, $desc, $ownerid);
+       gwvpmini_AddRepo($name, $desc, $ownerid, $clonefrom);
        
        return true;
 }
index 46c4f95..6584109 100644 (file)
@@ -186,6 +186,7 @@ function gwvpmini_GitCreateRepoForm()
        echo "<option value=\"perms-registered\">Must be Registered To Read</option>";
        echo "<option value=\"perms-onlywrite\">Only Writers can Read</option>";
        echo "</select>";
+       echo "<tr><th>Clone From</th><td><input type=\"text\" name=\"clonefrom\"></td></tr>";
        echo "</td></tr>";
        echo "<tr><td colspan=\"2\"><input type=\"submit\" name=\"Create\" value=\"Create\"></td></tr>";
        echo "</table>";
@@ -211,6 +212,13 @@ function gwvpmini_RepoCreate()
                $inputcheckerror = "Repo name contains invalid characters, repos can only contain a-z, A-Z, 0-9, _, - and .";
        }
        
+       $clonefrom = false;
+       if(isset($_REQUEST["clonefrom"])) {
+               if($_REQUEST["clonefrom"] != "") {
+                       $clonefrom = $_REQUEST["clonefrom"];
+               }
+       }
+       
        if(!$inputcheck) {
                gwvpmini_SendMessage("error", "$inputcheckerror");\r
                header("Location: $BASE_URL/repos");
@@ -220,7 +228,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"]);
+                       gwvpmini_createGitRepo($_REQUEST["reponame"], $_SESSION["id"], $_REQUEST["repodesc"], $_REQUEST["perms"], $clonefrom);
                        gwvpmini_SendMessage("info", "Repo ".$_REQUEST["reponame"]." has been created");
                        header("Location: $BASE_URL/repos");
                }