当前位置: 首页>>代码示例>>Java>>正文


Java BlameResult.getSourceCommit方法代码示例

本文整理汇总了Java中org.eclipse.jgit.blame.BlameResult.getSourceCommit方法的典型用法代码示例。如果您正苦于以下问题:Java BlameResult.getSourceCommit方法的具体用法?Java BlameResult.getSourceCommit怎么用?Java BlameResult.getSourceCommit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jgit.blame.BlameResult的用法示例。


在下文中一共展示了BlameResult.getSourceCommit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: blame

import org.eclipse.jgit.blame.BlameResult; //导入方法依赖的package包/类
/**
 * Returns the list of lines in the specified source file annotated with the source commit metadata.
 * 
 * @param repository
 * @param blobPath
 * @param objectId
 * @return list of annotated lines
 */
public static List<AnnotatedLine> blame(Repository repository, String blobPath, String objectId) {
	List<AnnotatedLine> lines = new ArrayList<AnnotatedLine>();
	try {
		ObjectId object;
		if (StringUtils.isEmpty(objectId)) {
			object = JGitUtils.getDefaultBranch(repository);
		} else {
			object = repository.resolve(objectId);
		}
		BlameCommand blameCommand = new BlameCommand(repository);
		blameCommand.setFilePath(blobPath);
		blameCommand.setStartCommit(object);
		BlameResult blameResult = blameCommand.call();
		RawText rawText = blameResult.getResultContents();
		int length = rawText.size();
		for (int i = 0; i < length; i++) {
			RevCommit commit = blameResult.getSourceCommit(i);
			AnnotatedLine line = new AnnotatedLine(commit, i + 1, rawText.getString(i));
			lines.add(line);
		}
	} catch (Throwable t) {
		LOGGER.error(MessageFormat.format("failed to generate blame for {0} {1}!", blobPath, objectId), t);
	}
	return lines;
}
 
开发者ID:tomaswolf,项目名称:gerrit-gitblit-plugin,代码行数:34,代码来源:DiffUtils.java

示例2: main

import org.eclipse.jgit.blame.BlameResult; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, GitAPIException {
    // prepare a new test-repository
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
        BlameCommand blamer = new BlameCommand(repository);
        ObjectId commitID = repository.resolve("HEAD~~");
        blamer.setStartCommit(commitID);
        blamer.setFilePath("README.md");
        BlameResult blame = blamer.call();

        // read the number of lines from the given revision, this excludes changes from the last two commits due to the "~~" above
        int lines = countLinesOfFileInCommit(repository, commitID, "README.md");
        for (int i = 0; i < lines; i++) {
            RevCommit commit = blame.getSourceCommit(i);
            System.out.println("Line: " + i + ": " + commit);
        }

        final int currentLines;
        try (final FileInputStream input = new FileInputStream("README.md")) {
            currentLines = IOUtils.readLines(input, "UTF-8").size();
        }

        System.out.println("Displayed commits responsible for " + lines + " lines of README.md, current version has " + currentLines + " lines");
    }
}
 
开发者ID:centic9,项目名称:jgit-cookbook,代码行数:25,代码来源:ShowBlame.java

示例3: getReviewersFromBlame

import org.eclipse.jgit.blame.BlameResult; //导入方法依赖的package包/类
/**
 * Fill a map of all the possible reviewers based on the provided blame data
 *
 * @param edits List of edits that were made for this patch
 * @param blameResult Result of blame computation
 * @param reviewers the reviewer hash table to fill
 */
private void getReviewersFromBlame(final List<Edit> edits,
    final BlameResult blameResult, Map<Account, Integer> reviewers) {
  for (Edit edit : edits) {
    for (int i = edit.getBeginA(); i < edit.getEndA(); i++) {
      RevCommit commit = blameResult.getSourceCommit(i);
      Set<Account.Id> ids =
          byEmailCache.get(commit.getAuthorIdent().getEmailAddress());

      for (Account.Id id : ids) {
        Account account = accountCache.get(id).getAccount();
        addAccount(account, reviewers, weightBlame);
      }
    }
  }
}
 
开发者ID:Intersec,项目名称:smart-reviewers,代码行数:23,代码来源:SmartReviewers.java

示例4: blame

import org.eclipse.jgit.blame.BlameResult; //导入方法依赖的package包/类
/**
 * Returns the list of lines in the specified source file annotated with the
 * source commit metadata.
 * 
 * @param repository
 * @param blobPath
 * @param objectId
 * @return list of annotated lines
 */
