use of org.eclipse.jgit.notes.Note in project gerrit by GerritCodeReview.
the class ExternalIdReader method all.
/** Reads and returns all external IDs. */
private Set<ExternalId> all(Repository repo, ObjectId rev) throws IOException {
if (rev.equals(ObjectId.zeroId())) {
return ImmutableSet.of();
}
try (Timer0.Context ctx = readAllLatency.start();
RevWalk rw = new RevWalk(repo)) {
NoteMap noteMap = readNoteMap(rw, rev);
Set<ExternalId> extIds = new HashSet<>();
for (Note note : noteMap) {
byte[] raw = rw.getObjectReader().open(note.getData(), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ);
try {
extIds.add(ExternalId.parse(note.getName(), raw));
} catch (Exception e) {
log.error(String.format("Ignoring invalid external ID note %s", note.getName()), e);
}
}
return extIds;
}
}
use of org.eclipse.jgit.notes.Note in project gerrit by GerritCodeReview.
the class ReviewNoteMerger method merge.
@Override
public Note merge(Note base, Note ours, Note theirs, ObjectReader reader, ObjectInserter inserter) throws IOException {
if (ours == null) {
return theirs;
}
if (theirs == null) {
return ours;
}
if (ours.getData().equals(theirs.getData())) {
return ours;
}
ObjectLoader lo = reader.open(ours.getData());
byte[] sep = new byte[] { '\n' };
ObjectLoader lt = reader.open(theirs.getData());
try (ObjectStream os = lo.openStream();
ByteArrayInputStream b = new ByteArrayInputStream(sep);
ObjectStream ts = lt.openStream();
UnionInputStream union = new UnionInputStream(os, b, ts)) {
ObjectId noteData = inserter.insert(Constants.OBJ_BLOB, lo.getSize() + sep.length + lt.getSize(), union);
return new Note(ours, noteData);
}
}
use of org.eclipse.jgit.notes.Note in project gerrit by GerritCodeReview.
the class NotesBranchUtil method commitNewNotes.
/**
* Create a new commit in the {@code notesBranch} by creating not yet existing notes from the
* {@code notes} map. The notes from the {@code notes} map which already exist in the note-tree of
* the tip of the {@code notesBranch} will not be updated.
*
* @param notes map of notes
* @param notesBranch notes branch to update
* @param commitAuthor author of the commit in the notes branch
* @param commitMessage for the commit in the notes branch
* @return map with those notes from the {@code notes} that were newly created
* @throws IOException
* @throws ConcurrentRefUpdateException
*/
public final NoteMap commitNewNotes(NoteMap notes, String notesBranch, PersonIdent commitAuthor, String commitMessage) throws IOException, ConcurrentRefUpdateException {
this.overwrite = false;
commitNotes(notes, notesBranch, commitAuthor, commitMessage);
NoteMap newlyCreated = NoteMap.newEmptyMap();
for (Note n : notes) {
if (base == null || !base.contains(n)) {
newlyCreated.set(n, n.getData());
}
}
return newlyCreated;
}
use of org.eclipse.jgit.notes.Note in project gerrit by GerritCodeReview.
the class RevisionNoteMap method parse.
static RevisionNoteMap<ChangeRevisionNote> parse(ChangeNoteUtil noteUtil, Change.Id changeId, ObjectReader reader, NoteMap noteMap, PatchLineComment.Status status) throws ConfigInvalidException, IOException {
Map<RevId, ChangeRevisionNote> result = new HashMap<>();
for (Note note : noteMap) {
ChangeRevisionNote rn = new ChangeRevisionNote(noteUtil, changeId, reader, note.getData(), status);
rn.parse();
result.put(new RevId(note.name()), rn);
}
return new RevisionNoteMap<>(noteMap, ImmutableMap.copyOf(result));
}
use of org.eclipse.jgit.notes.Note in project gerrit by GerritCodeReview.
the class RevisionNoteMap method parseRobotComments.
static RevisionNoteMap<RobotCommentsRevisionNote> parseRobotComments(ChangeNoteUtil noteUtil, ObjectReader reader, NoteMap noteMap) throws ConfigInvalidException, IOException {
Map<RevId, RobotCommentsRevisionNote> result = new HashMap<>();
for (Note note : noteMap) {
RobotCommentsRevisionNote rn = new RobotCommentsRevisionNote(noteUtil, reader, note.getData());
rn.parse();
result.put(new RevId(note.name()), rn);
}
return new RevisionNoteMap<>(noteMap, ImmutableMap.copyOf(result));
}
Aggregations