From 4fcac9d2cbdafb51e3ee9ca3b3da64fd86103174 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Tue, 26 Nov 2013 15:58:15 -0500
Subject: [PATCH] Remove artifact setting from manager dialog

---
 src/main/java/com/gitblit/GCExecutor.java |   78 ++++++++++++++++++++-------------------
 1 files changed, 40 insertions(+), 38 deletions(-)

diff --git a/src/main/java/com/gitblit/GCExecutor.java b/src/main/java/com/gitblit/GCExecutor.java
index 312baf5..681065b 100644
--- a/src/main/java/com/gitblit/GCExecutor.java
+++ b/src/main/java/com/gitblit/GCExecutor.java
@@ -20,14 +20,14 @@
 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.storage.file.FileRepository;
-import org.eclipse.jgit.storage.file.GC;
-import org.eclipse.jgit.storage.file.GC.RepoStatistics;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -36,15 +36,15 @@
 
 /**
  * The GC executor handles periodic garbage collection in repositories.
- * 
+ *
  * @author James Moger
- * 
+ *
  */
 public class GCExecutor implements Runnable {
 
 	public static enum GCStatus {
 		READY, COLLECTING;
-		
+
 		public boolean exceeds(GCStatus s) {
 			return ordinal() > s.ordinal();
 		}
@@ -52,11 +52,11 @@
 	private final Logger logger = LoggerFactory.getLogger(GCExecutor.class);
 
 	private final IStoredSettings settings;
-	
+
 	private AtomicBoolean running = new AtomicBoolean(false);
-	
+
 	private AtomicBoolean forceClose = new AtomicBoolean(false);
-	
+
 	private final Map<String, GCStatus> gcCache = new ConcurrentHashMap<String, GCStatus>();
 
 	public GCExecutor(IStoredSettings settings) {
@@ -65,24 +65,24 @@
 
 	/**
 	 * Indicates if the GC executor is ready to process repositories.
-	 * 
+	 *
 	 * @return true if the GC executor is ready to process repositories
 	 */
 	public boolean isReady() {
 		return settings.getBoolean(Keys.git.enableGarbageCollection, false);
 	}
-	
+
 	public boolean isRunning() {
 		return running.get();
 	}
-	
+
 	public boolean lock(String repositoryName) {
 		return setGCStatus(repositoryName, GCStatus.COLLECTING);
 	}
 
 	/**
 	 * Tries to set a GCStatus for the specified repository.
-	 * 
+	 *
 	 * @param repositoryName
 	 * @return true if the status has been set
 	 */
@@ -100,7 +100,7 @@
 
 	/**
 	 * Returns true if Gitblit is actively collecting garbage in this repository.
-	 * 
+	 *
 	 * @param repositoryName
 	 * @return true if actively collecting garbage
 	 */
@@ -111,13 +111,13 @@
 
 	/**
 	 * Resets the GC status to ready.
-	 * 
+	 *
 	 * @param repositoryName
 	 */
 	public void releaseLock(String repositoryName) {
 		gcCache.put(repositoryName.toLowerCase(), GCStatus.READY);
 	}
-	
+
 	public void close() {
 		forceClose.set(true);
 	}
@@ -127,8 +127,8 @@
 		if (!isReady()) {
 			return;
 		}
-		
-		running.set(true);		
+
+		running.set(true);
 		Date now = new Date();
 
 		for (String repositoryName : GitBlit.self().getRepositoryList()) {
@@ -141,15 +141,15 @@
 			}
 			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;
 				}
-				
+
 				if (!isRepositoryIdle(repository)) {
 					logger.debug(MessageFormat.format("GCExecutor is skipping {0} because it is not idle", repositoryName));
 					continue;
@@ -162,12 +162,13 @@
 					logger.warn(MessageFormat.format("Can not acquire GC lock for {0}, skipping", repositoryName));
 					continue;
 				}
-				
+
 				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();
 				cal.setTime(model.lastGC);
@@ -181,17 +182,18 @@
 
 				// 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;
 				}
 			} catch (Exception e) {
@@ -204,20 +206,20 @@
 						model.lastGC = new Date();
 						GitBlit.self().updateConfiguration(repository, model);
 					}
-				
+
 					repository.close();
 				}
-				
-				// reset the GC lock 
+
+				// reset the GC lock
 				releaseLock(repositoryName);
 				logger.debug(MessageFormat.format("GCExecutor released GC lock for {0}", repositoryName));
 			}
 		}
-		
+
 		running.set(false);
 	}
-	
-	private boolean isRepositoryIdle(FileRepository repository) {
+
+	private boolean isRepositoryIdle(Repository repository) {
 		try {
 			// Read the use count.
 			// An idle use count is 2:

--
Gitblit v1.9.1