add scandir_replace function
authorStricted <Stricted@nexus-irc.de>
Fri, 14 Sep 2012 15:36:16 +0000 (17:36 +0200)
committerStricted <Stricted@nexus-irc.de>
Fri, 14 Sep 2012 15:37:53 +0000 (17:37 +0200)
git_download.php

index 16e1c861abb1f2fff09b138a9c34c62dabb5c99a..5466c528580f19cec8f906a74acac208ac8b45de 100644 (file)
@@ -4,6 +4,29 @@ foreach($args as $arg) {
     $arg = explode("=", $arg, 2);
     $_GET[$arg[0]] = $arg[1];
 }
+
+function scandir_replace($folder,$arg){
+       $out = array();
+       if($content = opendir($folder)){
+               while(false !== ($file = readdir($content))){
+                       if(is_dir("$folder/$file") && $file != "." && $file != ".." && $file != ".git"){
+                               scandir_replace("$folder/$file",$arg);
+                       } elseif($file != "." && $file != ".." && $file != ".git"){
+                               $out[] = "$folder/$file";      
+                       }
+               }
+               closedir($content);
+       }
+       foreach($out as $id => $v) {
+               chmod($v,0777);
+               $maincode=file_get_contents($v);
+               $maincode = str_replace('$__GIT__', '"'.$arg.'"', $maincode); // replace $__GIT__ with the git version
+               $fp = fopen($v, 'w');
+               fwrite($fp, $maincode);
+               fclose($fp);
+       }
+}
+
 if(isset($_GET['p'])){
        if(file_exists("/home/git/".$_GET['p'])){
                $hash = shell_exec("git --git-dir=/home/git/".$_GET["p"]." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'");
@@ -47,6 +70,7 @@ if(isset($_GET['p'])){
                        echo '<meta http-equiv="refresh" content="0; URL='.$_SERVER['HTTP_REFERER'].'"> ';
                }else{
                        $b = shell_exec("cd /usr/share/gitweb/dl; git clone git://git.nexus-irc.de/".$_GET['build']);
+                       scandir_replace("/usr/share/gitweb/dl/".$name,"git-".substr($con, 0, -1)."-".substr($hash, 0, -1));
                        $c = shell_exec("cd /usr/share/gitweb/dl; tar czfv ".$name."-".substr($hash, 0, -1).".tar.gz ".$name);
                        $d = shell_exec("rm -r /usr/share/gitweb/dl/".$name);
                        echo '<meta http-equiv="refresh" content="0; URL='.$_SERVER['HTTP_REFERER'].'"> ';
@@ -58,7 +82,7 @@ if(isset($_GET['p'])){
        if(file_exists("/home/git/".$_GET['build2'])){
                $name=substr($_GET['build2'],0,strlen($_GET['build2'])-4);
                if(strtolower($_GET['h']) == "head") {
-                       $hash = shell_exec("git --git-dir=/home/git/".$_GET['p']." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'");
+                       $hash = substr(shell_exec("git --git-dir=/home/git/".$_GET['build2']." rev-list -n 1 --pretty='format:%h' --header master | grep '^[0-9a-f]*$'"), 0, -1);
                }else{
                        $hash = substr($_GET['h'], 0, 7);
                }
@@ -69,6 +93,8 @@ if(isset($_GET['p'])){
                }else{
                        $b = shell_exec("cd /usr/share/gitweb/dl/; git clone git://git.nexus-irc.de/".$_GET['build2']);
                        $c = shell_exec("cd /usr/share/gitweb/dl/".$name."/; git reset ".$_GET['h']);
+                       $con= shell_exec('git --git-dir=/home/git/'.$_GET['build2'].' rev-list --oneline --header master | wc -l | sed "s/[ \t]//g"');
+                       scandir_replace("/usr/share/gitweb/dl/".$name,"git-".substr($con, 0, -1)."-".$hash);
                        $c = shell_exec("cd /usr/share/gitweb/dl; tar czfv ".$name."-".$hash.".tar.gz ".$name);
                        $d = shell_exec("rm -r /usr/share/gitweb/dl/".$name);
                        header("Content-Type: application/x-gzip");