From fbe265fa787e4be9cb63c6bae2ef30b9400d9afc Mon Sep 17 00:00:00 2001
From: Simon Harrer <simon.harrer@gmail.com>
Date: Thu, 18 Jul 2013 10:11:04 -0400
Subject: [PATCH] Fixes findbugs warning - dereferencing null in exception case

---
 src/main/java/com/gitblit/utils/CommitCache.java |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/gitblit/utils/CommitCache.java b/src/main/java/com/gitblit/utils/CommitCache.java
index e188ff9..e84506e 100644
--- a/src/main/java/com/gitblit/utils/CommitCache.java
+++ b/src/main/java/com/gitblit/utils/CommitCache.java
@@ -67,7 +67,7 @@
 	 * 
 	 * @return
 	 */
-	protected Date getCacheCutoffDate() {
+	public Date getCutoffDate() {
 		final Calendar cal = Calendar.getInstance();
 		cal.setTimeInMillis(System.currentTimeMillis());
 		cal.set(Calendar.HOUR_OF_DAY, 0);
@@ -110,6 +110,23 @@
 	}
 	
 	/**
+	 * Clears the commit cache for a specific branch of a specific repository.
+	 * 
+	 * @param repositoryName
+	 * @param branch
+	 */
+	public void clear(String repositoryName, String branch) {
+		String repoKey = repositoryName.toLowerCase();
+		ObjectCache<List<RepositoryCommit>> repoCache = cache.get(repoKey);
+		if (repoCache != null) {
+			List<RepositoryCommit> commits = repoCache.remove(branch.toLowerCase());
+			if (!ArrayUtils.isEmpty(commits)) {
+				logger.info(MessageFormat.format("{0}:{1} commit cache cleared", repositoryName, branch));
+			}
+		}
+	}
+	
+	/**
 	 * Get all commits for the specified repository:branch that are in the cache.
 	 * 
 	 * @param repositoryName
@@ -118,7 +135,7 @@
 	 * @return a list of commits
 	 */
 	public List<RepositoryCommit> getCommits(String repositoryName, Repository repository, String branch) {
-		return getCommits(repositoryName, repository, branch, getCacheCutoffDate());
+		return getCommits(repositoryName, repository, branch, getCutoffDate());
 	}
 	
 	/**
@@ -134,7 +151,7 @@
 	 */
 	public List<RepositoryCommit> getCommits(String repositoryName, Repository repository, String branch, Date sinceDate) {
 		long start = System.nanoTime();
-		Date cacheCutoffDate = getCacheCutoffDate();
+		Date cacheCutoffDate = getCutoffDate();
 		List<RepositoryCommit> list;
 		if (cacheDays > 0 && (sinceDate.getTime() >= cacheCutoffDate.getTime())) {
 			// request fits within the cache window

--
Gitblit v1.9.1