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

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

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

Git.blame介绍

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

代码示例

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

public static void main(String args[])
    throws IOException, GitAPIException {
    try (Repository repo = CookbookHelper.openJGitCookbookRepository()) {
      final String[] list = new File(".").list();
      if(list == null) {
        throw new IllegalStateException("Did not find any files at " + new File(".").getAbsolutePath());
      }

      for(String file : list) {
        if(new File(file).isDirectory()) {
          continue;
        }

        System.out.println("Blaming " + file);
        final BlameResult result = new Git(repo).blame().setFilePath(file)
          .setTextComparator(RawTextComparator.WS_IGNORE_ALL).call();
        final RawText rawText = result.getResultContents();
        for (int i = 0; i < rawText.size(); i++) {
          final PersonIdent sourceAuthor = result.getSourceAuthor(i);
          final RevCommit sourceCommit = result.getSourceCommit(i);
          System.out.println(sourceAuthor.getName() +
              (sourceCommit != null ? "/" + sourceCommit.getCommitTime() + "/" + sourceCommit.getName() : "") +
              ": " + rawText.getString(i));
        }
      }
    }
  }
}

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

public static void main(String args[])
    throws IOException, GitAPIException {
    try (Repository repo = CookbookHelper.openJGitCookbookRepository()) {
      final String[] list = new File(".").list();
      if(list == null) {
        throw new IllegalStateException("Did not find any files at " + new File(".").getAbsolutePath());
      }

      for(String file : list) {
        if(new File(file).isDirectory()) {
          continue;
        }

        System.out.println("Blaming " + file);
        final BlameResult result = new Git(repo).blame().setFilePath(file)
          .setTextComparator(RawTextComparator.WS_IGNORE_ALL).call();
        final RawText rawText = result.getResultContents();
        for (int i = 0; i < rawText.size(); i++) {
          final PersonIdent sourceAuthor = result.getSourceAuthor(i);
          final RevCommit sourceCommit = result.getSourceCommit(i);
          System.out.println(sourceAuthor.getName() +
              (sourceCommit != null ? "/" + sourceCommit.getCommitTime() + "/" + sourceCommit.getName() : "") +
              ": " + rawText.getString(i));
        }
      }
    }
  }
}

代码示例来源:origin: mauricioaniche/repodriller

public List<BlamedLine> blame(String file, String commitToBeBlamed, boolean priorCommit) {
  try (Git git = openRepository()) {
    ObjectId gitCommitToBeBlamed;
    if (priorCommit) {
      Iterable<RevCommit> commits = git.log().add(git.getRepository().resolve(commitToBeBlamed)).call();
      gitCommitToBeBlamed = commits.iterator().next().getParent(0).getId();
    } else {
      gitCommitToBeBlamed = git.getRepository().resolve(commitToBeBlamed);
    }
    BlameResult blameResult = git.blame().setFilePath(file).setStartCommit(gitCommitToBeBlamed).setFollowFileRenames(true).call();
    if (blameResult != null) {
      int rows = blameResult.getResultContents().size();
      List<BlamedLine> result = new ArrayList<>();
      for (int i = 0; i < rows; i++) {
        result.add(new BlamedLine(i,
            blameResult.getResultContents().getString(i),
            blameResult.getSourceAuthor(i).getName(),
            blameResult.getSourceCommitter(i).getName(),
            blameResult.getSourceCommit(i).getId().getName()));
      }
      return result;
    } else {
      throw new RuntimeException("BlameResult not found.");
    }
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.sonarsource.scm.git/sonar-scm-git-plugin

BlameResult blameResult;
try {
 blameResult = git.blame()

代码示例来源:origin: org.apache.maven.scm/maven-scm-provider-jgit

BlameResult blameResult = git.blame().setFilePath( filename ).call();

代码示例来源:origin: apache/maven-scm

BlameResult blameResult = git.blame().setFilePath( filename ).call();

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

org.eclipse.jgit.api.BlameCommand blame = new Git(gr).blame();

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

git = new Git(gr);
BlameCommand blame = git.blame();

相关文章