From 2ea85bfe371215ef21fcd528bc40fa57c48ee698 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 31 Oct 2012 16:38:03 -0400
Subject: [PATCH] Personal repositories must always be owned by the account the repo is stored in
---
src/com/gitblit/GitBlit.java | 61 +++++++++++++++++++++++++-----
1 files changed, 50 insertions(+), 11 deletions(-)
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java
index 6e587ca..35451f6 100644
--- a/src/com/gitblit/GitBlit.java
+++ b/src/com/gitblit/GitBlit.java
@@ -932,7 +932,7 @@
*/
private void addToCachedRepositoryList(RepositoryModel model) {
if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
- repositoryListCache.put(model.name, model);
+ repositoryListCache.put(model.name.toLowerCase(), model);
// update the fork origin repository with this repository clone
if (!StringUtils.isEmpty(model.originRepository)) {
@@ -954,7 +954,7 @@
if (StringUtils.isEmpty(name)) {
return null;
}
- return repositoryListCache.remove(name);
+ return repositoryListCache.remove(name.toLowerCase());
}
/**
@@ -1045,6 +1045,16 @@
// update cache
for (String repository : repositories) {
getRepositoryModel(repository);
+ }
+ }
+
+ // rebuild fork networks
+ for (RepositoryModel model : repositoryListCache.values()) {
+ if (!StringUtils.isEmpty(model.originRepository)) {
+ if (repositoryListCache.containsKey(model.originRepository)) {
+ RepositoryModel origin = repositoryListCache.get(model.originRepository);
+ origin.addFork(model.name);
+ }
}
}
@@ -1178,7 +1188,7 @@
}
// cached model
- RepositoryModel model = repositoryListCache.get(repositoryName);
+ RepositoryModel model = repositoryListCache.get(repositoryName.toLowerCase());
if (gcExecutor.isCollectingGarbage(model.name)) {
// Gitblit is busy collecting garbage, use our cached model
@@ -1445,7 +1455,7 @@
Constants.CONFIG_GITBLIT, null, "federationSets")));
model.isFederated = getConfig(config, "isFederated", false);
model.gcThreshold = getConfig(config, "gcThreshold", settings.getString(Keys.git.defaultGarbageCollectionThreshold, "500KB"));
- model.gcPeriod = getConfig(config, "gcPeriod", settings.getString(Keys.git.defaultGarbageCollectionPeriod, "7 days"));
+ model.gcPeriod = getConfig(config, "gcPeriod", settings.getInteger(Keys.git.defaultGarbageCollectionPeriod, 7));
try {
model.lastGC = new SimpleDateFormat(Constants.ISO8601).parse(getConfig(config, "lastGC", "1970-01-01'T'00:00:00Z"));
} catch (Exception e) {
@@ -1483,7 +1493,7 @@
// ensure origin still exists
File repoFolder = new File(getRepositoriesFolder(), originRepo);
if (repoFolder.exists()) {
- model.originRepository = originRepo;
+ model.originRepository = originRepo.toLowerCase();
}
}
} catch (URISyntaxException e) {
@@ -1503,7 +1513,7 @@
if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
// if we are caching use the cache to determine availability
// otherwise we end up adding a phantom repository to the cache
- return repositoryListCache.containsKey(repositoryName);
+ return repositoryListCache.containsKey(repositoryName.toLowerCase());
}
Repository r = getRepository(repositoryName, false);
if (r == null) {
@@ -1561,7 +1571,7 @@
}
for (String repository : repositoryListCache.keySet()) {
- if (repository.toLowerCase().startsWith(userPath)) {
+ if (repository.startsWith(userPath)) {
RepositoryModel model = repositoryListCache.get(repository);
if (!StringUtils.isEmpty(model.originRepository)) {
if (roots.contains(model.originRepository)) {
@@ -1575,7 +1585,7 @@
// not caching
ProjectModel project = getProjectModel(userProject);
for (String repository : project.repositories) {
- if (repository.toLowerCase().startsWith(userProject)) {
+ if (repository.startsWith(userProject)) {
RepositoryModel model = repositoryListCache.get(repository);
if (model.originRepository.equalsIgnoreCase(origin)) {
// user has a fork
@@ -1598,7 +1608,7 @@
public ForkModel getForkNetwork(String repository) {
if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
// find the root
- RepositoryModel model = repositoryListCache.get(repository);
+ RepositoryModel model = repositoryListCache.get(repository.toLowerCase());
while (model.originRepository != null) {
model = repositoryListCache.get(model.originRepository);
}
@@ -1609,7 +1619,7 @@
}
private ForkModel getForkModel(String repository) {
- RepositoryModel model = repositoryListCache.get(repository);
+ RepositoryModel model = repositoryListCache.get(repository.toLowerCase());
ForkModel fork = new ForkModel(model);
if (!ArrayUtils.isEmpty(model.forks)) {
for (String aFork : model.forks) {
@@ -1729,6 +1739,27 @@
*/
private boolean getConfig(StoredConfig config, String field, boolean defaultValue) {
return config.getBoolean(Constants.CONFIG_GITBLIT, field, defaultValue);
+ }
+
+ /**
+ * Returns the gitblit string value for the specified key. If key is not
+ * set, returns defaultValue.
+ *
+ * @param config
+ * @param field
+ * @param defaultValue
+ * @return field value or defaultValue
+ */
+ private int getConfig(StoredConfig config, String field, int defaultValue) {
+ String value = config.getString(Constants.CONFIG_GITBLIT, null, field);
+ if (StringUtils.isEmpty(value)) {
+ return defaultValue;
+ }
+ try {
+ return Integer.parseInt(value);
+ } catch (Exception e) {
+ }
+ return defaultValue;
}
/**
@@ -1896,7 +1927,7 @@
repository.federationStrategy.name());
config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFederated", repository.isFederated);
config.setString(Constants.CONFIG_GITBLIT, null, "gcThreshold", repository.gcThreshold);
- config.setString(Constants.CONFIG_GITBLIT, null, "gcPeriod", repository.gcPeriod);
+ config.setInt(Constants.CONFIG_GITBLIT, null, "gcPeriod", repository.gcPeriod);
if (repository.lastGC != null) {
config.setString(Constants.CONFIG_GITBLIT, null, "lastGC", new SimpleDateFormat(Constants.ISO8601).format(repository.lastGC));
}
@@ -2876,6 +2907,14 @@
}
/**
+ *
+ * @return true if we are running the gc executor
+ */
+ public boolean isCollectingGarbage() {
+ return gcExecutor.isRunning();
+ }
+
+ /**
* Returns true if Gitblit is actively collecting garbage in this repository.
*
* @param repositoryName
--
Gitblit v1.9.1