Java Code Examples for org.eclipse.jgit.api.BlameCommand#setStartCommit()
The following examples show how to use
org.eclipse.jgit.api.BlameCommand#setStartCommit() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Git.java From OpenSZZ-Cloud-Native with GNU General Public License v3.0 | 6 votes |
/** * It gets blame of a file at a specific commit time * index 0 of array ==> line 0 * index 1 of array ==> line 1 * index 2 of array ==> line 2 * @param commitSha * @param file * @param git * @return */ //removed unused parameter PrintWriter l public String getBlameAt(String commitSha, String file, int lineNumber) { File localRepo1 = new File(workingDirectory+""); try { if (blame==null){ org.eclipse.jgit.api.Git git = org.eclipse.jgit.api.Git.open(localRepo1); Repository repository = git.getRepository(); BlameCommand blamer = new BlameCommand(repository); ObjectId commitID; commitID = repository.resolve(commitSha); blamer.setStartCommit(commitID); blamer.setFilePath(file); blame = blamer.call();} RevCommit commit = blame.getSourceCommit(lineNumber); return commit.getName(); } catch (Exception e) { return null; } }
Example 2
Source File: GitRepository.java From mojito with Apache License 2.0 | 6 votes |
/** * Get the git-blame information for entire file * * @param filePath * @return * @throws CommandException */ public BlameResult getBlameResultForFile(String filePath) throws CommandException { logger.debug("getBlameResultForFile: {}", filePath); try { BlameCommand blamer = new BlameCommand(jgitRepository); ObjectId commitID = jgitRepository.resolve("HEAD"); blamer.setStartCommit(commitID); blamer.setFilePath(filePath); BlameResult blame = blamer.call(); return blame; } catch (GitAPIException | IOException e) { String msg = MessageFormat.format("Can't get blame result for file: {0}", filePath); logger.error(msg, e); throw new CommandException(msg, e); } }
Example 3
Source File: GitRevisionInformationProvider.java From jdt-codemining with Eclipse Public License 1.0 | 4 votes |
@Override public RevisionInformation getRevisionInformation(IResource resource) { RepositoryMapping mapping = RepositoryMapping.getMapping(resource); if (mapping == null) { return null; } Repository repository = mapping.getRepository(); if (repository == null) { return null; } String path = mapping.getRepoRelativePath(resource); if (path == null) { return null; } final BlameCommand command = new BlameCommand(repository).setFollowFileRenames(true).setFilePath(path); try { command.setStartCommit(repository.resolve(Constants.HEAD)); } catch (IOException e) { return null; } command.setTextComparator(RawTextComparator.WS_IGNORE_ALL); BlameResult result; try { result = command.call(); } catch (Exception e1) { // Activator.error(e1.getMessage(), e1); return null; } // progress.worked(1); if (result == null) return null; RevisionInformation info = new RevisionInformation(); Map<RevCommit, BlameRevision> revisions = new HashMap<>(); int lineCount = result.getResultContents().size(); BlameRevision previous = null; for (int i = 0; i < lineCount; i++) { RevCommit commit = result.getSourceCommit(i); String sourcePath = result.getSourcePath(i); if (commit == null) { // Unregister the current revision if (previous != null) { previous.register(); previous = null; } continue; } BlameRevision revision = revisions.get(commit); if (revision == null) { revision = new ExtendedBlameRevision(); revision.setRepository(repository); revision.setCommit(commit); revision.setSourcePath(sourcePath); revisions.put(commit, revision); info.addRevision(revision); } revision.addSourceLine(i, result.getSourceLine(i)); if (previous != null) if (previous == revision) previous.addLine(); else { previous.register(); previous = revision.reset(i); } else previous = revision.reset(i); } if (previous != null) previous.register(); return info; }