Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit » [jgit] Find Commits for Notes([jgit] Find Commits for Notes)
[jgit] Find Commits for Notes [message #759323] Mon, 28 November 2011 11:35 Go to next message
Lars Ohlen is currently offline Lars Ohlen
Messages: 3
Registered: October 2011
Location: Sweden
Junior Member

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 14:06 Go to previous message
Christian Halstrick is currently offline Christian Halstrick
Messages: 18
Registered: July 2009
Junior Member
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: Thu Oct 23 16:37:33 GMT 2014

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

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