| | |
| | | import org.eclipse.jgit.diff.DiffFormatter;
|
| | | import org.eclipse.jgit.diff.RawText;
|
| | | import org.eclipse.jgit.diff.RawTextComparator;
|
| | | import org.eclipse.jgit.lib.Constants;
|
| | | import org.eclipse.jgit.lib.ObjectId;
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | | import org.eclipse.jgit.revwalk.RevCommit;
|
| | | import org.eclipse.jgit.revwalk.RevTree;
|
| | |
| | | RevTree commitTree = commit.getTree();
|
| | | RevTree baseTree;
|
| | | if (baseCommit == null) {
|
| | | final RevWalk rw = new RevWalk(repository);
|
| | | RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
|
| | | rw.dispose();
|
| | | baseTree = parent.getTree();
|
| | | if (commit.getParentCount() > 0) {
|
| | | final RevWalk rw = new RevWalk(repository);
|
| | | RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
|
| | | rw.dispose();
|
| | | baseTree = parent.getTree();
|
| | | } else {
|
| | | // FIXME initial commit. no parent?!
|
| | | baseTree = commitTree;
|
| | | }
|
| | | } else {
|
| | | baseTree = baseCommit.getTree();
|
| | | }
|
| | |
| | | RevTree commitTree = commit.getTree();
|
| | | RevTree baseTree;
|
| | | if (baseCommit == null) {
|
| | | final RevWalk rw = new RevWalk(repository);
|
| | | RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
|
| | | baseTree = parent.getTree();
|
| | | if (commit.getParentCount() > 0) {
|
| | | final RevWalk rw = new RevWalk(repository);
|
| | | RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
|
| | | baseTree = parent.getTree();
|
| | | } else {
|
| | | // FIXME initial commit. no parent?!
|
| | | baseTree = commitTree;
|
| | | }
|
| | | } else {
|
| | | baseTree = baseCommit.getTree();
|
| | | }
|
| | |
| | | public static List<AnnotatedLine> blame(Repository repository, String blobPath, String objectId) {
|
| | | List<AnnotatedLine> lines = new ArrayList<AnnotatedLine>();
|
| | | try {
|
| | | ObjectId object;
|
| | | if (StringUtils.isEmpty(objectId)) {
|
| | | objectId = Constants.HEAD;
|
| | | object = JGitUtils.getDefaultBranch(repository);
|
| | | } else {
|
| | | object = repository.resolve(objectId);
|
| | | }
|
| | | BlameCommand blameCommand = new BlameCommand(repository);
|
| | | blameCommand.setFilePath(blobPath);
|
| | | blameCommand.setStartCommit(repository.resolve(objectId));
|
| | | blameCommand.setStartCommit(object);
|
| | | BlameResult blameResult = blameCommand.call();
|
| | | RawText rawText = blameResult.getResultContents();
|
| | | int length = rawText.size();
|