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


Java BlameResult类代码示例

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


BlameResult类属于org.eclipse.jgit.blame包,在下文中一共展示了BlameResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getBlame

import org.eclipse.jgit.blame.BlameResult; //导入依赖的package包/类
/** git blame기능을 구현함.
 * @param filePath
 * @param commitID
 * @return
 */
public List<VCBlame> getBlame(String filePath, String commitID){
	List<VCBlame> gitBlames = new ArrayList<VCBlame>();
	RevCommit commit = CommitUtils.getCommit(this.localRepo, commitID);

	try{
		BlameResult result = git.blame().setStartCommit(commit).setFilePath(filePath).call();
		// 입력 받은 커밋을 기점으로 파일의 라인 별로 코드를 분석함.
		for(int i=0; i<result.getResultContents().size(); i++)
			gitBlames.add(new VCBlame(result.getSourceCommit(i)));

	}catch(Exception e){
		System.err.println(e.getMessage());
	}
	return gitBlames;
}
 
开发者ID:forweaver,项目名称:forweaver2.0,代码行数:21,代码来源:GitUtil.java

示例4: run

import org.eclipse.jgit.blame.BlameResult; //导入依赖的package包/类
@Override
protected void run () throws GitException {
    Repository repository = getRepository();
    org.eclipse.jgit.api.BlameCommand cmd = new Git(repository).blame();
    cmd.setFilePath(Utils.getRelativePath(getRepository().getWorkTree(), file));
    if (revision != null) {
        cmd.setStartCommit(Utils.findCommit(repository, revision));
    } else if (repository.getConfig().get(WorkingTreeOptions.KEY).getAutoCRLF() != CoreConfig.AutoCRLF.FALSE) {
        // work-around for autocrlf
        cmd.setTextComparator(new AutoCRLFComparator());
    }
    cmd.setFollowFileRenames(true);
    try {
        BlameResult cmdResult = cmd.call();
        if (cmdResult != null) {
            result = getClassFactory().createBlameResult(cmdResult, repository);
        }
    } catch (GitAPIException ex) {
        throw new GitException(ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:BlameCommand.java

示例5: 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

示例6: computeBlame

import org.eclipse.jgit.blame.BlameResult; //导入依赖的package包/类
/**
 * Compute the blame data for the parent, we are not interested in the
 * specific commit but the parent, since we only want to know the last person
 * that edited this specific part of the code.
 *
 * @param entry {@link PatchListEntry}
 * @param commit Parent {@link RevCommit}
 * @return Result of blame computation, null if the computation fails
 */
private BlameResult computeBlame(final PatchListEntry entry,
    final RevCommit parent) {
  BlameCommand blameCommand = new BlameCommand(repo);
  blameCommand.setStartCommit(parent);
  blameCommand.setFilePath(entry.getNewName());
  try {
    BlameResult blameResult = blameCommand.call();
    blameResult.computeAll();
    return blameResult;
  } catch (GitAPIException ex) {
    log.error("Couldn't execute blame for commit {}", parent.getName(), ex);
  } catch (IOException err) {
    log.error("Error while computing blame for commit {}", parent.getName(),
        err);
  }
  return null;
}
 
开发者ID:Intersec,项目名称:smart-reviewers,代码行数:27,代码来源:SmartReviewers.java

示例7: getBlameForLines

import org.eclipse.jgit.blame.BlameResult; //导入依赖的package包/类
public void getBlameForLines(final String file, final int lineFrom,
		final int lineTo, final int changedTs) throws IOException {
	final BlameGenerator bg = new BlameGenerator(
			repository.getRepository(), file);
	bg.setDiffAlgorithm(MyersDiff.INSTANCE);
	bg.setTextComparator(RawTextComparator.WS_IGNORE_ALL);

	bg.push(null, repository.getRepository().resolve(Constants.HEAD));
	final BlameResult br = bg.computeBlameResult();
	br.computeRange(lineFrom, lineTo);

	for (int i = lineFrom; i < lineTo; i++) {
		final int timeDiff = changedTs
				- br.getSourceCommit(i).getCommitTime();
		System.out.println(timeDiff);
	}

	// Now store the stuff in before/after and num lines(?).
	// Maybe we need to normalize over a) all the lines b) all the lines
	// that ever changed? c) something else
	// God help us
}
 
开发者ID:mast-group,项目名称:commitmining-tools,代码行数:23,代码来源:LineLifecycle.java

示例8: 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

示例9: 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

示例10: 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

示例11: testBlameMixedLineEndings

import org.eclipse.jgit.blame.BlameResult; //导入依赖的package包/类
public void testBlameMixedLineEndings () throws Exception {
    File f = new File(workDir, "f");
    String content = "";
    for (int i = 0; i < 10000; ++i) {
        content += i + "\r\n";
    }
    write(f, content);

    // lets turn autocrlf on
    StoredConfig cfg = repository.getConfig();
    cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true");
    cfg.save();

    File[] files = new File[] { f };
    GitClient client = getClient(workDir);
    client.add(files, NULL_PROGRESS_MONITOR);
    GitRevisionInfo info = client.commit(files, "commit", null, null, NULL_PROGRESS_MONITOR);

    content = content.replaceFirst("0", "01");
    write(f, content);

    // it should be up to date again
    org.eclipse.jgit.api.BlameCommand cmd = new Git(repository).blame();
    cmd.setFilePath("f");
    BlameResult blameResult = cmd.call();
    assertEquals(info.getRevision(), blameResult.getSourceCommit(1).getName());
    
    GitBlameResult res = client.blame(f, null, NULL_PROGRESS_MONITOR);
    assertNull(res.getLineDetails(0));
    assertLineDetails(f, 1, info.getRevision(), info.getAuthor(), info.getCommitter(), res.getLineDetails(1));
    
    // without autocrlf it should all be modified
    cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "false");
    cfg.save();
    res = client.blame(f, null, NULL_PROGRESS_MONITOR);
    assertNull(res.getLineDetails(1));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:BlameTest.java

示例12: blame

import org.eclipse.jgit.blame.BlameResult; //导入依赖的package包/类
public List<GitBlame> blame(Workspace ws, String path) throws AccessDeniedException, GitAPIException {
    Repository repository = getRepository(ws.getSpaceKey());

    String relativePath = ws.getRelativePath(path).toString();

    try (Git git = Git.wrap(repository)) {
        BlameResult blameResult = git.blame()
                .setFilePath(relativePath)
                .setFollowFileRenames(true)
                .call();

        if (blameResult == null) { // file not exist
            return Lists.newArrayList();
        }

        int lineCnt = blameResult.getResultContents().size();

        return IntStream.range(0, lineCnt)
                .mapToObj(i -> {
                    org.eclipse.jgit.lib.PersonIdent author = blameResult.getSourceAuthor(i);
                    RevCommit commit = blameResult.getSourceCommit(i);

                    GitBlame.GitBlameBuilder builder = GitBlame.builder()
                            .author(mapper.map(author, PersonIdent.class));

                    if (commit != null) {
                        builder.shortName(commit.abbreviate(ABBREVIATION_LENGTH).name());
                    }

                    return builder.build();
                }).collect(Collectors.toList());
    }
}
 
开发者ID:Coding,项目名称:WebIDE-Backend,代码行数:34,代码来源:GitManagerImpl.java

示例13: 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

示例14: blame

import org.eclipse.jgit.blame.BlameResult; //导入依赖的package包/类
@Override
public BlameModel blame(String commitId,
                        String filePath) throws IOException, GitException {

	Preconditions.checkNotNull(commitId);
	Preconditions.checkNotNull(filePath);

	try {
		BlameResult blameResult = git.blame()
			.setStartCommit(repo.resolve(commitId))
			.setFilePath(filePath)
			.setFollowFileRenames(true)
			.call();

		if(blameResult == null) {
			throw new NotFoundException(String.format("%s not found in %S at %s", filePath,
				repository.toString(), commitId));
		}

		return transformBlameModel(blameResult, commitId, filePath);
	}
	catch (JGitInternalException | GitAPIException e) {
		Throwable cause = e.getCause();
		if(MissingObjectException.class.isInstance(cause)) {
			throw new NotFoundException(cause.getMessage(), e);
		}
		throw new GitException(e);
	}
}
 
开发者ID:devhub-tud,项目名称:git-server,代码行数:30,代码来源:JGitRepositoryFacade.java

示例15: transformBlameModel

import org.eclipse.jgit.blame.BlameResult; //导入依赖的package包/类
protected BlameModel transformBlameModel(BlameResult input, String commitId, String path) {
	final BlameModel model = new BlameModel();
	model.setCommitId(commitId);
	model.setPath(path);
	final List<BlameBlock> blames = Lists.<BlameBlock> newArrayList();

	for(int i = 0, length = input.getResultContents().size(); i < length; i++) {
		BlameBlock block = new BlameBlock();
		block.setFromCommitId(input.getSourceCommit(i).getName());
		block.setSourceFrom(input.getSourceLine(i) + 1);
		block.setDestinationFrom(i + 1);
		block.setFromFilePath(input.getSourcePath(i));
		block.setLength(1);

		for(int j = i + 1; j < length &&
			equalCommitId(input, j, block) &&
			nextLineNumberInBlock(input, j, block); j++) {
			i++;
			block.incrementLength();
		}

		blames.add(block);
	}

	model.setBlames(blames);
	return model;
}
 
开发者ID:devhub-tud,项目名称:git-server,代码行数:28,代码来源:JGitRepositoryFacade.java


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