Search in sources :

Example 1 with GitNote

use of com.gitblit.models.GitNote in project gitblit by gitblit.

the class JGitUtilsTest method testCommitNotes.

@Test
public void testCommitNotes() throws Exception {
    Repository repository = GitBlitSuite.getJGitRepository();
    RevCommit commit = JGitUtils.getCommit(repository, "690c268c793bfc218982130fbfc25870f292295e");
    List<GitNote> list = JGitUtils.getNotesOnCommit(repository, commit);
    repository.close();
    assertTrue(list.size() > 0);
    assertEquals("183474d554e6f68478a02d9d7888b67a9338cdff", list.get(0).notesRef.getReferencedObjectId().getName());
}
Also used : Repository(org.eclipse.jgit.lib.Repository) GitNote(com.gitblit.models.GitNote) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 2 with GitNote

use of com.gitblit.models.GitNote in project gitblit by gitblit.

the class JGitUtils method getNotesOnCommit.

/**
 * Returns the list of notes entered about the commit from the refs/notes
 * namespace. If the repository does not exist or is empty, an empty list is
 * returned.
 *
 * @param repository
 * @param commit
 * @return list of notes
 */
public static List<GitNote> getNotesOnCommit(Repository repository, RevCommit commit) {
    List<GitNote> list = new ArrayList<GitNote>();
    if (!hasCommits(repository)) {
        return list;
    }
    List<RefModel> noteBranches = getNoteBranches(repository, true, -1);
    for (RefModel notesRef : noteBranches) {
        RevTree notesTree = JGitUtils.getCommit(repository, notesRef.getName()).getTree();
        // flat notes list
        String notePath = commit.getName();
        String text = getStringContent(repository, notesTree, notePath);
        if (!StringUtils.isEmpty(text)) {
            List<RevCommit> history = getRevLog(repository, notesRef.getName(), notePath, 0, -1);
            RefModel noteRef = new RefModel(notesRef.displayName, null, history.get(history.size() - 1));
            GitNote gitNote = new GitNote(noteRef, text);
            list.add(gitNote);
            continue;
        }
        // folder structure
        StringBuilder sb = new StringBuilder(commit.getName());
        sb.insert(2, '/');
        notePath = sb.toString();
        text = getStringContent(repository, notesTree, notePath);
        if (!StringUtils.isEmpty(text)) {
            List<RevCommit> history = getRevLog(repository, notesRef.getName(), notePath, 0, -1);
            RefModel noteRef = new RefModel(notesRef.displayName, null, history.get(history.size() - 1));
            GitNote gitNote = new GitNote(noteRef, text);
            list.add(gitNote);
        }
    }
    return list;
}
Also used : RefModel(com.gitblit.models.RefModel) ArrayList(java.util.ArrayList) GitNote(com.gitblit.models.GitNote) RevTree(org.eclipse.jgit.revwalk.RevTree) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

GitNote (com.gitblit.models.GitNote)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 RefModel (com.gitblit.models.RefModel)1 ArrayList (java.util.ArrayList)1 Repository (org.eclipse.jgit.lib.Repository)1 RevTree (org.eclipse.jgit.revwalk.RevTree)1 Test (org.junit.Test)1