Add option to filter commits from feeds using a pattern
Add option to filter commits from feeds using a pattern

--- a/config/gitphp.conf.defaults.php
+++ b/config/gitphp.conf.defaults.php
@@ -275,6 +275,18 @@
  * http://www.gitphp.org/projects/gitphp/wiki/Clean_URLs
  */
 $gitphp_conf['cleanurl'] = false;
+
+/*
+ * feedfilter
+ * Sets a regular expression to use to filter commits out
+ * of the project atom/rss feed.  Commits that have a
+ * commit message matching this pattern will be excluded.
+ * For example, '/GIT_SILENT/' will exclude any commit
+ * with the string GIT_SILENT in the commit message.
+ */
+//$gitphp_conf['feedfilter'] = '/GIT_SILENT/';
+
+/*
 
 
 /*********************************************************

--- a/include/controller/Controller_Feed.class.php
+++ b/include/controller/Controller_Feed.class.php
@@ -114,6 +114,9 @@
 		//	$strategy = new GitPHP_LogLoad_Raw();
 		//}
 		$log = new GitPHP_Log($this->GetProject(), $this->GetProject()->GetHeadCommit(), $strategy, GitPHP_Controller_Feed::FeedItemCount);
+		if ($this->config->HasKey('feedfilter')) {
+			$log->FilterCommits($this->config->GetValue('feedfilter'));
+		}
 		$log->FilterOldCommits(48*60*60, 20);
 
 		$this->tpl->assign('log', $log);

--- a/include/git/log/Log.class.php
+++ b/include/git/log/Log.class.php
@@ -84,5 +84,37 @@
 		}
 
 	}
+
+	/**
+	 * Filters out commits matching a certain pattern
+	 *
+	 * @param string $pattern pattern
+	 */
+	public function FilterCommits($pattern)
+	{
+		if (empty($pattern))
+			return;
+
+		if (!$this->dataLoad) {
+			$this->LoadData();
+		}
+
+		$filtered = false;
+		foreach ($this->hashList as $i => $hash) {
+			$commit = $this->project->GetCommit($hash);
+			$comment = $commit->GetComment();
+			foreach ($comment as $commentline) {
+				if (preg_match($pattern, $commentline)) {
+					unset($this->hashList[$i]);
+					$filtered = true;
+					break;
+				}
+			}
+		}
+
+		if ($filtered) {
+			$this->hashList = array_values($this->hashList);
+		}
+	}
 }
 

comments