Example usage for org.eclipse.jgit.api Git notesShow

List of usage examples for org.eclipse.jgit.api Git notesShow

Introduction

In this page you can find the example usage for org.eclipse.jgit.api Git notesShow.

Prototype

public ShowNoteCommand notesShow() 

Source Link

Document

Return a command to show notes on an object

Usage

From source file:com.google.appraise.eclipse.core.client.git.AppraiseGitReviewClient.java

License:Open Source License

/**
 * Reads a single note out as a string from the given commit hash.
 * Returns null if the note isn't found.
 *//*from w w w .  jav  a  2 s. co  m*/
private String readOneNote(Git git, String notesRef, String hash) throws GitClientException {
    try (RevWalk walker = new RevWalk(git.getRepository())) {
        ShowNoteCommand cmd = git.notesShow();
        cmd.setNotesRef(notesRef);
        ObjectId ref = git.getRepository().resolve(hash);
        RevCommit commit = walker.parseCommit(ref);
        cmd.setObjectId(commit);
        Note note = cmd.call();
        if (note == null) {
            return null;
        }
        return noteToString(repo, note);
    } catch (Exception e) {
        throw new GitClientException(e);
    }
}

From source file:org.eclipse.egit.ui.internal.commit.RepositoryCommit.java

License:Open Source License

/**
 * Get notes for this commit./*w w  w.j  a  v  a2 s. co  m*/
 *
 * @return non-null but possibly empty array of {@link RepositoryCommitNote}
 *         instances.
 */
public RepositoryCommitNote[] getNotes() {
    if (notes == null) {
        List<RepositoryCommitNote> noteList = new ArrayList<RepositoryCommitNote>();
        try {
            Repository repo = getRepository();
            Git git = Git.wrap(repo);
            RevCommit revCommit = getRevCommit();
            for (Ref ref : repo.getRefDatabase().getRefs(Constants.R_NOTES).values()) {
                Note note = git.notesShow().setNotesRef(ref.getName()).setObjectId(revCommit).call();
                if (note != null)
                    noteList.add(new RepositoryCommitNote(this, ref, note));
            }
            notes = noteList.toArray(new RepositoryCommitNote[noteList.size()]);
        } catch (Exception e) {
            Activator.logError("Error showing notes", e); //$NON-NLS-1$
            notes = new RepositoryCommitNote[0];
        }
    }
    return notes;
}