Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » [jgit] Find Commits for Notes([jgit] Find Commits for Notes)
[jgit] Find Commits for Notes [message #759323] Mon, 28 November 2011 06:35 Go to next message
Eclipse UserFriend

Hi,

I'm investigating on how to use the Notes feature in Git.
(e.g. having the ability to add meta data to a Commit without altering the revision tree)

JGit has some basic API support for Notes (add notes and list notes), but not no search API. I have the need to find the commit id for a specific Note entry!

I using some low-level JGit APIs find the object id for the Notes, but would like
to find to which Commit this Note object id belongs to.

Any ideas or hints appreciated.

BR

Lars












Re: [jgit] Find Commits for Notes [message #759902 is a reply to message #759323] Wed, 30 November 2011 09:06 Go to previous message
Eclipse UserFriend
The name of a Note is the id of the object the note was attached to. See this

Git repo = ...
new FileWriter(new File(repo.getRepository().getWorkTree(), "f.txt")).write("hello world");
repo.add().addFilepattern("f.txt").call();
RevCommit commit = repo.commit().setMessage("tests").call();
System.out.println("created commit with id: "+commit.getId());
repo.notesAdd().setObjectId(commit).setMessage("content of Note").call();
for (Note n : repo.notesList().call())
  System.out.println("Found note on object "+n.getName()+", data: "+n.getData());


You can also lookup the note for a specific commit by using the NoteMap class.

// better way to search for notes. Look up how to do it in ListNotesCommand.java
RevWalk walk = new RevWalk(repo);
NoteMap map = NoteMap.newEmptyMap();
Ref ref = repo.getRef("refs/notes/commits");
if (ref != null) {
  RevCommit notesCommit = walk.parseCommit(ref.getObjectId());
  map = NoteMap.read(walk.getObjectReader(), notesCommit);
  map.getNote(notesCommit.getId());

Previous Topic:question about ReceivePck
Next Topic:Git Plugin in RCP - Wizard Error
Goto Forum:
  


Current Time: Mon Jun 23 14:52:48 EDT 2025

Powered by FUDForum. Page generated in 0.07479 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top