Add project settings option to override individual settings for any project, regardless of the project list method used. Also use settings as terminology instead of override
Add project settings option to override individual settings for any project, regardless of the project list method used. Also use settings as terminology instead of override

--- a/config/projects.conf.php.example
+++ b/config/projects.conf.php.example
@@ -17,56 +17,15 @@
  *
  * There are three ways to list projects:
  *
- * 1. Two dimensional array of projects with categories
- *
- * The top level is the full array of projects.
- * Each project itself is an array with the following keys:
- * 'project': the path to the project, minus the projectroot
- * 'category': the category for the project. This is optional.
- * 'owner': the owner of the project.  This is optional,
- *          and overrides the actual owner
- * 'description': the description of the project.  This is optional,
- *                and overrides the description in the project's
- *                description file
- * 'cloneurl': the full clone url of the project.  This is optional,
- *             and overrides the clone URL setting in the config for
- *             this project.  This can also be an empty string to
- *             override the config clone url to say that only this
- *             project has no clone url.
- * 'pushurl': the full push url of the project.  This is optional,
- *            and overrides the push URL setting in the config for
- *            this project.  This can also be an empty string to
- *            override the config push url to say that only this
- *            project has no push url.
+ * 1. Array of projects
  */
 //$git_projects = array(
-//	array(
-//		'project' => 'gentoo.git'
-//	),
-//	array(
-//		'project' => 'core/fbx.git',
-//		'category' => 'Core'
-//	),
-//	array(
-//		'project' => 'php/gitphp.git',
-//		'category' => 'PHP',
-//		'description' => 'GitPHP, a web-based git repository browser in PHP',
-//		'owner' => 'Christopher Han',
-//		'cloneurl' => 'http://git.xiphux.com/php/gitphp.git',
-//		'pushurl' => ''
-//	),
-//	array(
-//		'project' => 'php/mdb.git',
-//		'category' => 'PHP'
-//	),
-//	array(
-//		'project' => 'php/xxcache.git',
-//		'category' => 'PHP'
-//	),
-//	array(
-//		'project' => 'websites/bth.git',
-//		'category' => 'Websites'
-//	)
+//	'gentoo.git'
+//	'core/fbx.git',
+//	'php/gitphp.git',
+//	'php/mdb.git',
+//	'php/xxcache.git',
+//	'websites/bth.git',
 //);
 
 
@@ -82,3 +41,46 @@
  */
 
 
+/*
+ * git_projects_settings
+ *
+ * This is used to specify override settings for individual projects.
+ * This is an array, where each key is the project, and the value is an
+ * array of settings.  This can be used with any of the project list
+ * methods above.
+ *
+ * The settings array can have the following key/value settings:
+ * 'category': the category for the project.
+ * 'owner': the owner of the project.  This overrides the actual owner
+ * 'description': the description of the project.  This overrides the 
+ *		  description in the project's description file
+ * 'cloneurl': the full clone url of the project.  This overrides the
+ *	       clone URL setting in the config for this project.
+ *	       This can also be an empty string to override the global
+ *             clone url to say that only this project has no clone url.
+ * 'pushurl': the full push url of the project.  This overrides the
+ *	      push URL setting in the config for this project.
+ *	      This can also be an empty string to override the global
+ *	      push url to say that only this project has no push url.
+ */
+//$git_projects_settings['php/gitphp.git'] = array(
+//	'category' => 'PHP',
+//	'description' => 'GitPHP, a web-based git repository browser in PHP',
+//	'owner' => 'Christopher Han',
+//	'cloneurl' => 'http://git.xiphux.com/php/gitphp.git',
+//	'pushurl' => ''
+//);
+//$git_projects_settings['gentoo.git'] = array(
+//	'description' => 'Gentoo portage overlay'
+//);
+//$git_projects_settings['core/fbx.git'] = array(
+//	'description' => 'FBX music player',
+//	'category' => 'Core'
+//);
+//$git_projects_settings['php/mdb.git'] = array(
+//	'category' => 'PHP',
+//	'description' => 'MDB: Media Database',
+//	'cloneurl' => '',
+//	'pushurl' => ''
+//);
+

--- a/include/controller/ControllerBase.class.php
+++ b/include/controller/ControllerBase.class.php
@@ -130,7 +130,7 @@
 
 		$projList = GitPHP_ProjectList::GetInstance();
 		if ($projList) {
-			$cacheKeyPrefix .= '|' . sha1(serialize($projList->GetConfig()));
+			$cacheKeyPrefix .= '|' . sha1(serialize($projList->GetConfig())) . '|' . sha1(serialize($projList->GetSettings()));
 			unset($projList);
 		}
 		if ($this->project && $projectKeys) {

--- a/include/git/ProjectList.class.php
+++ b/include/git/ProjectList.class.php
@@ -69,19 +69,21 @@
 			if (isset($git_projects)) {
 				if (is_string($git_projects)) {
 					self::$instance = new GitPHP_ProjectListFile($git_projects);
-					return;
 				} else if (is_array($git_projects)) {
 					if ($legacy) {
 						self::$instance = new GitPHP_ProjectListArrayLegacy($git_projects);
 					} else {
 						self::$instance = new GitPHP_ProjectListArray($git_projects);
 					}
-					return;
 				}
 			}
 		}
 
