Gitosis support
Gitosis support

--- a/include/display.git_project_index.php
+++ b/include/display.git_project_index.php
@@ -11,7 +11,7 @@
 
 function git_project_index($projectroot, $projectlist)
 {
-	global $tpl, $git_projects;
+	global $tpl;
 
 	header("Content-type: text/plain; charset=utf-8");
 	header("Content-Disposition: inline; filename=\"index.aux\"");
@@ -19,7 +19,7 @@
 	$cachekey = sha1(serialize($projectlist));
 
 	if (!$tpl->is_cached('projectindex.tpl', $cachekey)) {
-		if (isset($git_projects))
+		if (is_array($projectlist))
 			$tpl->assign("categorized", TRUE);
 		$projlist = git_read_projects($projectroot, $projectlist);
 		$tpl->assign("projlist", $projlist);

--- a/include/display.git_project_list.php
+++ b/include/display.git_project_list.php
@@ -15,7 +15,7 @@
 
 function git_project_list($projectroot,$projectlist,$order = "project")
 {
-	global $tpl,$git_projects;
+	global $tpl;
 
 	$cachekey = sha1(serialize($projectlist)) . "|" . sha1($order);
 
@@ -25,7 +25,7 @@
 			if (count($projects) > 0) {
 				if ($order)
 					$tpl->assign("order",$order);
-				if (!isset($git_projects)) {
+				if (!is_array($projectlist)) {
 					switch ($order) {
 						case "project":
 							usort($projects,"projectcmp");

--- a/include/gitutil.git_project_owner.php
+++ b/include/gitutil.git_project_owner.php
@@ -9,7 +9,25 @@
 
 function git_project_owner($projectroot,$project)
 {
-	if (function_exists('posix_getpwuid')) {
+	global $git_projects;
+
+	if (is_file($git_projects)) {
+		if (!($fp = fopen($git_projects, 'r')))
+			return "Failed to open projects.list";
+
+		while (!feof($fp) && ($line = fgets($fp)))
+		{
+			$pinfo = explode(' ', $line);
+			$ppath = $pinfo[0];
+			if ($ppath == $project)
+			{
+				fclose($fp);
+				return urldecode($pinfo[1]);
+			}
+		}
+
+		fclose($fp);
+	} elseif (function_exists('posix_getpwuid')) {
 		$data = posix_getpwuid(fileowner($projectroot . $project));
 		if (isset($data['gecos']) && (strlen($data['gecos']) > 0))
 			return $data['gecos'];

--- a/include/gitutil.git_read_packed_refs.php
+++ b/include/gitutil.git_read_packed_refs.php
@@ -15,7 +15,7 @@
 		return null;
 
 	$refs = array();
-        $refs = explode("\n",git_read_hash($projectroot . $project . "/" . 'packed-refs'));
+	$refs = explode("\n",git_read_hash($projectroot . $project . "/" . 'packed-refs'));
 	$reflist = array();
 
 	$dirlen = strlen($refdir);
@@ -29,7 +29,7 @@
 					$reflist[] = $refobj;
 			}
 		}
-        }
+	}
 
 	return $reflist;
 }

--- a/include/gitutil.git_read_projects.php
+++ b/include/gitutil.git_read_projects.php
@@ -12,43 +12,60 @@
 
 function git_read_projects($projectroot,$projectlist,$projdata = FALSE)
 {
+	if (!isset($projectroot))
+		return "No projectroot set";
+
+	if (!is_dir($projectroot))
+		return "Projectroot is not a directory";
+
 	$projects = array();
-	if (isset($projectroot)) {
-		if (is_dir($projectroot)) {
-			if (isset($projectlist)) {
-				foreach ($projectlist as $cat => $plist) {
-					if (is_array($plist)) {
-						$projs = array();
-						foreach ($plist as $pname => $ppath) {
-							if (is_dir($projectroot . $ppath) && is_file($projectroot . $ppath . "/HEAD")) {
-								if ($projdata)
-									$projs[] = git_project_info($projectroot, $ppath);
-								else
-									$projs[] = $ppath;
-							}
-						}
-						if (count($projs) > 0) {
-							sort($projs);
-							$projects[$cat] = $projs;
-						}
+	if (is_file($projectlist)) {
+		if (!($fp = fopen($projectlist, 'r')))
+			return "Failed to open projects.list";
+
+		while (!feof($fp) && ($line = fgets($fp)))
+		{
+			$pinfo = explode(' ', $line);
+			$ppath = $pinfo[0];
+			if (is_file($projectroot . $ppath . "/HEAD"))
+			{
+				if ($projdata)
+					$ppath = git_project_info($projectroot, $ppath);
+				$projects[] = $ppath;
+			}
+		}
+
+		fclose($fp);
+	} elseif (is_array($projectlist)) {
+		foreach ($projectlist as $cat => $plist) {
+			if (is_array($plist)) {
+				$projs = array();
+				foreach ($plist as $pname => $ppath) {
+					if (is_file($projectroot . $ppath . "/HEAD")) {
+						if ($projdata)
+							$projs[] = git_project_info($projectroot, $ppath);
+						else
+							$projs[] = $ppath;
 					}
 				}
-			} else {
-				$projects = git_recurse_projects($projectroot);
-				$len = count($projects);
-				$cut = strlen($projectroot);
-				for ($i = 0; $i < $len; ++$i) {
-					$p = substr($projects[$i],$cut + 1);
-					if ($projdata)
-						$projects[$i] = git_project_info($projectroot, $p);
-					else
-						$projects[$i] = $p;
+				if (count($projs) > 0) {
+					sort($projs);
+					$projects[$cat] = $projs;
 				}
 			}
-		} else
-			return "Projectroot is not a directory";
-	} else
-		return "No projectroot set";
+		}
+	} else {
+		$projects = git_recurse_projects($projectroot);
+		$len = count($projects);
+		$cut = strlen($projectroot);
+		for ($i = 0; $i < $len; ++$i) {
+			$p = substr($projects[$i],$cut + 1);
+			if ($projdata)
+				$projects[$i] = git_project_info($projectroot, $p);
+			else
+				$projects[$i] = $p;
+		}
+	}
 	return $projects;
 }
 

file:a/index.php -> file:b/index.php
--- a/index.php
+++ b/index.php
@@ -40,13 +40,9 @@
   */
  require_once($gitphp_conf['smarty_prefix'] . "Smarty.class.php");
  $tpl = new Smarty;
- if ((!isset($_GET['a'])) || (
-     	($_GET['a'] != "commitdiff_plain") &&
-     	($_GET['a'] != "blob_plain") &&
-     	($_GET['a'] != "blobdiff_plain") &&
-     	($_GET['a'] != "rss") &&
-     	($_GET['a'] != "opml") &&
-	($_GET['a'] != "snapshot"))) {
+ if (!isset($_GET['a']) ||
+	!in_array($_GET['a'], array('commitdiff_plain', 'blob_plain',
+		'blobdiff_plain', 'rss', 'opml', 'snapshot'))) {
 	$tpl->load_filter('output','trimwhitespace');
 	$extraoutput = TRUE;
 }
@@ -77,7 +73,7 @@
 		$tpl->cache_lifetime = $gitphp_conf['cachelifetime'];
 	if (!(isset($gitphp_conf['cacheexpire']) && ($gitphp_conf['cacheexpire'] === FALSE))) {
 		require_once('include/cache.cache_expire.php');
-		cache_expire($gitphp_conf['projectroot'], $project, (isset($git_projects) ? $git_projects : null));
+		cache_expire($gitphp_conf['projectroot'], $project, (is_array($git_projects) ? $git_projects : null));
 	}
  }
 
@@ -226,7 +222,7 @@
 	}
  } else {
 	require_once('include/display.git_project_list.php');
-	git_project_list($gitphp_conf['projectroot'], (isset($git_projects) ? $git_projects : null), (isset($_GET['o']) ? $_GET['o'] : "project"));
+	git_project_list($gitphp_conf['projectroot'], $git_projects, (isset($_GET['o']) ? $_GET['o'] : "project"));
  }
 
  if ($gitphp_conf['debug'] && $extraoutput)

comments