From 9f5a860d1ecaebb80530fc22607d34fc80d8c09d Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 04 Oct 2012 08:04:49 -0400
Subject: [PATCH] Fixed duplicate entries in repository cache (issue 140)

---
 src/com/gitblit/GitBlit.java |   25 +++++++++++++++----------
 docs/04_releases.mkd         |    1 +
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/docs/04_releases.mkd b/docs/04_releases.mkd
index 30582d5..ffd56dd 100644
--- a/docs/04_releases.mkd
+++ b/docs/04_releases.mkd
@@ -11,6 +11,7 @@
 
 #### fixes
 
+- Fixed duplicate entries in repository cache (issue 140)
 - Fixed connection leak in LDAPUserService (issue 139)
 - Fixed bug in commit page where changes to a submodule threw a null pointer exception (issue 132)
 - Fixed bug in the diff view for filenames that have non-ASCII characters (issue 128)
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java
index 6348964..b14adc9 100644
--- a/src/com/gitblit/GitBlit.java
+++ b/src/com/gitblit/GitBlit.java
@@ -746,17 +746,17 @@
 	 * Adds the repository to the list of cached repositories if Gitblit is
 	 * configured to cache the repository list.
 	 * 
-	 * @param name
+	 * @param model
 	 */
-	private void addToCachedRepositoryList(String name, RepositoryModel model) {
+	private void addToCachedRepositoryList(RepositoryModel model) {
 		if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
-			repositoryListCache.put(name, model);
+			repositoryListCache.put(model.name, model);
 			
 			// update the fork origin repository with this repository clone
 			if (!StringUtils.isEmpty(model.originRepository)) {
 				if (repositoryListCache.containsKey(model.originRepository)) {
 					RepositoryModel origin = repositoryListCache.get(model.originRepository);
-					origin.addFork(name);
+					origin.addFork(model.name);
 				}
 			}
 		}
@@ -1001,7 +1001,7 @@
 			if (model == null) {
 				return null;
 			}
-			addToCachedRepositoryList(repositoryName, model);
+			addToCachedRepositoryList(model);
 			return model;
 		}
 		
@@ -1023,7 +1023,7 @@
 			logger.info(MessageFormat.format("Config for \"{0}\" has changed. Reloading model and updating cache.", repositoryName));
 			model = loadRepositoryModel(repositoryName);
 			removeFromCachedRepositoryList(repositoryName);
-			addToCachedRepositoryList(repositoryName, model);
+			addToCachedRepositoryList(model);
 		} else {
 			// update a few repository parameters 
 			if (!model.hasCommits) {
@@ -1236,10 +1236,15 @@
 			return null;
 		}
 		RepositoryModel model = new RepositoryModel();
-		model.name = repositoryName;
+		model.isBare = r.isBare();
+		File basePath = getFileOrFolder(Keys.git.repositoriesFolder, "git");
+		if (model.isBare) {
+			model.name = com.gitblit.utils.FileUtils.getRelativePath(basePath, r.getDirectory());
+		} else {
+			model.name = com.gitblit.utils.FileUtils.getRelativePath(basePath, r.getDirectory().getParentFile());
+		}
 		model.hasCommits = JGitUtils.hasCommits(r);
 		model.lastChange = JGitUtils.getLastChange(r);
-		model.isBare = r.isBare();
 		if (repositoryName.indexOf('/') == -1) {
 			model.projectPath = "";
 		} else {
@@ -1670,7 +1675,7 @@
 		// update repository cache
 		removeFromCachedRepositoryList(repositoryName);
 		// model will actually be replaced on next load because config is stale
-		addToCachedRepositoryList(repository.name, repository);
+		addToCachedRepositoryList(repository);
 	}
 	
 	/**
@@ -2678,7 +2683,7 @@
 		}
 
 		// add this clone to the cached model
-		addToCachedRepositoryList(cloneModel.name, cloneModel);
+		addToCachedRepositoryList(cloneModel);
 		return cloneModel;
 	}
 }

--
Gitblit v1.9.1