org.eclipse.jgit.api.Git.gc()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中org.eclipse.jgit.api.Git.gc()方法的一些代码示例,展示了Git.gc()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Git.gc()方法的具体详情如下:
包路径:org.eclipse.jgit.api.Git
类名称:Git
方法名:gc

Git.gc介绍

[英]Return a command object to execute a gc command
[中]返回命令对象以执行gc命令

代码示例

代码示例来源:origin: gocd/gocd

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();
}

代码示例来源:origin: gocd/gocd

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;
    }
  }
});

代码示例来源:origin: gocd/gocd

@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));
}

代码示例来源:origin: gocd/gocd

@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));
}

代码示例来源:origin: gocd/gocd

@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));
}

代码示例来源:origin: centic9/jgit-cookbook

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());
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

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());
      }
    }
  }
}

代码示例来源:origin: kiegroup/appformer

public GarbageCollectCommand _gc() {
  return git.gc();
}

代码示例来源:origin: io.fabric8/fabric-git

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;
  }
};

代码示例来源:origin: jboss-fuse/fabric8

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;
  }
};

代码示例来源:origin: indeedeng/proctor

@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;
  }
});

代码示例来源:origin: com.indeed/proctor-store-git

@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;
  }
});

代码示例来源:origin: org.apache.camel/camel-git

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);
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server-shaded

@Override
public GarbageCollectCommand gc() {
  return super.gc().setProgressMonitor(progressMonitor("gc"));
}

代码示例来源:origin: line/centraldogma

@Override
public GarbageCollectCommand gc() {
  return super.gc().setProgressMonitor(progressMonitor("gc"));
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server

@Override
public GarbageCollectCommand gc() {
  return super.gc().setProgressMonitor(progressMonitor("gc"));
}

代码示例来源:origin: sonia.scm.plugins/scm-git-plugin

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();
  }
 }
}

代码示例来源:origin: io.fabric8/fabric-git

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);
  }
}

代码示例来源:origin: io.github.svndump-to-git/git-importer

GarbageCollectCommand gc = new Git(repo).gc();

代码示例来源:origin: jboss-fuse/fabric8

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);
  }
}

相关文章