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

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

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

Git.log介绍

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

代码示例

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

Iterable<RevCommit> revisions() throws GitAPIException {
  LogCommand command = git.log();
  return command.call();
}

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

public Long commitCountOnMaster() throws GitAPIException, IncorrectObjectTypeException, MissingObjectException {
    // not inside a doLocked/synchronized block because we don't want to block the server status service.
    // we do a `git branch` because we switch branches as part of normal git operations,
    // and we don't care about number of commits on those branches.
    List<Ref> branches = git.branchList().call();
    for (Ref branch : branches) {
      if (branch.getName().equals("refs/heads/master")) {
        Iterable<RevCommit> commits = git.log().add(branch.getObjectId()).call();
        long count = 0;
        for (RevCommit commit : commits) {
          count++;
        }
        return count;
      }
    }
    return Long.valueOf(-1);
  }
}

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

public GoConfigRevisions getCommits(final int pageSize, final int offset) {
  return doLocked(() -> {
    GoConfigRevisions goConfigRevisions = new GoConfigRevisions();
    try {
      LogCommand command = git.log().setMaxCount(pageSize).setSkip(offset);
      Iterable<RevCommit> revisions = command.call();
      for (RevCommit revision : revisions) {
        GoConfigRevision goConfigRevision = new GoConfigRevision((byte[]) null, revision.getFullMessage());
        goConfigRevision.setCommitSHA(revision.name());
        goConfigRevisions.add(goConfigRevision);
      }
    } catch (Exception e) {
      // ignore
    }
    return goConfigRevisions;
  });
}

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory resolveCommit(String revstr) throws IOException, GitAPIException {
  ObjectId objectId = getWrappedObject().getRepository().resolve(revstr);
  if (objectId == null) {
    return Memory.NULL;
  }
  LogCommand command = getWrappedObject()
      .log()
      .add(objectId)
      .setMaxCount(1);
  Iterable<RevCommit> call = command.call();
  for (RevCommit revCommit : call) {
    return GitUtils.valueOf(revCommit);
  }
  return Memory.NULL;
}

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

private static RevCommitsPair resolveRevCommitsPair(Repository repo) {
  RevCommitsPair revCommitIteratorPair;
  try (RevWalk revWalk = new RevWalk(repo); Git git = new Git(repo)) {
    final Iterator<RevCommit> first;
    final Iterator<RevCommit> second;
    final ObjectId headId = repo.resolve(Constants.HEAD);
    final RevCommit headCommit = revWalk.parseCommit(headId);
    if (isMergeCommit(headCommit)) {
      final RevCommit firstParent = headCommit.getParent(0);
      final RevCommit secondParent = headCommit.getParent(1);
      first = git.log().add(firstParent).call().iterator();
      second = git.log().add(secondParent).call().iterator();
    }
    else {
      first = git.log().call().iterator();
      second = Collections.emptyIterator();
    }
    revCommitIteratorPair =
        new RevCommitsPair(new OmitMergeCommitsIterator(first),
            new OmitMergeCommitsIterator(second));
  }
  catch (GitAPIException | IOException ignored) {
    revCommitIteratorPair = new RevCommitsPair();
  }
  return revCommitIteratorPair;
}

代码示例来源:origin: apache/incubator-gobblin

} catch (FileNotFoundException e) {
 Iterable<RevCommit> logs = git.log().call();
 RevCommit lastLog = null;

代码示例来源:origin: FlowCI/flow-platform

/**
 * List branch commits
 * @param path
 * @return
 * @throws GitException
 */
public static List<RevCommit> listCommits(Path path) throws GitException {
  try (Git git = Git.open(path.toFile())) {
    Iterable<RevCommit> iterable = git.log().call();
    List<RevCommit> commits = stream(iterable.spliterator(), false).collect(toList());
    return commits;
  } catch (Throwable throwable) {
    throw new GitException("get commits error", throwable);
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory log(Environment env, ArrayMemory settings) throws Throwable {
  LogCommand log = getWrappedObject().log();

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

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      try (Git git = new Git(repository)) {
        Iterable<RevCommit> commits = git.log().all().call();
        int count = 0;
        for (RevCommit commit : commits) {
          System.out.println("LogCommit: " + commit);
          count++;
        }
        System.out.println(count);
      }
    }
  }
}

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

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      try (Git git = new Git(repository)) {
        Iterable<RevCommit> commits = git.log().all().call();
        int count = 0;
        for (RevCommit commit : commits) {
          System.out.println("LogCommit: " + commit);
          count++;
        }
        System.out.println(count);
      }
    }
  }
}

