From 261ddf0fcf9a55fbb5b4e7c6c2cdb4c2f8c860fe Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Thu, 10 Apr 2014 18:58:09 -0400 Subject: [PATCH] Revise dispatchers and move command classes --- src/main/java/com/gitblit/manager/GitblitManager.java | 61 +++++++++++++++++++++++++++++- 1 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gitblit/manager/GitblitManager.java b/src/main/java/com/gitblit/manager/GitblitManager.java index 6eb6023..8856715 100644 --- a/src/main/java/com/gitblit/manager/GitblitManager.java +++ b/src/main/java/com/gitblit/manager/GitblitManager.java @@ -22,6 +22,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Type; +import java.security.PublicKey; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; @@ -33,7 +34,12 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.eclipse.jgit.api.CloneCommand; +import org.eclipse.jgit.api.FetchCommand; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.transport.RefSpec; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,9 +68,10 @@ import com.gitblit.models.SettingModel; import com.gitblit.models.TeamModel; import com.gitblit.models.UserModel; +import com.gitblit.tickets.ITicketService; +import com.gitblit.transport.ssh.IPublicKeyManager; import com.gitblit.utils.ArrayUtils; import com.gitblit.utils.HttpUtils; -import com.gitblit.utils.JGitUtils; import com.gitblit.utils.JsonUtils; import com.gitblit.utils.ObjectCache; import com.gitblit.utils.StringUtils; @@ -101,6 +108,8 @@ protected final IAuthenticationManager authenticationManager; + protected final IPublicKeyManager publicKeyManager; + protected final IRepositoryManager repositoryManager; protected final IProjectManager projectManager; @@ -112,6 +121,7 @@ INotificationManager notificationManager, IUserManager userManager, IAuthenticationManager authenticationManager, + IPublicKeyManager publicKeyManager, IRepositoryManager repositoryManager, IProjectManager projectManager, IFederationManager federationManager) { @@ -121,6 +131,7 @@ this.notificationManager = notificationManager; this.userManager = userManager; this.authenticationManager = authenticationManager; + this.publicKeyManager = publicKeyManager; this.repositoryManager = repositoryManager; this.projectManager = projectManager; this.federationManager = federationManager; @@ -158,7 +169,33 @@ // clone the repository try { - JGitUtils.cloneRepository(repositoryManager.getRepositoriesFolder(), cloneName, fromUrl, true, null); + Repository canonical = getRepository(repository.name); + File folder = new File(repositoryManager.getRepositoriesFolder(), cloneName); + CloneCommand clone = new CloneCommand(); + clone.setBare(true); + + // fetch branches with exclusions + Collection<Ref> branches = canonical.getRefDatabase().getRefs(Constants.R_HEADS).values(); + List<String> branchesToClone = new ArrayList<String>(); + for (Ref branch : branches) { + String name = branch.getName(); + if (name.startsWith(Constants.R_TICKET)) { + // exclude ticket branches + continue; + } + branchesToClone.add(name); + } + clone.setBranchesToClone(branchesToClone); + clone.setURI(fromUrl); + clone.setDirectory(folder); + Git git = clone.call(); + + // fetch tags + FetchCommand fetch = git.fetch(); + fetch.setRefSpecs(new RefSpec("+refs/tags/*:refs/tags/*")); + fetch.call(); + + git.getRepository().close(); } catch (Exception e) { throw new GitBlitException(e); } @@ -483,6 +520,20 @@ } } + /** + * Throws an exception if trying to get a ticket service. + * + */ + @Override + public ITicketService getTicketService() { + throw new RuntimeException("This class does not have a ticket service!"); + } + + @Override + public IPublicKeyManager getPublicKeyManager() { + return publicKeyManager; + } + /* * ISTOREDSETTINGS * @@ -611,6 +662,12 @@ } return user; } + + @Override + public UserModel authenticate(String username, PublicKey key) { + return authenticationManager.authenticate(username, key); + } + @Override public UserModel authenticate(HttpServletRequest httpRequest, boolean requiresCertificate) { UserModel user = authenticationManager.authenticate(httpRequest, requiresCertificate); -- Gitblit v1.9.1