Search in sources :

Example 1 with Note

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;
    }
}
Also used : Note(org.eclipse.jgit.notes.Note) Timer0(com.google.gerrit.metrics.Timer0) NoteMap(org.eclipse.jgit.notes.NoteMap) RevWalk(org.eclipse.jgit.revwalk.RevWalk) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 2 with Note

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);
    }
}
Also used : UnionInputStream(org.eclipse.jgit.util.io.UnionInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectId(org.eclipse.jgit.lib.ObjectId) ObjectStream(org.eclipse.jgit.lib.ObjectStream) Note(org.eclipse.jgit.notes.Note) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader)

Example 3 with Note

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;
}
Also used : Note(org.eclipse.jgit.notes.Note) NoteMap(org.eclipse.jgit.notes.NoteMap)

Example 4 with Note

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));
}
Also used : HashMap(java.util.HashMap) Note(org.eclipse.jgit.notes.Note) RevId(com.google.gerrit.reviewdb.client.RevId)

Example 5 with Note

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));
}
Also used : HashMap(java.util.HashMap) Note(org.eclipse.jgit.notes.Note) RevId(com.google.gerrit.reviewdb.client.RevId)

Aggregations

Note (org.eclipse.jgit.notes.Note)16 RevWalk (org.eclipse.jgit.revwalk.RevWalk)10 Change (com.google.gerrit.reviewdb.client.Change)6 Comment (com.google.gerrit.reviewdb.client.Comment)6 CommentRange (com.google.gerrit.reviewdb.client.CommentRange)6 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)6 ChangeNotesRevWalk (com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk)6 Timestamp (java.sql.Timestamp)6 Test (org.junit.Test)6 RevId (com.google.gerrit.reviewdb.client.RevId)5 ObjectId (org.eclipse.jgit.lib.ObjectId)5 NoteMap (org.eclipse.jgit.notes.NoteMap)5 IOException (java.io.IOException)3 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)3 Repository (org.eclipse.jgit.lib.Repository)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)2 ListMultimap (com.google.common.collect.ListMultimap)1 MultimapBuilder (com.google.common.collect.MultimapBuilder)1