public void run() throws Exception { try { LOGGER.info("Before GC: {}", git.gc().getStatistics()); LOGGER.debug("Before GC: Size - {}", getConfigRepoDisplaySize()); long expireTimeInMs = systemEnvironment.getConfigGitGCExpireTime(); git.gc().setAggressive(systemEnvironment.get(SystemEnvironment.GO_CONFIG_REPO_GC_AGGRESSIVE)) .setExpire(new Date(System.currentTimeMillis() - expireTimeInMs)) .call(); LOGGER.info("After GC: {}", git.gc().getStatistics()); LOGGER.debug("After GC: Size: {}", getConfigRepoDisplaySize()); } catch (GitAPIException e) { LOGGER.error("Could not perform GC", e); throw e; } } });
/** * Return a command object to execute a {@code gc} command * * @see <a href= * "http://www.kernel.org/pub/software/scm/git/docs/git-gc.html" >Git * documentation about gc</a> * @return a {@link org.eclipse.jgit.api.GarbageCollectCommand} used to * collect all optional parameters and to finally execute the * {@code gc} command * @since 2.2 */ public GarbageCollectCommand gc() { return new GarbageCollectCommand(repo); }
public Void call(Git git, GitContext context) throws Exception { long before = System.currentTimeMillis(); try { git.gc().call(); LOGGER.debug("git gc took " + ((System.currentTimeMillis() - before)) + " ms."); } catch (GitAPIException e) { LOGGER.debug("git gc threw an exception!", e); } return null; } };
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { Properties ret = git.gc(). setProgressMonitor(new PrintlnProgressMonitor()).call(); for(Map.Entry<Object, Object> entry : ret.entrySet()) { System.out.println("Ret: " + entry.getKey() + ": " + entry.getValue()); } } } }
LOGGER.info("Performing 'git gc' after {} merges", MAX_MERGES_WITHOUT_GC); try { git.gc().setAggressive(true).call(); } catch (Exception e) { LOGGER.warn("Problem invoking 'git gc': {}", e.getMessage());
checkCallable(); return toProperties(gc.getStatistics()); } catch (ParseException e) { throw new JGitInternalException(JGitText.get().gcFailed, e);
@Override public GarbageCollectCommand gc() { return super.gc().setProgressMonitor(progressMonitor("gc")); }
public Properties getStatistics() throws GitAPIException { // not inside a doLocked/synchronized block because we don't want to block the server status service. return git.gc().getStatistics(); }
/** * Computes and returns the repository statistics. * * @return the repository statistics * @throws org.eclipse.jgit.api.errors.GitAPIException * thrown if the repository statistics cannot be computed * @since 3.0 */ public Properties getStatistics() throws GitAPIException { try { if (repo instanceof FileRepository) { GC gc = new GC((FileRepository) repo); return toProperties(gc.getStatistics()); } else { return new Properties(); } } catch (IOException e) { throw new JGitInternalException( JGitText.get().couldNotGetRepoStatistics, e); } }
private void execute(Repository repository, GarbageCollectCommand gcc) throws GitAPIException { Properties properties = gcc.call(); logger.info(message(repository, properties, "after")); }
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { Properties ret = git.gc(). setProgressMonitor(new PrintlnProgressMonitor()).call(); for(Map.Entry<Object, Object> entry : ret.entrySet()) { System.out.println("Ret: " + entry.getKey() + ": " + entry.getValue()); } } } }
@Override public Properties call() throws GitAPIException { checkCallable(); return toProperties(gc.getStatistics()); } catch (ParseException e) { throw new JGitInternalException(JGitText.get().gcFailed, e);
@Override public GarbageCollectCommand gc() { return super.gc().setProgressMonitor(progressMonitor("gc")); }
@Test public void shouldNotPerformGCWhenPeriodicGCIsTurnedOff() throws Exception { when(systemEnvironment.get(SystemEnvironment.GO_CONFIG_REPO_PERIODIC_GC)).thenReturn(false); configRepo.checkin(goConfigRevision("v1", "md5-1")); Long numberOfLooseObjectsOld = (Long) configRepo.git().gc().getStatistics().get("sizeOfLooseObjects"); configRepo.garbageCollect(); Long numberOfLooseObjectsNow = (Long) configRepo.git().gc().getStatistics().get("sizeOfLooseObjects"); assertThat(numberOfLooseObjectsNow, is(numberOfLooseObjectsOld)); }
/** * Computes and returns the repository statistics. * * @return the repository statistics * @throws GitAPIException * thrown if the repository statistics cannot be computed * @since 3.0 */ public Properties getStatistics() throws GitAPIException { try { if (repo instanceof FileRepository) { GC gc = new GC((FileRepository) repo); return toProperties(gc.getStatistics()); } else { return new Properties(); } } catch (IOException e) { throw new JGitInternalException( JGitText.get().couldNotGetRepoStatistics, e); } }
public Void call(Git git, GitContext context) throws Exception { long before = System.currentTimeMillis(); try { git.gc().call(); LOGGER.debug("git gc took " + ((System.currentTimeMillis() - before)) + " ms."); } catch (GitAPIException e) { LOGGER.debug("git gc threw an exception!", e); } return null; } };
checkCallable(); return toProperties(gc.getStatistics()); } catch (ParseException e) { throw new JGitInternalException(JGitText.get().gcFailed, e);
@Override public GarbageCollectCommand gc() { return super.gc().setProgressMonitor(progressMonitor("gc")); }
@Test public void shouldPerformGC() throws Exception { configRepo.checkin(goConfigRevision("v1", "md5-1")); Long numberOfLooseObjects = (Long) configRepo.git().gc().getStatistics().get("sizeOfLooseObjects"); assertThat(numberOfLooseObjects > 0l, is(true)); configRepo.garbageCollect(); numberOfLooseObjects = (Long) configRepo.git().gc().getStatistics().get("sizeOfLooseObjects"); assertThat(numberOfLooseObjects, is(0l)); }