Search in sources :

Example 26 with NoteMap

use of org.eclipse.jgit.notes.NoteMap in project gerrit by GerritCodeReview.

the class GroupsNoteDbConsistencyChecker method readGroupNames.

private void readGroupNames(Repository repo, List<Ref> refs, Result result, BiMap<AccountGroup.UUID, String> uuidNameBiMap) throws IOException {
    Optional<Ref> maybeRef = refs.stream().filter(r -> r.getName().equals(RefNames.REFS_GROUPNAMES)).findFirst();
    if (!maybeRef.isPresent()) {
        result.problems.add(error("ref %s does not exist", RefNames.REFS_GROUPNAMES));
        return;
    }
    Ref ref = maybeRef.get();
    try (RevWalk rw = new RevWalk(repo)) {
        RevCommit c = rw.parseCommit(ref.getObjectId());
        NoteMap nm = NoteMap.read(rw.getObjectReader(), c);
        for (Note note : nm) {
            ObjectLoader ld = rw.getObjectReader().open(note.getData());
            byte[] data = ld.getCachedBytes();
            GroupReference gRef;
            try {
                gRef = GroupNameNotes.getFromNoteData(data);
            } catch (ConfigInvalidException e) {
                result.problems.add(error("notename entry %s: %s does not parse: %s", note, new String(data, StandardCharsets.UTF_8), e.getMessage()));
                continue;
            }
            ObjectId nameKey = GroupNameNotes.getNoteKey(AccountGroup.nameKey(gRef.getName()));
            if (!Objects.equals(nameKey, note)) {
                result.problems.add(error("notename entry %s does not match name %s", note, gRef.getName()));
            }
            // We trust SHA1 to have no collisions, so no need to check uniqueness of name.
            uuidNameBiMap.put(gRef.getUUID(), gRef.getName());
        }
    }
}
Also used : AllUsersName(com.google.gerrit.server.config.AllUsersName) InternalGroup(com.google.gerrit.entities.InternalGroup) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RevWalk(org.eclipse.jgit.revwalk.RevWalk) ImmutableList(com.google.common.collect.ImmutableList) ConsistencyProblemInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo) Map(java.util.Map) FormatMethod(com.google.errorprone.annotations.FormatMethod) RefNames(com.google.gerrit.entities.RefNames) ConsistencyProblemInfo.error(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo.error) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) NoteMap(org.eclipse.jgit.notes.NoteMap) AccountGroup(com.google.gerrit.entities.AccountGroup) BiMap(com.google.common.collect.BiMap) Note(org.eclipse.jgit.notes.Note) ConsistencyCheckInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) ObjectId(org.eclipse.jgit.lib.ObjectId) GroupReference(com.google.gerrit.entities.GroupReference) Objects(java.util.Objects) HashBiMap(com.google.common.collect.HashBiMap) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) Ref(org.eclipse.jgit.lib.Ref) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ConsistencyProblemInfo.warning(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo.warning) FluentLogger(com.google.common.flogger.FluentLogger) Repository(org.eclipse.jgit.lib.Repository) Singleton(com.google.inject.Singleton) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ObjectId(org.eclipse.jgit.lib.ObjectId) NoteMap(org.eclipse.jgit.notes.NoteMap) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Ref(org.eclipse.jgit.lib.Ref) Note(org.eclipse.jgit.notes.Note) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) GroupReference(com.google.gerrit.entities.GroupReference) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 27 with NoteMap

use of org.eclipse.jgit.notes.NoteMap in project gerrit by GerritCodeReview.

the class ChangeUpdate method getRevisionNoteMap.

private RevisionNoteMap<ChangeRevisionNote> getRevisionNoteMap(RevWalk rw, ObjectId curr) throws ConfigInvalidException, IOException {
    if (curr.equals(ObjectId.zeroId())) {
        return RevisionNoteMap.emptyMap();
    }
    // The old ChangeNotes may have already parsed the revision notes. We can reuse them as long as
    // the ref hasn't advanced.
    ChangeNotes notes = getNotes();
    if (notes != null && notes.revisionNoteMap != null) {
        ObjectId idFromNotes = firstNonNull(notes.load().getRevision(), ObjectId.zeroId());
        if (idFromNotes.equals(curr)) {
            return notes.revisionNoteMap;
        }
    }
    NoteMap noteMap = NoteMap.read(rw.getObjectReader(), rw.parseCommit(curr));
    // parse any existing revision notes so we can merge them.
    return RevisionNoteMap.parse(noteUtil.getChangeNoteJson(), rw.getObjectReader(), noteMap, HumanComment.Status.PUBLISHED);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) NoteMap(org.eclipse.jgit.notes.NoteMap)

Example 28 with NoteMap

use of org.eclipse.jgit.notes.NoteMap in project gerrit by GerritCodeReview.

the class ChangeDraftUpdate method getRevisionNoteMap.

private RevisionNoteMap<ChangeRevisionNote> getRevisionNoteMap(RevWalk rw, ObjectId curr) throws ConfigInvalidException, IOException {
    // The old DraftCommentNotes already parsed the revision notes. We can reuse them as long as
    // the ref hasn't advanced.
    ChangeNotes changeNotes = getNotes();
    if (changeNotes != null) {
        DraftCommentNotes draftNotes = changeNotes.load().getDraftCommentNotes();
        if (draftNotes != null) {
            ObjectId idFromNotes = firstNonNull(draftNotes.getRevision(), ObjectId.zeroId());
            RevisionNoteMap<ChangeRevisionNote> rnm = draftNotes.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();
    }
    // parse any existing revision notes so we can merge them.
    return RevisionNoteMap.parse(noteUtil.getChangeNoteJson(), rw.getObjectReader(), noteMap, HumanComment.Status.DRAFT);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) NoteMap(org.eclipse.jgit.notes.NoteMap)

Example 29 with NoteMap

use of org.eclipse.jgit.notes.NoteMap in project gerrit by GerritCodeReview.

the class RobotCommentUpdate method getRevisionNoteMap.

private RevisionNoteMap<RobotCommentsRevisionNote> getRevisionNoteMap(RevWalk rw, ObjectId curr) throws ConfigInvalidException, IOException {
    if (curr.equals(ObjectId.zeroId())) {
        return RevisionNoteMap.emptyMap();
    }
    // 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();
    }
    // parse any existing revision notes so we can merge them.
    return RevisionNoteMap.parseRobotComments(noteUtil.getChangeNoteJson(), rw.getObjectReader(), noteMap);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) NoteMap(org.eclipse.jgit.notes.NoteMap)

Aggregations

NoteMap (org.eclipse.jgit.notes.NoteMap)29 ObjectId (org.eclipse.jgit.lib.ObjectId)23 RevWalk (org.eclipse.jgit.revwalk.RevWalk)15 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)11 Repository (org.eclipse.jgit.lib.Repository)9 Note (org.eclipse.jgit.notes.Note)9 IOException (java.io.IOException)8 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)7 ObjectReader (org.eclipse.jgit.lib.ObjectReader)6 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 Ref (org.eclipse.jgit.lib.Ref)5 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)4 ConsistencyProblemInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo)3 AllUsersName (com.google.gerrit.server.config.AllUsersName)3 Inject (com.google.inject.Inject)3 Singleton (com.google.inject.Singleton)3 ListMultimap (com.google.common.collect.ListMultimap)2 MultimapBuilder (com.google.common.collect.MultimapBuilder)2 AccountGroup (com.google.gerrit.entities.AccountGroup)2 GroupReference (com.google.gerrit.entities.GroupReference)2