Example usage for org.eclipse.jgit.notes NoteMap read

List of usage examples for org.eclipse.jgit.notes NoteMap read

Introduction

In this page you can find the example usage for org.eclipse.jgit.notes NoteMap read.

Prototype

public static NoteMap read(ObjectReader reader, RevTree tree)
        throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException 

Source Link

Document

Load a collection of notes from a tree.

Usage

From source file:com.google.gerrit.server.git.NotesBranchUtil.java

License:Apache License

private void loadBase(String notesBranch) throws IOException {
    Ref branch = db.getRefDatabase().exactRef(notesBranch);
    if (branch != null) {
        baseCommit = revWalk.parseCommit(branch.getObjectId());
        base = NoteMap.read(revWalk.getObjectReader(), baseCommit);
    }// w w  w.jav a  2s  .c  om
    if (baseCommit != null) {
        ours = NoteMap.read(revWalk.getObjectReader(), baseCommit);
    } else {
        ours = NoteMap.newEmptyMap();
    }
}

From source file:com.google.gerrit.server.git.NotesBranchUtil.java

License:Apache License

private void updateRef(String notesBranch) throws IOException, MissingObjectException,
        IncorrectObjectTypeException, CorruptObjectException, ConcurrentRefUpdateException {
    if (baseCommit != null && oursCommit.getTree().equals(baseCommit.getTree())) {
        // If the trees are identical, there is no change in the notes.
        // Avoid saving this commit as it has no new information.
        return;/*w  w w . j  a v  a2  s. c  om*/
    }

    int remainingLockFailureCalls = MAX_LOCK_FAILURE_CALLS;
    RefUpdate refUpdate = createRefUpdate(notesBranch, oursCommit, baseCommit);

    for (;;) {
        Result result = refUpdate.update();

        if (result == Result.LOCK_FAILURE) {
            if (--remainingLockFailureCalls > 0) {
                try {
                    Thread.sleep(SLEEP_ON_LOCK_FAILURE_MS);
                } catch (InterruptedException e) {
                    // ignore
                }
            } else {
                throw new ConcurrentRefUpdateException("Failed to lock the ref: " + notesBranch,
                        refUpdate.getRef(), result);
            }

        } else if (result == Result.REJECTED) {
            RevCommit theirsCommit = revWalk.parseCommit(refUpdate.getOldObjectId());
            NoteMap theirs = NoteMap.read(revWalk.getObjectReader(), theirsCommit);
            NoteMapMerger merger = new NoteMapMerger(db, getNoteMerger(), MergeStrategy.RESOLVE);
            NoteMap merged = merger.merge(base, ours, theirs);
            RevCommit mergeCommit = createCommit(merged, gerritIdent, "Merged note commits\n", theirsCommit,
                    oursCommit);
            refUpdate = createRefUpdate(notesBranch, mergeCommit, theirsCommit);
            remainingLockFailureCalls = MAX_LOCK_FAILURE_CALLS;

        } else if (result == Result.IO_FAILURE) {
            throw new IOException("Couldn't update " + notesBranch + ". " + result.name());
        } else {
            gitRefUpdated.fire(project, refUpdate);
            break;
        }
    }
}

From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java

License:Apache License

public static NoteMap parseCommentsFromNotes(Repository repo, String refName, RevWalk walk, Change.Id changeId,
        Multimap<RevId, PatchLineComment> comments, Status status) throws IOException, ConfigInvalidException {
    Ref ref = repo.getRefDatabase().exactRef(refName);
    if (ref == null) {
        return null;
    }/*from  www.j  av a  2s  .  co  m*/

    ObjectReader reader = walk.getObjectReader();
    RevCommit commit = walk.parseCommit(ref.getObjectId());
    NoteMap noteMap = NoteMap.read(reader, commit);

    for (Note note : noteMap) {
        byte[] bytes = reader.open(note.getData(), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ);
        List<PatchLineComment> result = parseNote(bytes, changeId, status);
        if (result == null || result.isEmpty()) {
            continue;
        }
        comments.putAll(new RevId(note.name()), result);
    }
    return noteMap;
}

From source file:com.google.gerrit.server.notedb.RobotCommentNotes.java

License:Apache License

@Override
protected void onLoad(LoadHandle handle) throws IOException, ConfigInvalidException {
    metaId = handle.id();//  ww w.ja va2 s .  c o  m
    if (metaId == null) {
        loadDefaults();
        return;
    }
    metaId = metaId.copy();

    RevCommit tipCommit = handle.walk().parseCommit(metaId);
    ObjectReader reader = handle.walk().getObjectReader();
    revisionNoteMap = RevisionNoteMap.parseRobotComments(args.noteUtil, reader,
            NoteMap.read(reader, tipCommit));
    ListMultimap<RevId, RobotComment> cs = MultimapBuilder.hashKeys().arrayListValues().build();
    for (RobotCommentsRevisionNote rn : revisionNoteMap.revisionNotes.values()) {
        for (RobotComment c : rn.getComments()) {
            cs.put(new RevId(c.revId), c);
        }
    }
    comments = ImmutableListMultimap.copyOf(cs);
}

From source file:com.google.gerrit.server.notedb.RobotCommentUpdate.java

License:Apache License

private RevisionNoteMap<RobotCommentsRevisionNote> getRevisionNoteMap(RevWalk rw, ObjectId curr)
        throws ConfigInvalidException, OrmException, IOException {
    if (curr.equals(ObjectId.zeroId())) {
        return RevisionNoteMap.emptyMap();
    }/*from  w  w w.j ava2  s .  c om*/
    if (migration.readChanges()) {
        // If reading from changes is enabled, then the old RobotCommentNotes
        // already parsed the revision notes. We can reuse them as long as the ref
        // hasn't advanced.
        ChangeNotes changeNotes = getNotes();
        if (changeNotes != null) {
            RobotCommentNotes robotCommentNotes = changeNotes.load().getRobotCommentNotes();
            if (robotCommentNotes != null) {
                ObjectId idFromNotes = firstNonNull(robotCommentNotes.getRevision(), ObjectId.zeroId());
                RevisionNoteMap<RobotCommentsRevisionNote> rnm = robotCommentNotes.getRevisionNoteMap();
                if (idFromNotes.equals(curr) && rnm != null) {
                    return rnm;
                }
            }
        }
    }
    NoteMap noteMap;
    if (!curr.equals(ObjectId.zeroId())) {
        noteMap = NoteMap.read(rw.getObjectReader(), rw.parseCommit(curr));
    } else {
        noteMap = NoteMap.newEmptyMap();
    }
    // Even though reading from changes might not be enabled, we need to
    // parse any existing revision notes so we can merge them.
    return RevisionNoteMap.parseRobotComments(noteUtil, rw.getObjectReader(), noteMap);
}