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());
}
}
}
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);
}
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);
}
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);
}
Aggregations