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(); }
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; } } });
@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)); }
@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)); }
@Test public void shouldGetLooseObjectCount() throws Exception { configRepo.checkin(goConfigRevision("v1", "md5-1")); Long numberOfLooseObjects = (Long) configRepo.git().gc().getStatistics().get("numberOfLooseObjects"); assertThat(configRepo.getLooseObjectCount(), is(numberOfLooseObjects)); }
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()); } } } }
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()); } } } }
public GarbageCollectCommand _gc() { return git.gc(); }
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 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; } };
@Override public Void call() { try { LOGGER.info("Start running `git gc` command to clean up git garbage"); final Properties call = getGit().gc().call(); LOGGER.info("`git gc` has been completed " + call.toString()); } catch (final GitAPIException e) { LOGGER.error("Failed to run `git gc` command.", e); } return null; } });
@Override public Void call() { try { LOGGER.info("Start running `git gc` command to clean up git garbage"); final Properties call = getGit().gc().call(); LOGGER.info("`git gc` has been completed " + call.toString()); } catch (final GitAPIException e) { LOGGER.error("Failed to run `git gc` command.", e); } return null; } });
protected void doGc(Exchange exchange, String operation) throws Exception { Properties result = null; try { result = git.gc().call(); } catch (Exception e) { LOG.error("There was an error in Git {} operation", operation); throw e; } updateExchange(exchange, result); }
@Override public GarbageCollectCommand gc() { return super.gc().setProgressMonitor(progressMonitor("gc")); }
@Override public GarbageCollectCommand gc() { return super.gc().setProgressMonitor(progressMonitor("gc")); }
@Override public GarbageCollectCommand gc() { return super.gc().setProgressMonitor(progressMonitor("gc")); }
private void gc(Repository repository){ File file = repositoryHandler.getDirectory(repository); Git git = null; try { git = open(file); GarbageCollectCommand gcc = git.gc(); // print statistics before execution, because it looks like // jgit returns the statistics after gc has finished statistics(repository, gcc); execute(repository, gcc); } catch (IOException ex) { logger.warn("failed to open git repository", ex); } catch (GitAPIException ex) { logger.warn("failed running git gc command", ex); } finally { if (git != null){ git.close(); } } }
private void doCommit(Git git, GitContext context) { try { String message = context.getCommitMessage(); IllegalStateAssertion.assertTrue(message.length() > 0, "Empty commit message"); // git add --all git.add().addFilepattern(".").call(); // git commit -m message git.commit().setMessage(message).call(); if (--commitsWithoutGC < 0) { commitsWithoutGC = MAX_COMMITS_WITHOUT_GC; LOGGER.debug("Performing 'git gc' after {} commits", MAX_COMMITS_WITHOUT_GC); git.gc().call(); } } catch (GitAPIException ex) { throw FabricException.launderThrowable(ex); } }
GarbageCollectCommand gc = new Git(repo).gc();
private void doCommit(Git git, GitContext context) { try { String message = context.getCommitMessage(); IllegalStateAssertion.assertTrue(message.length() > 0, "Empty commit message"); // git add --all git.add().addFilepattern(".").call(); // git commit -m message git.commit().setMessage(message).call(); if (--commitsWithoutGC < 0) { commitsWithoutGC = MAX_COMMITS_WITHOUT_GC; LOGGER.debug("Performing 'git gc' after {} commits", MAX_COMMITS_WITHOUT_GC); git.gc().call(); } } catch (GitAPIException ex) { throw FabricException.launderThrowable(ex); } }