-		self::$instance = new GitPHP_ProjectListDirectory(GitPHP_Config::GetInstance()->GetValue('projectroot'));
+		if (!self::$instance)
+			self::$instance = new GitPHP_ProjectListDirectory(GitPHP_Config::GetInstance()->GetValue('projectroot'));
+
+		if (isset($git_projects_settings))
+			self::$instance->ApplySettings($git_projects_settings);
 	}
 
 }

--- a/include/git/ProjectListArray.class.php
+++ b/include/git/ProjectListArray.class.php
@@ -52,16 +52,26 @@
 	 */
 	protected function PopulateProjects()
 	{
-		foreach ($this->projectConfig as $projData) {
-			if (is_array($projData)) {
-				if (isset($projData['project'])) {
-					try {
+		foreach ($this->projectConfig as $proj => $projData) {
+			try {
+				if (is_string($projData)) {
+					// Just flat array of project paths
+					$projObj = new GitPHP_Project($projData);
+					$this->projects[$projData] = $projObj;
+				} else if (is_array($projData)) {
+					if (is_string($proj) && !empty($proj)) {
+						// Project key pointing to data array
+						$projObj = new GitPHP_Project($proj);
+						$this->projects[$proj] = $projObj;
+						$this->ApplyProjectSettings($proj, $projData);
+					} else if (isset($projData['project'])) {
+						// List of data arrays with projects inside
 						$projObj = new GitPHP_Project($projData['project']);
 						$this->projects[$projData['project']] = $projObj;
-						$this->ApplyProjectOverride($projData);
-					} catch (Exception $e) {
+						$this->ApplyProjectSettings(null, $projData);
 					}
 				}
+			} catch (Exception $e) {
 			}
 		}
 	}

--- a/include/git/ProjectListBase.class.php
+++ b/include/git/ProjectListBase.class.php
@@ -45,6 +45,15 @@
 	protected $projectConfig = null;
 
 	/**
+	 * projectSettings
+	 *
+	 * Stores the project settings internally
+	 *
+	 * @access protected
+	 */
+	protected $projectSettings = null;
+
+	/**
 	 * __construct
 	 *
 	 * Constructor
@@ -106,6 +115,18 @@
 	}
 
 	/**
+	 * GetSettings
+	 *
+	 * Gets the settings applied to this projectlist
+	 *
+	 * @access public
+	 */
+	public function GetSettings()
+	{
+		return $this->projectSettings;
+	}
+
+	/**
 	 * PopulateProjects
 	 *
 	 * Populates the internal list of projects
@@ -205,38 +226,62 @@
 	}
 
 	/**
-	 * ApplyProjectOverride
+	 * ApplyProjectSettings
 	 *
 	 * Applies override settings for a project
 	 *
 	 * @access protected
+	 * @param string $project the project path
 	 * @param array $projData project data array
 	 */
-	protected function ApplyProjectOverride($projData)
-	{
-		if ((!isset($projData['project'])) || empty($projData['project']))
+	protected function ApplyProjectSettings($project, $projData)
+	{
+		if (empty($project)) {
+			if (isset($projData['project']) && !empty($projData['project']))
+				$project = $projData['project'];
+			else
+				return;
+		}
+
+		$projectObj = $this->GetProject($project);
+		if (!$projectObj)
 			return;
 
-		$project = $this->GetProject($projData['project']);
-		if (!$project)
+		if (isset($projData['category']) && is_string($projData['category'])) {
+			$projectObj->SetCategory($projData['category']);
+		}
+		if (isset($projData['owner']) && is_string($projData['owner'])) {
+			$projectObj->SetOwner($projData['owner']);
+		}
+		if (isset($projData['description']) && is_string($projData['description'])) {
+			$projectObj->SetDescription($projData['description']);
+		}
+		if (isset($projData['cloneurl']) && is_string($projData['cloneurl'])) {
+			$projectObj->SetCloneUrl($projData['cloneurl']);
+		}
+		if (isset($projData['pushurl']) && is_string($projData['pushurl'])) {
+			$projectObj->SetPushUrl($projData['pushurl']);
+		}
+	}
+
+	/**
+	 * ApplySettings
+	 *
+	 * Applies a list of settings to the project list
+	 *
+	 * @access protected
+	 * @param array $settings the array of settings
+	 */
+	public function ApplySettings($settings)
+	{
+		if ((!$settings) || (count($settings) < 1))
 			return;
 
-
-		if (isset($projData['category']) && is_string($projData['category'])) {
-			$project->SetCategory($projData['category']);
-		}
-		if (isset($projData['owner']) && is_string($projData['owner'])) {
-			$project->SetOwner($projData['owner']);
-		}
-		if (isset($projData['description']) && is_string($projData['description'])) {
-			$project->SetDescription($projData['description']);
-		}
-		if (isset($projData['cloneurl']) && is_string($projData['cloneurl'])) {
-			$project->SetCloneUrl($projData['cloneurl']);
-		}
-		if (isset($projData['pushurl']) && is_string($projData['pushurl'])) {
-			$project->SetPushUrl($projData['pushurl']);
-		}
+		foreach ($settings as $proj => $setting) {
+			$this->ApplyProjectSettings($proj, $setting);
+		}
+
+		$this->projectSettings = $settings;
 	}
 
 }

comments