summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-04-15 08:18:02 -0400
committerJames Moger <james.moger@gitblit.com>2013-04-15 08:18:02 -0400
commit843c42bafae020e2e0e6d49befc6db960f61c66c (patch)
tree0d765db364e389dea0bcad47f04dcdc2a59bd47b /src
parent47dc64a5d4b10edf2ef418d3e4b428a33420a2a2 (diff)
downloadgitblit-843c42bafae020e2e0e6d49befc6db960f61c66c.tar.gz
gitblit-843c42bafae020e2e0e6d49befc6db960f61c66c.zip
Completed migration to JGit 3.0.0-SNAPSHOT
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/gitblit/AddIndexedBranch.java7
-rw-r--r--src/main/java/com/gitblit/GCExecutor.java26
-rw-r--r--src/main/java/com/gitblit/GitBlit.java3
-rw-r--r--src/main/java/com/gitblit/utils/JGitUtils.java3
-rw-r--r--src/test/java/com/gitblit/tests/GitBlitSuite.java22
-rw-r--r--src/test/java/com/gitblit/tests/GitServletTest.java5
-rw-r--r--src/test/java/com/gitblit/tests/PushLogTest.java8
7 files changed, 42 insertions, 32 deletions
diff --git a/src/main/java/com/gitblit/AddIndexedBranch.java b/src/main/java/com/gitblit/AddIndexedBranch.java
index 67b77428..e2f3dacf 100644
--- a/src/main/java/com/gitblit/AddIndexedBranch.java
+++ b/src/main/java/com/gitblit/AddIndexedBranch.java
@@ -25,9 +25,8 @@ import java.util.TreeSet;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
-import org.eclipse.jgit.storage.file.FileBasedConfig;
+import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
-import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.util.FS;
import com.beust.jcommander.JCommander;
@@ -88,8 +87,8 @@ public class AddIndexedBranch {
try {
// load repository config
File gitDir = FileKey.resolve(new File(folder, repo), FS.DETECTED);
- FileRepository repository = (FileRepository)new FileRepositoryBuilder().setGitDir(gitDir).build();
- FileBasedConfig config = repository.getConfig();
+ Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
+ StoredConfig config = repository.getConfig();
config.load();
Set<String> indexedBranches = new LinkedHashSet<String>();
diff --git a/src/main/java/com/gitblit/GCExecutor.java b/src/main/java/com/gitblit/GCExecutor.java
index 19393aa6..0a0c8ad5 100644
--- a/src/main/java/com/gitblit/GCExecutor.java
+++ b/src/main/java/com/gitblit/GCExecutor.java
@@ -20,14 +20,14 @@ import java.text.MessageFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
+import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import org.eclipse.jgit.api.GarbageCollectCommand;
+import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.internal.storage.file.FileRepository;
-import org.eclipse.jgit.internal.storage.file.GC;
-import org.eclipse.jgit.internal.storage.file.GC.RepoStatistics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -141,10 +141,10 @@ public class GCExecutor implements Runnable {
}
boolean garbageCollected = false;
RepositoryModel model = null;
- FileRepository repository = null;
+ Repository repository = null;
try {
model = GitBlit.self().getRepositoryModel(repositoryName);
- repository = (FileRepository) GitBlit.self().getRepository(repositoryName);
+ repository = GitBlit.self().getRepository(repositoryName);
if (repository == null) {
logger.warn(MessageFormat.format("GCExecutor is missing repository {0}?!?", repositoryName));
continue;
@@ -165,8 +165,9 @@ public class GCExecutor implements Runnable {
logger.debug(MessageFormat.format("GCExecutor locked idle repository {0}", repositoryName));
- GC gc = new GC(repository);
- RepoStatistics stats = gc.getStatistics();
+ Git git = new Git(repository);
+ GarbageCollectCommand gc = git.gc();
+ Properties stats = gc.getStatistics();
// determine if this is a scheduled GC
Calendar cal = Calendar.getInstance();
@@ -181,16 +182,17 @@ public class GCExecutor implements Runnable {
// determine if filesize triggered GC
long gcThreshold = FileUtils.convertSizeToLong(model.gcThreshold, 500*1024L);
- boolean hasEnoughGarbage = stats.sizeOfLooseObjects >= gcThreshold;
+ long sizeOfLooseObjects = (Long) stats.get("sizeOfLooseObjects");
+ boolean hasEnoughGarbage = sizeOfLooseObjects >= gcThreshold;
// if we satisfy one of the requirements, GC
- boolean hasGarbage = stats.sizeOfLooseObjects > 0;
+ boolean hasGarbage = sizeOfLooseObjects > 0;
if (hasGarbage && (hasEnoughGarbage || shouldCollectGarbage)) {
- long looseKB = stats.sizeOfLooseObjects/1024L;
+ long looseKB = sizeOfLooseObjects/1024L;
logger.info(MessageFormat.format("Collecting {1} KB of loose objects from {0}", repositoryName, looseKB));
// do the deed
- gc.gc();
+ gc.call();
garbageCollected = true;
}
@@ -217,7 +219,7 @@ public class GCExecutor implements Runnable {
running.set(false);
}
- private boolean isRepositoryIdle(FileRepository repository) {
+ private boolean isRepositoryIdle(Repository repository) {
try {
// Read the use count.
// An idle use count is 2:
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java
index 27ab6ecf..0f1b73bf 100644
--- a/src/main/java/com/gitblit/GitBlit.java
+++ b/src/main/java/com/gitblit/GitBlit.java
@@ -71,7 +71,6 @@ import org.eclipse.jgit.lib.RepositoryCache;
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.storage.file.FileBasedConfig;
-import org.eclipse.jgit.internal.storage.file.WindowCache;
import org.eclipse.jgit.storage.file.WindowCacheConfig;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
@@ -3186,7 +3185,7 @@ public class GitBlit implements ServletContextListener {
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()));
diff --git a/src/main/java/com/gitblit/utils/JGitUtils.java b/src/main/java/com/gitblit/utils/JGitUtils.java
index 8a02a652..1e0ea5d6 100644
--- a/src/main/java/com/gitblit/utils/JGitUtils.java
+++ b/src/main/java/com/gitblit/utils/JGitUtils.java
@@ -67,7 +67,6 @@ import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.revwalk.filter.CommitTimeRevFilter;
import org.eclipse.jgit.revwalk.filter.RevFilter;
-import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.FetchResult;
@@ -199,7 +198,7 @@ public class JGitUtils {
File folder = new File(repositoriesFolder, name);
if (folder.exists()) {
File gitDir = FileKey.resolve(new File(repositoriesFolder, name), FS.DETECTED);
- FileRepository repository = (FileRepository)new FileRepositoryBuilder().setGitDir(gitDir).build();
+ Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
result.fetchResult = fetchRepository(credentialsProvider, repository);
repository.close();
} else {
diff --git a/src/test/java/com/gitblit/tests/GitBlitSuite.java b/src/test/java/com/gitblit/tests/GitBlitSuite.java
index 0b8437a6..82552ec1 100644
--- a/src/test/java/com/gitblit/tests/GitBlitSuite.java
+++ b/src/test/java/com/gitblit/tests/GitBlitSuite.java
@@ -25,7 +25,7 @@ import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache;
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
-import org.eclipse.jgit.internal.storage.file.FileRepository;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.util.FS;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -78,32 +78,38 @@ public class GitBlitSuite {
private static AtomicBoolean started = new AtomicBoolean(false);
public static Repository getHelloworldRepository() throws Exception {
- return new FileRepository(new File(REPOSITORIES, "helloworld.git"));
+ return getRepository("helloworld.git");
}
public static Repository getTicgitRepository() throws Exception {
- return new FileRepository(new File(REPOSITORIES, "ticgit.git"));
+ return getRepository("ticgit.git");
}
public static Repository getJGitRepository() throws Exception {
- return new FileRepository(new File(REPOSITORIES, "test/jgit.git"));
+ return getRepository("test/jgit.git");
}
public static Repository getAmbitionRepository() throws Exception {
- return new FileRepository(new File(REPOSITORIES, "test/ambition.git"));
+ return getRepository("test/ambition.git");
}
public static Repository getTheoreticalPhysicsRepository() throws Exception {
- return new FileRepository(new File(REPOSITORIES, "test/theoretical-physics.git"));
+ return getRepository("test/theoretical-physics.git");
}
public static Repository getIssuesTestRepository() throws Exception {
JGitUtils.createRepository(REPOSITORIES, "gb-issues.git").close();
- return new FileRepository(new File(REPOSITORIES, "gb-issues.git"));
+ return getRepository("gb-issues.git");
}
public static Repository getGitectiveRepository() throws Exception {
- return new FileRepository(new File(REPOSITORIES, "test/gitective.git"));
+ return getRepository("test/gitective.git");
+ }
+
+ private static Repository getRepository(String name) throws Exception {
+ File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED);
+ Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
+ return repository;
}
public static boolean startGitblit() throws Exception {
diff --git a/src/test/java/com/gitblit/tests/GitServletTest.java b/src/test/java/com/gitblit/tests/GitServletTest.java
index 6f1d600d..c1aaf1a3 100644
--- a/src/test/java/com/gitblit/tests/GitServletTest.java
+++ b/src/test/java/com/gitblit/tests/GitServletTest.java
@@ -19,8 +19,9 @@ import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.internal.storage.file.FileRepository;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.PushResult;
import org.eclipse.jgit.transport.RefSpec;
@@ -786,7 +787,7 @@ public class GitServletTest {
public void testPushLog() throws IOException {
String name = "refchecks/ticgit.git";
File refChecks = new File(GitBlitSuite.REPOSITORIES, name);
- FileRepository repository = new FileRepository(refChecks);
+ Repository repository = new FileRepositoryBuilder().setGitDir(refChecks).build();
List<PushLogEntry> pushes = PushLogUtils.getPushLog(name, repository);
GitBlitSuite.close(repository);
assertTrue("Repository has an empty push log!", pushes.size() > 0);
diff --git a/src/test/java/com/gitblit/tests/PushLogTest.java b/src/test/java/com/gitblit/tests/PushLogTest.java
index 0e01344e..0f46b53b 100644
--- a/src/test/java/com/gitblit/tests/PushLogTest.java
+++ b/src/test/java/com/gitblit/tests/PushLogTest.java
@@ -19,7 +19,10 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
-import org.eclipse.jgit.internal.storage.file.FileRepository;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.RepositoryCache.FileKey;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
+import org.eclipse.jgit.util.FS;
import org.junit.Test;
import com.gitblit.models.PushLogEntry;
@@ -30,7 +33,8 @@ public class PushLogTest {
@Test
public void testPushLog() throws IOException {
String name = "~james/helloworld.git";
- FileRepository repository = new FileRepository(new File(GitBlitSuite.REPOSITORIES, name));
+ File gitDir = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, name), FS.DETECTED);
+ Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
List<PushLogEntry> pushes = PushLogUtils.getPushLog(name, repository);
GitBlitSuite.close(repository);
}