Package org.eclipse.jgit.notes
Class NoteMap
java.lang.Object
org.eclipse.jgit.notes.NoteMap
Index of notes from a note branch.
This class is not thread-safe, and relies on an
ObjectReader that it borrows/shares with the
caller. The reader can be used during any call, and is not released by this
class. The caller should arrange for releasing the shared
ObjectReader at the proper times.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ObjectReaderBorrowed reader to access the repository.private InMemoryNoteBucketAll of the notes that have been loaded. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(AnyObjectId id) Determine if a note exists for the specified ObjectId.get(AnyObjectId id) Lookup a note for a specific ObjectId.byte[]getCachedBytes(AnyObjectId id, int sizeLimit) Open and return the content of an object's note.getNote(AnyObjectId id) Lookup a note for a specific ObjectId.(package private) InMemoryNoteBucketgetRoot()iterator()private voidstatic NoteMapConstruct a new empty note map.(package private) static NoteMapnewMap(InMemoryNoteBucket root, ObjectReader reader) Construct a new note map from an existing note bucket.static NoteMapread(ObjectReader reader, RevCommit commit) Load a collection of notes from a branch.static NoteMapread(ObjectReader reader, RevTree tree) Load a collection of notes from a tree.static NoteMapreadTree(ObjectReader reader, ObjectId treeId) Load a collection of notes from a tree.voidremove(AnyObjectId noteOn) Remove a note from an object.voidset(AnyObjectId noteOn, String noteData, ObjectInserter ins) Attach a note to an object.voidset(AnyObjectId noteOn, ObjectId noteData) Attach (or remove) a note on an object.static StringshortenRefName(String noteRefName) Shorten the note ref name by trimming off theConstants.R_NOTESprefix if it exists.writeTree(ObjectInserter inserter) Write this note map as a tree.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
reader
Borrowed reader to access the repository. -
root
All of the notes that have been loaded.
-
-
Constructor Details
-
NoteMap
-
-
Method Details
-
newEmptyMap
Construct a new empty note map.- Returns:
- an empty note map.
-
shortenRefName
Shorten the note ref name by trimming off theConstants.R_NOTESprefix if it exists.- Parameters:
noteRefName- aStringobject.- Returns:
- a more user friendly note name
-
read
public static NoteMap read(ObjectReader reader, RevCommit commit) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException Load a collection of notes from a branch.- Parameters:
reader- reader to scan the note branch with. This reader may be retained by the NoteMap for the life of the map in order to support lazy loading of entries.commit- the revision of the note branch to read.- Returns:
- the note map read from the commit.
- Throws:
IOException- the repository cannot be accessed through the reader.CorruptObjectException- a tree object is corrupt and cannot be read.IncorrectObjectTypeException- a tree object wasn't actually a tree.MissingObjectException- a reference tree object doesn't exist.
-
read
public static NoteMap read(ObjectReader reader, RevTree tree) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException Load a collection of notes from a tree.- Parameters:
reader- reader to scan the note branch with. This reader may be retained by the NoteMap for the life of the map in order to support lazy loading of entries.tree- the note tree to read.- Returns:
- the note map read from the tree.
- Throws:
IOException- the repository cannot be accessed through the reader.CorruptObjectException- a tree object is corrupt and cannot be read.IncorrectObjectTypeException- a tree object wasn't actually a tree.MissingObjectException- a reference tree object doesn't exist.
-
readTree
public static NoteMap readTree(ObjectReader reader, ObjectId treeId) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException Load a collection of notes from a tree.- Parameters:
reader- reader to scan the note branch with. This reader may be retained by the NoteMap for the life of the map in order to support lazy loading of entries.treeId- the note tree to read.- Returns:
- the note map read from the tree.
- Throws:
IOException- the repository cannot be accessed through the reader.CorruptObjectException- a tree object is corrupt and cannot be read.IncorrectObjectTypeException- a tree object wasn't actually a tree.MissingObjectException- a reference tree object doesn't exist.
-
newMap
Construct a new note map from an existing note bucket.- Parameters:
root- the root bucket of this note mapreader- reader to scan the note branch with. This reader may be retained by the NoteMap for the life of the map in order to support lazy loading of entries.- Returns:
- the note map built from the note bucket
-
iterator
-
get
Lookup a note for a specific ObjectId.- Parameters:
id- the object to look for.- Returns:
- the note's blob ObjectId, or null if no note exists.
- Throws:
IOException- a portion of the note space is not accessible.
-
getNote
Lookup a note for a specific ObjectId.- Parameters:
id- the object to look for.- Returns:
- the note for the given object id, or null if no note exists.
- Throws:
IOException- a portion of the note space is not accessible.
-
contains
Determine if a note exists for the specified ObjectId.- Parameters:
id- the object to look for.- Returns:
- true if a note exists; false if there is no note.
- Throws:
IOException- a portion of the note space is not accessible.
-
getCachedBytes
public byte[] getCachedBytes(AnyObjectId id, int sizeLimit) throws LargeObjectException, MissingObjectException, IOException Open and return the content of an object's note. This method assumes the note is fairly small and can be accessed efficiently. Larger notes should be accessed by streaming:ObjectId dataId = thisMap.get(id); if (dataId != null) reader.open(dataId).openStream();- Parameters:
id- object to lookup the note of.sizeLimit- maximum number of bytes to return. If the note data size is larger than this limit, LargeObjectException will be thrown.- Returns:
- if a note is defined for
id, the note content. If no note is defined, null. - Throws:
LargeObjectException- the note data is larger thansizeLimit.MissingObjectException- the note's blob does not exist in the repository.IOException- the note's blob cannot be read from the repository
-
set
Attach (or remove) a note on an object. If no note exists, a new note is stored. If a note already exists for the given object, it is replaced (or removed). This method only updates the map in memory. If the caller wants to attach a UTF-8 encoded string message to an object,set(AnyObjectId, String, ObjectInserter)is a convenient way to encode and update a note in one step.- Parameters:
noteOn- the object to attach the note to. This same ObjectId can later be used as an argument toget(AnyObjectId)orgetCachedBytes(AnyObjectId, int)to read back thenoteData.noteData- data to associate with the note. This must be the ObjectId of a blob that already exists in the repository. If null the note will be deleted, if present.- Throws:
IOException- a portion of the note space is not accessible.
-
set
Attach a note to an object. If no note exists, a new note is stored. If a note already exists for the given object, it is replaced (or removed).- Parameters:
noteOn- the object to attach the note to. This same ObjectId can later be used as an argument toget(AnyObjectId)orgetCachedBytes(AnyObjectId, int)to read back thenoteData.noteData- text to store in the note. The text will be UTF-8 encoded when stored in the repository. If null the note will be deleted, if the empty string a note with the empty string will be stored.ins- inserter to write the encodednoteDataout as a blob. The caller must ensure the inserter is flushed before the updated note map is made available for reading.- Throws:
IOException- the note data could not be stored in the repository.
-
remove
Remove a note from an object. If no note exists, no action is performed. This method only updates the map in memory.- Parameters:
noteOn- the object to remove the note from.- Throws:
IOException- a portion of the note space is not accessible.
-
writeTree
Write this note map as a tree.- Parameters:
inserter- inserter to use when writing trees to the object database. Caller is responsible for flushing the inserter before trying to read the objects, or exposing them through a reference.- Returns:
- the top level tree.
- Throws:
IOException- a tree could not be written.
-
getRoot
InMemoryNoteBucket getRoot()- Returns:
- the root note bucket
-
load
private void load(ObjectId rootTree) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException
-