public static List<AnnotatedLine> blame(Repository repository, String blobPath, String objectId) {
	List<AnnotatedLine> lines = new ArrayList<AnnotatedLine>();
	try {
		ObjectId object;
		if (StringUtils.isEmpty(objectId)) {
			object = JGitUtils.getDefaultBranch(repository);
		} else {
			object = repository.resolve(objectId);
		}
		BlameCommand blameCommand = new BlameCommand(repository);
		blameCommand.setFilePath(blobPath);
		blameCommand.setStartCommit(object);
		BlameResult blameResult = blameCommand.call();
		RawText rawText = blameResult.getResultContents();
		int length = rawText.size();
		for (int i = 0; i < length; i++) {
			RevCommit commit = blameResult.getSourceCommit(i);
			AnnotatedLine line = new AnnotatedLine(commit, i + 1, rawText.getString(i));
			lines.add(line);
		}
	} catch (Throwable t) {
		LOGGER.error(MessageFormat.format("failed to generate blame for {0} {1}!", blobPath, objectId), t);
	}
	return lines;
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:35,代码来源:DiffUtils.java

示例5: main

import org.eclipse.jgit.blame.BlameResult; //导入方法依赖的package包/类
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).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));
            }
        }
    }
}
 
开发者ID:centic9,项目名称:jgit-cookbook,代码行数:27,代码来源:BlameFile.java

示例6: GitBlameResult

import org.eclipse.jgit.blame.BlameResult; //导入方法依赖的package包/类
GitBlameResult (BlameResult result, Repository repository) {
    this.lineCount = result.getResultContents().size();
    this.lineDetails = new GitLineDetails[lineCount];

    Map<String, File> cachedFiles = new HashMap<String, File>(lineCount);
    this.blamedFile = getFile(cachedFiles, result.getResultPath(), repository.getWorkTree());

    Map<RevCommit, GitRevisionInfo> cachedRevisions = new HashMap<RevCommit, GitRevisionInfo>(lineCount);
    Map<PersonIdent, GitUser> cachedUsers = new HashMap<PersonIdent, GitUser>(lineCount * 2);
    for (int i = 0; i < lineCount; ++i) {
        RevCommit commit = result.getSourceCommit(i);
        if (commit == null) {
            lineDetails[i] = null;
        } else {
            GitRevisionInfo revInfo = cachedRevisions.get(commit);
            if (revInfo == null) {
                revInfo = new GitRevisionInfo(commit, repository);
                cachedRevisions.put(commit, revInfo);
            }
            GitUser author = getUser(cachedUsers, result.getSourceAuthor(i));
            GitUser committer = getUser(cachedUsers, result.getSourceCommitter(i));
            File sourceFile = getFile(cachedFiles, result.getSourcePath(i), repository.getWorkTree());
            String content = result.getResultContents().getString(i);
            lineDetails[i] = new GitLineDetails(content, revInfo, author, committer, sourceFile, result.getSourceLine(i));
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:GitBlameResult.java

示例7: blame

import org.eclipse.jgit.blame.BlameResult; //导入方法依赖的package包/类
private void blame(BlameOutput output, Git git, File gitBaseDir, InputFile inputFile) {
  String filename = pathResolver.relativePath(gitBaseDir, inputFile.file());
  LOG.debug("Blame file {}", filename);
  BlameResult blameResult;
  try {
    blameResult = git.blame()
      // Equivalent to -w command line option
      .setTextComparator(RawTextComparator.WS_IGNORE_ALL)
      .setFilePath(filename).call();
  } catch (Exception e) {
    throw new IllegalStateException("Unable to blame file " + inputFile.relativePath(), e);
  }
  List<BlameLine> lines = new ArrayList<>();
  if (blameResult == null) {
    LOG.debug("Unable to blame file {}. It is probably a symlink.", inputFile.relativePath());
    return;
  }
  for (int i = 0; i < blameResult.getResultContents().size(); i++) {
    if (blameResult.getSourceAuthor(i) == null || blameResult.getSourceCommit(i) == null) {
      LOG.debug("Unable to blame file {}. No blame info at line {}. Is file committed? [Author: {} Source commit: {}]", inputFile.relativePath(), i + 1,
        blameResult.getSourceAuthor(i), blameResult.getSourceCommit(i));
      return;
    }
    lines.add(new BlameLine()
      .date(blameResult.getSourceCommitter(i).getWhen())
      .revision(blameResult.getSourceCommit(i).getName())
      .author(blameResult.getSourceAuthor(i).getEmailAddress()));
  }
  if (lines.size() == inputFile.lines() - 1) {
    // SONARPLUGINS-3097 Git do not report blame on last empty line
    lines.add(lines.get(lines.size() - 1));
  }
  output.blameResult(inputFile, lines);
}
 
开发者ID:SonarSource,项目名称:sonar-scm-git,代码行数:35,代码来源:JGitBlameCommand.java


注:本文中的org.eclipse.jgit.blame.BlameResult.getSourceCommit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。