From 0e44acbb2fec928a1606dc60f427a148fff405c9 Mon Sep 17 00:00:00 2001
From: Mohamed Ragab <moragab@gmail.com>
Date: Wed, 02 May 2012 11:15:01 -0400
Subject: [PATCH] Added a script to facilitate setting the proxy host and port and no proxy hosts, and then it concatenates all the java system properties for setting the java proxy configurations and puts the resulting string in an environment variable JAVA_PROXY_CONFIG, modified the scirpts gitblit,  gitblit-ubuntu, and gitblit-centos to source the java-proxy-config.sh script and then include the resulting java proxy configuration in the java command

---
 src/com/gitblit/GitServlet.java |   81 ++++++++++++++++++++++++++++------------
 1 files changed, 56 insertions(+), 25 deletions(-)

diff --git a/src/com/gitblit/GitServlet.java b/src/com/gitblit/GitServlet.java
index 23fb32a..94042c7 100644
--- a/src/com/gitblit/GitServlet.java
+++ b/src/com/gitblit/GitServlet.java
@@ -26,10 +26,12 @@
 import java.io.OutputStreamWriter;
 import java.text.MessageFormat;
 import java.util.Collection;
+import java.util.Enumeration;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
 import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 
@@ -48,6 +50,8 @@
 
 import com.gitblit.models.RepositoryModel;
 import com.gitblit.models.UserModel;
+import com.gitblit.utils.ClientLogger;
+import com.gitblit.utils.FileUtils;
 import com.gitblit.utils.HttpUtils;
 import com.gitblit.utils.StringUtils;
 
@@ -71,22 +75,9 @@
 
 	private File groovyDir;
 
-	/**
-	 * Configure the servlet from Gitblit's configuration.
-	 */
-	@Override
-	public String getInitParameter(String name) {
-		if (name.equals("base-path")) {
-			return GitBlit.getRepositoriesFolder().getAbsolutePath();
-		} else if (name.equals("export-all")) {
-			return "1";
-		}
-		return super.getInitParameter(name);
-	}
-
 	@Override
 	public void init(ServletConfig config) throws ServletException {
-		groovyDir = GitBlit.getGroovyScriptsFolder();		
+		groovyDir = GitBlit.getGroovyScriptsFolder();
 		try {
 			gse = new GroovyScriptEngine(groovyDir.getAbsolutePath());
 		} catch (IOException e) {
@@ -106,7 +97,48 @@
 				return rp;
 			}
 		});
-		super.init(config);
+		super.init(new GitblitServletConfig(config));
+	}
+
+	/**
+	 * Transitional wrapper class to configure the JGit 1.2 GitFilter. This
+	 * GitServlet will probably be replaced by a GitFilter so that Gitblit can
+	 * serve Git repositories on the root URL and not a /git sub-url.
+	 * 
+	 * @author James Moger
+	 * 
+	 */
+	private class GitblitServletConfig implements ServletConfig {
+		final ServletConfig config;
+
+		GitblitServletConfig(ServletConfig config) {
+			this.config = config;
+		}
+
+		@Override
+		public String getServletName() {
+			return config.getServletName();
+		}
+
+		@Override
+		public ServletContext getServletContext() {
+			return config.getServletContext();
+		}
+
+		@Override
+		public String getInitParameter(String name) {
+			if (name.equals("base-path")) {
+				return GitBlit.getRepositoriesFolder().getAbsolutePath();
+			} else if (name.equals("export-all")) {
+				return "1";
+			}
+			return config.getInitParameter(name);
+		}
+
+		@Override
+		public Enumeration<String> getInitParameterNames() {
+			return config.getInitParameterNames();
+		}
 	}
 
 	/**
@@ -130,12 +162,12 @@
 		 */
 		@Override
 		public void onPreReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {
-			Set<String> scripts = new LinkedHashSet<String>();
-			scripts.addAll(GitBlit.getStrings(Keys.groovy.preReceiveScripts));
 			RepositoryModel repository = getRepositoryModel(rp);
+			Set<String> scripts = new LinkedHashSet<String>();
+			scripts.addAll(GitBlit.self().getPreReceiveScriptsInherited(repository));
 			scripts.addAll(repository.preReceiveScripts);
 			UserModel user = getUserModel(rp);
-			runGroovy(repository, user, commands, scripts);
+			runGroovy(repository, user, commands, rp, scripts);
 			for (ReceiveCommand cmd : commands) {
 				if (!Result.NOT_ATTEMPTED.equals(cmd.getResult())) {
 					logger.warn(MessageFormat.format("{0} {1} because \"{2}\"", cmd.getNewId()
@@ -158,12 +190,12 @@
 				logger.info("skipping post-receive hooks, no refs created, updated, or removed");
 				return;
 			}
-			Set<String> scripts = new LinkedHashSet<String>();
-			scripts.addAll(GitBlit.getStrings(Keys.groovy.postReceiveScripts));
 			RepositoryModel repository = getRepositoryModel(rp);
+			Set<String> scripts = new LinkedHashSet<String>();
+			scripts.addAll(GitBlit.self().getPostReceiveScriptsInherited(repository));
 			scripts.addAll(repository.postReceiveScripts);
 			UserModel user = getUserModel(rp);
-			runGroovy(repository, user, commands, scripts);
+			runGroovy(repository, user, commands, rp, scripts);
 
 			// Experimental
 			// runNativeScript(rp, "hooks/post-receive", commands);
@@ -177,9 +209,7 @@
 		 */
 		protected RepositoryModel getRepositoryModel(ReceivePack rp) {
 			Repository repository = rp.getRepository();
-			String rootPath = GitBlit.getRepositoriesFolder().getAbsolutePath();
-			String repositoryName = repository.getDirectory().getAbsolutePath();
-			repositoryName = repositoryName.substring(rootPath.length() + 1);
+			String repositoryName = FileUtils.getRelativePath(GitBlit.getRepositoriesFolder(), repository.getDirectory());
 			RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
 			return model;
 		}
@@ -209,7 +239,7 @@
 		 * @param scripts
 		 */
 		protected void runGroovy(RepositoryModel repository, UserModel user,
-				Collection<ReceiveCommand> commands, Set<String> scripts) {
+				Collection<ReceiveCommand> commands, ReceivePack rp, Set<String> scripts) {
 			if (scripts == null || scripts.size() == 0) {
 				// no Groovy scripts to execute
 				return;
@@ -222,6 +252,7 @@
 			binding.setVariable("commands", commands);
 			binding.setVariable("url", gitblitUrl);
 			binding.setVariable("logger", logger);
+			binding.setVariable("clientLogger", new ClientLogger(rp));
 			for (String script : scripts) {
 				if (StringUtils.isEmpty(script)) {
 					continue;

--
Gitblit v1.9.1