代码示例来源:origin: yacy/yacy_grid_mcp

public GitTool() {
  File gitWorkDir = new File(".");
  try {
    Git git = Git.open(gitWorkDir);
    Iterable<RevCommit> commits = git.log().all().call();
    Repository repo = git.getRepository();
    branch = repo.getBranch();
    RevCommit latestCommit = commits.iterator().next();
    name = latestCommit.getName();
    message = latestCommit.getFullMessage();
  } catch (Throwable e) {
    name = "";
    message = "";
    branch = "";
  }
}

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

try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
  try (Git git = new Git(repository)) {
    Iterable<RevCommit> logs = git.log()
        .call();
    int count = 0;
    logs = git.log()
        .add(repository.resolve("remotes/origin/testbranch"))
        .call();
    logs = git.log()
        .not(repository.resolve("master"))
        .add(repository.resolve("remotes/origin/testbranch"))
    logs = git.log()
        .all()
        .call();
    logs = git.log()
    logs = git.log()

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

try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
  try (Git git = new Git(repository)) {
    Iterable<RevCommit> logs = git.log()
        .call();
    int count = 0;
    logs = git.log()
        .add(repository.resolve("remotes/origin/testbranch"))
        .call();
    logs = git.log()
        .not(repository.resolve("master"))
        .add(repository.resolve("remotes/origin/testbranch"))
    logs = git.log()
        .all()
        .call();
    logs = git.log()
    logs = git.log()

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

Iterable<RevCommit> commitsToUse;
try (Git git = new Git(repo)) {
  LogCommand cmd = git.log().addRange(upstreamCommit, headCommit);
  commitsToUse = cmd.call();

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

Iterable<RevCommit> gitLog = git.log().call();
for (RevCommit logMessage : gitLog) {
  System.out.println("Before revert: " + logMessage.getName() + " - " + logMessage.getFullMessage());
gitLog = git.log().call();
for (RevCommit logMessage : gitLog) {
  System.out.println("After revert: " + logMessage.getName() + " - " + logMessage.getFullMessage());

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

Iterable<RevCommit> gitLog = git.log().call();
for (RevCommit logMessage : gitLog) {
  System.out.println("Before revert: " + logMessage.getName() + " - " + logMessage.getFullMessage());
gitLog = git.log().call();
for (RevCommit logMessage : gitLog) {
  System.out.println("After revert: " + logMessage.getName() + " - " + logMessage.getFullMessage());

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

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      try (Git git = new Git(repository)) {
        List<Ref> call = git.tagList().call();
        for (Ref ref : call) {
          System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());

          // fetch all commits for this tag
          LogCommand log = git.log();

          Ref peeledRef = repository.getRefDatabase().peel(ref);
          if(peeledRef.getPeeledObjectId() != null) {
            log.add(peeledRef.getPeeledObjectId());
          } else {
            log.add(ref.getObjectId());
          }

          Iterable<RevCommit> logs = log.call();
          for (RevCommit rev : logs) {
            System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
          }
        }
      }
    }
  }
}

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

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      try (Git git = new Git(repository)) {
        List<Ref> call = git.tagList().call();
        for (Ref ref : call) {
          System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());

          // fetch all commits for this tag
          LogCommand log = git.log();

          Ref peeledRef = repository.getRefDatabase().peel(ref);
          if(peeledRef.getPeeledObjectId() != null) {
            log.add(peeledRef.getPeeledObjectId());
          } else {
            log.add(ref.getObjectId());
          }

          Iterable<RevCommit> logs = log.call();
          for (RevCommit rev : logs) {
            System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
          }
        }
      }
    }
  }
}

代码示例来源:origin: org.openmrs.maven.plugins/openmrs-sdk-maven-plugin

/**
 * @inheritDoc
 */
@Override
public RevCommit getLastCommit(Git git){
  try {
    return git.log().setMaxCount(1).call().iterator().next();
  } catch (GitAPIException e) {
    throw new RuntimeException("Failed to access local repository data",e);
  }
}

代码示例来源:origin: maks/MGit

private RevCommit getLatestCommit() {
  try {
    Iterable<RevCommit> commits = getGit().log().setMaxCount(1).call();
    Iterator<RevCommit> it = commits.iterator();
    if (!it.hasNext())
      return null;
    return it.next();
  } catch (GitAPIException|StopTaskException e) {
    Timber.e(e);
  }
  return null;
}

相关文章