From f22a0633d08e38ac4bf92b5165a708e11b4d6598 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 03 Oct 2012 17:31:37 -0400
Subject: [PATCH] Implemented support for toggling User.canFork in Manager

---
 src/com/gitblit/GitServlet.java |   31 ++++++++++++++-----------------
 1 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/src/com/gitblit/GitServlet.java b/src/com/gitblit/GitServlet.java
index 68097cb..2571693 100644
--- a/src/com/gitblit/GitServlet.java
+++ b/src/com/gitblit/GitServlet.java
@@ -51,7 +51,6 @@
 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;
 
@@ -94,9 +93,16 @@
 			@Override
 			public ReceivePack create(HttpServletRequest req, Repository db)
 					throws ServiceNotEnabledException, ServiceNotAuthorizedException {
-				ReceivePack rp = super.create(req, db);
+				
+				// determine repository name from request
+				String repositoryName = req.getPathInfo().substring(1);
+				repositoryName = GitFilter.getRepositoryName(repositoryName);
+				
 				GitblitReceiveHook hook = new GitblitReceiveHook();
+				hook.repositoryName = repositoryName;
 				hook.gitblitUrl = HttpUtils.getGitblitURL(req);
+
+				ReceivePack rp = super.create(req, db);
 				rp.setPreReceiveHook(hook);
 				rp.setPostReceiveHook(hook);
 				return rp;
@@ -158,6 +164,8 @@
 
 		protected final Logger logger = LoggerFactory.getLogger(GitblitReceiveHook.class);
 
+		protected String repositoryName;
+		
 		protected String gitblitUrl;
 
 		/**
@@ -167,7 +175,7 @@
 		 */
 		@Override
 		public void onPreReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {
-			RepositoryModel repository = getRepositoryModel(rp);
+			RepositoryModel repository = GitBlit.self().getRepositoryModel(repositoryName);
 			Set<String> scripts = new LinkedHashSet<String>();
 			scripts.addAll(GitBlit.self().getPreReceiveScriptsInherited(repository));
 			scripts.addAll(repository.preReceiveScripts);
@@ -195,7 +203,7 @@
 				logger.info("skipping post-receive hooks, no refs created, updated, or removed");
 				return;
 			}
-			RepositoryModel repository = getRepositoryModel(rp);
+			RepositoryModel repository = GitBlit.self().getRepositoryModel(repositoryName);
 			Set<String> scripts = new LinkedHashSet<String>();
 			scripts.addAll(GitBlit.self().getPostReceiveScriptsInherited(repository));
 			scripts.addAll(repository.postReceiveScripts);
@@ -204,19 +212,6 @@
 
 			// Experimental
 			// runNativeScript(rp, "hooks/post-receive", commands);
-		}
-
-		/**
-		 * Returns the RepositoryModel for the repository we are pushing into.
-		 * 
-		 * @param rp
-		 * @return a RepositoryModel
-		 */
-		protected RepositoryModel getRepositoryModel(ReceivePack rp) {
-			Repository repository = rp.getRepository();
-			String repositoryName = FileUtils.getRelativePath(GitBlit.getRepositoriesFolder(), repository.getDirectory());
-			RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
-			return model;
 		}
 
 		/**
@@ -231,6 +226,7 @@
 			if (user == null) {
 				// anonymous push, create a temporary usermodel
 				user = new UserModel(person.getName());
+				user.isAuthenticated = false;
 			}
 			return user;
 		}
@@ -253,6 +249,7 @@
 			Binding binding = new Binding();
 			binding.setVariable("gitblit", GitBlit.self());
 			binding.setVariable("repository", repository);
+			binding.setVariable("receivePack", rp);
 			binding.setVariable("user", user);
 			binding.setVariable("commands", commands);
 			binding.setVariable("url", gitblitUrl);

--
Gitblit v1.9.1