简体   繁体   中英

How to read Git notes using JGit given a commit-sha

I am trying to read Git Notes information from a custom ref refs/notes/abcd of a particular commit in a repository using JGit

Here is what I tried:

Repository repository = repositoryManager.openRepository(repoName);
Git git = new Git(repository);
ObjectId oid = repository.resolve("5740b142a7b5f66768a2d904b267dccaef1a095f");
Note note = git.notesShow().setNotesRef("refs/notes/abcd").setObjectId(oid).call();
ObjectLoader loader = repository.open(note.getData());
byte[] data = loader.getBytes();
System.out.println(new String(data, "utf-8"));

I get the following compilation error:

error: incompatible types: org.eclipse.jgit.lib.ObjectId cannot be converted to org.eclipse.jgit.revwalk.RevObject

How do I pass a RevObject variable to Git setObjectId() given a commit-sha string?

With a RevWalk , the object id can be parsed and the resulting RevCommit can be passed to the ShowNoteCommand .

For example:

RevCommit commit;
try( RevWalk revWalk = new RevWalk( repository ) ) {
  commit = revWalk.parseCommit( oid );
}

git.notesShow().setObjectId( commit )...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM