merge + refactor getStoreDirectory

This commit is contained in:
Mohamed Karray
2018-11-28 15:14:49 +01:00
98 changed files with 1474 additions and 1534 deletions

View File

@@ -136,7 +136,7 @@ public class ScmTransportProtocol extends TransportProtocol
*/
@Override
public Transport open(URIish uri, Repository local, String remoteName)
throws NotSupportedException, TransportException
throws TransportException
{
File localDirectory = local.getDirectory();
File path = local.getFS().resolve(localDirectory, uri.getPath());
@@ -150,7 +150,7 @@ public class ScmTransportProtocol extends TransportProtocol
//J-
return new TransportLocalWithHooks(
hookEventFacadeProvider.get(),
repositoryHandlerProvider.get(),
repositoryHandlerProvider.get(),
local, uri, gitDir
);
//J+

View File

@@ -38,6 +38,7 @@ package sonia.scm.repository;
import com.google.common.base.Strings;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -88,6 +89,8 @@ public class GitRepositoryHandler
GitRepositoryServiceProvider.COMMANDS);
private static final Object LOCK = new Object();
private static final String CONFIG_SECTION_SCMM = "scmm";
private static final String CONFIG_KEY_REPOSITORY_ID = "repositoryid";
private final Scheduler scheduler;
@@ -97,19 +100,13 @@ public class GitRepositoryHandler
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param storeFactory
* @param fileSystem
* @param scheduler
* @param repositoryLocationResolver
*/
@Inject
public GitRepositoryHandler(ConfigurationStoreFactory storeFactory, FileSystem fileSystem, Scheduler scheduler, RepositoryLocationResolver repositoryLocationResolver, GitWorkdirFactory workdirFactory)
public GitRepositoryHandler(ConfigurationStoreFactory storeFactory,
Scheduler scheduler,
RepositoryLocationResolver repositoryLocationResolver,
GitWorkdirFactory workdirFactory)
{
super(storeFactory, fileSystem, repositoryLocationResolver);
super(storeFactory, repositoryLocationResolver);
this.scheduler = scheduler;
this.workdirFactory = workdirFactory;
}
@@ -182,15 +179,26 @@ public class GitRepositoryHandler
return getStringFromResource(RESOURCE_VERSION, DEFAULT_VERSION_INFORMATION);
}
public GitWorkdirFactory getWorkdirFactory() {
return workdirFactory;
}
public String getRepositoryId(StoredConfig gitConfig) {
return gitConfig.getString(GitRepositoryHandler.CONFIG_SECTION_SCMM, null, GitRepositoryHandler.CONFIG_KEY_REPOSITORY_ID);
}
//~--- methods --------------------------------------------------------------
@Override
protected void create(Repository repository, File directory) throws IOException {
try (org.eclipse.jgit.lib.Repository gitRepository = build(directory)) {
gitRepository.create(true);
StoredConfig config = gitRepository.getConfig();
config.setString(CONFIG_SECTION_SCMM, null, CONFIG_KEY_REPOSITORY_ID, repository.getId());
config.save();
}
}
private org.eclipse.jgit.lib.Repository build(File directory) throws IOException {
return new FileRepositoryBuilder()
.setGitDir(directory)
@@ -224,22 +232,4 @@ public class GitRepositoryHandler
{
return GitConfig.class;
}
/**
* Method description
*
*
* @param directory
*
* @return
*/
@Override
protected boolean isRepository(File directory)
{
return new File(directory, DIRECTORY_REFS).exists();
}
public GitWorkdirFactory getWorkdirFactory() {
return workdirFactory;
}
}

View File

@@ -36,6 +36,7 @@ package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.transport.PostReceiveHook;
import org.eclipse.jgit.transport.PreReceiveHook;
import org.eclipse.jgit.transport.ReceiveCommand;
@@ -44,11 +45,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.RepositoryHookType;
import sonia.scm.repository.RepositoryUtil;
import sonia.scm.repository.spi.GitHookContextProvider;
import sonia.scm.repository.spi.HookEventFacade;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
@@ -128,14 +127,14 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook
try
{
Repository repository = rpack.getRepository();
String id = resolveRepositoryId(repository);
String repositoryId = resolveRepositoryId(repository);
logger.trace("resolved repository to id {}", id);
logger.trace("resolved repository to {}", repositoryId);
GitHookContextProvider context = new GitHookContextProvider(rpack,
receiveCommands);
hookEventFacade.handle(id).fireHookEvent(type, context);
hookEventFacade.handle(repositoryId).fireHookEvent(type, context);
}
catch (Exception ex)
@@ -187,20 +186,10 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook
*
* @throws IOException
*/
private String resolveRepositoryId(Repository repository) throws IOException
private String resolveRepositoryId(Repository repository)
{
File directory;
if (repository.isBare())
{
directory = repository.getDirectory();
}
else
{
directory = repository.getWorkTree();
}
return RepositoryUtil.getRepositoryId(handler, directory);
StoredConfig gitConfig = repository.getConfig();
return handler.getRepositoryId(gitConfig);
}
//~--- fields ---------------------------------------------------------------