From: Stricted Date: Fri, 14 Sep 2012 15:36:16 +0000 (+0200) Subject: add scandir_replace function X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=7b5266f15fddd9f029e21563436a5dd00446baf5;p=gitweb.git add scandir_replace function --- diff --git a/git_download.php b/git_download.php index 16e1c86..5466c52 100644 --- a/git_download.php +++ b/git_download.php @@ -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 ' '; }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 ' '; @@ -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");