repoManager.openRepository(projectControl.getProject().getNameKey());
try {
final RevWalk revWalk = new RevWalk(repo);
final ObjectInserter inserter = repo.newObjectInserter();
try {
NoteMap baseNoteMap = null;
RevCommit baseCommit = null;
final Ref notesBranch = repo.getRef(REF_REJECT_COMMITS);
if (notesBranch != null) {
baseCommit = revWalk.parseCommit(notesBranch.getObjectId());
baseNoteMap = NoteMap.read(revWalk.getObjectReader(), baseCommit);
}
final NoteMap ourNoteMap;
if (baseCommit != null) {
ourNoteMap = NoteMap.read(repo.newObjectReader(), baseCommit);
} else {
ourNoteMap = NoteMap.newEmptyMap();
}
for (final ObjectId commitToBan : commitsToBan) {
try {
revWalk.parseCommit(commitToBan);
} catch (MissingObjectException e) {
// ignore exception, also not existing commits can be banned
} catch (IncorrectObjectTypeException e) {
result.notACommit(commitToBan, e.getMessage());
continue;
}
final Note note = ourNoteMap.getNote(commitToBan);
if (note != null) {
result.commitAlreadyBanned(commitToBan);
continue;
}
final String noteContent = reason != null ? reason : "";
final ObjectId noteContentId =
inserter
.insert(Constants.OBJ_BLOB, noteContent.getBytes("UTF-8"));
ourNoteMap.set(commitToBan, noteContentId);
result.commitBanned(commitToBan);
}
if (result.getNewlyBannedCommits().isEmpty()) {
return result;