From 0b086146ffd70574b1069056e35bb11a1d782407 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Tue, 07 May 2013 08:09:07 -0400
Subject: [PATCH] [authority] Clear user selection on filter change
---
src/main/java/com/gitblit/GitBlit.java | 68 +++++++++++++++++++++++++++++++---
1 files changed, 62 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java
index 2c5bfe5..42a1434 100644
--- a/src/main/java/com/gitblit/GitBlit.java
+++ b/src/main/java/com/gitblit/GitBlit.java
@@ -22,6 +22,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
+import java.lang.reflect.Type;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
@@ -71,7 +72,6 @@
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.storage.file.FileBasedConfig;
-import org.eclipse.jgit.storage.file.WindowCache;
import org.eclipse.jgit.storage.file.WindowCacheConfig;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
@@ -91,6 +91,7 @@
import com.gitblit.fanout.FanoutService;
import com.gitblit.fanout.FanoutSocketService;
import com.gitblit.git.GitDaemon;
+import com.gitblit.models.GitClientApplication;
import com.gitblit.models.FederationModel;
import com.gitblit.models.FederationProposal;
import com.gitblit.models.FederationSet;
@@ -121,6 +122,11 @@
import com.gitblit.utils.X509Utils.X509Metadata;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonIOException;
+import com.google.gson.JsonSyntaxException;
+import com.google.gson.reflect.TypeToken;
/**
* GitBlit is the servlet context listener singleton that acts as the core for
@@ -148,6 +154,9 @@
private final List<FederationModel> federationRegistrations = Collections
.synchronizedList(new ArrayList<FederationModel>());
+
+ private final List<GitClientApplication> clientApplications = Collections
+ .synchronizedList(new ArrayList<GitClientApplication>());
private final Map<String, FederationModel> federationPullResults = new ConcurrentHashMap<String, FederationModel>();
@@ -466,6 +475,45 @@
cloneUrls.add(MessageFormat.format(url, repositoryName, username));
}
return cloneUrls;
+ }
+
+ /**
+ * Returns the list of custom client applications to be used for the
+ * repository url panel;
+ *
+ * @return a list of client applications
+ */
+ public List<GitClientApplication> getClientApplications() {
+ if (clientApplications.isEmpty()) {
+ try {
+ InputStream is = getClass().getResourceAsStream("/clientapps.json");
+ Collection<GitClientApplication> clients = readClientApplications(is);
+ is.close();
+ if (clients != null) {
+ clientApplications.clear();
+ clientApplications.addAll(clients);
+ }
+ } catch (IOException e) {
+ logger.error("Failed to deserialize clientapps.json resource!", e);
+ }
+ }
+ return clientApplications;
+ }
+
+ private Collection<GitClientApplication> readClientApplications(InputStream is) {
+ try {
+ Type type = new TypeToken<Collection<GitClientApplication>>() {
+ }.getType();
+ InputStreamReader reader = new InputStreamReader(is);
+ Gson gson = new GsonBuilder().create();
+ Collection<GitClientApplication> links = gson.fromJson(reader, type);
+ return links;
+ } catch (JsonIOException e) {
+ logger.error("Error deserializing client applications!", e);
+ } catch (JsonSyntaxException e) {
+ logger.error("Error deserializing client applications!", e);
+ }
+ return null;
}
/**
@@ -1295,7 +1343,15 @@
for (String repo : list) {
RepositoryModel model = getRepositoryModel(user, repo);
if (model != null) {
- repositories.add(model);
+ if (!model.hasCommits) {
+ // only add empty repositories that user can push to
+ if (UserModel.ANONYMOUS.canPush(model)
+ || user != null && user.canPush(model)) {
+ repositories.add(model);
+ }
+ } else {
+ repositories.add(model);
+ }
}
}
if (getBoolean(Keys.web.showRepositorySizes, true)) {
@@ -3186,7 +3242,7 @@
cfg.setPackedGitMMAP(settings.getBoolean(Keys.git.packedGitMmap, cfg.isPackedGitMMAP()));
try {
- WindowCache.reconfigure(cfg);
+ cfg.install();
logger.debug(MessageFormat.format("{0} = {1,number,0}", Keys.git.packedGitWindowSize, cfg.getPackedGitWindowSize()));
logger.debug(MessageFormat.format("{0} = {1,number,0}", Keys.git.packedGitLimit, cfg.getPackedGitLimit()));
logger.debug(MessageFormat.format("{0} = {1,number,0}", Keys.git.deltaBaseCacheLimit, cfg.getDeltaBaseCacheLimit()));
@@ -3228,14 +3284,14 @@
protected void configureGitDaemon() {
String bindInterface = settings.getString(Keys.git.daemonBindInterface, "localhost");
- int port = settings.getInteger(Keys.git.daemonPort, GitDaemon.DEFAULT_PORT);
+ int port = settings.getInteger(Keys.git.daemonPort, 0);
if (port > 0) {
try {
gitDaemon = new GitDaemon(bindInterface, port, getRepositoriesFolder());
gitDaemon.start();
- logger.info(MessageFormat.format("Git daemon is listening on {0}:{1,number,0}", bindInterface, port));
} catch (IOException e) {
- logger.error(MessageFormat.format("Failed to start Git daemon on {0}:{1,number.0}", bindInterface, port), e);
+ gitDaemon = null;
+ logger.error(MessageFormat.format("Failed to start Git daemon on {0}:{1,number,0}", bindInterface, port), e);
}
}
}
--
Gitblit v1.9.1