AbstractChangeNotes: Don't extend VersionedMetaData

Similar to ChangeUpdate in Ib163d209, most of the VersionedMetaData
methods weren't actually being used, and using them accidentally would
lead to unexpected results.

Copy the few methods we do need into AbstractChangeNotes. This is not
a complete rethinking of the AbstractChangeNotes API, just a minimal
code change. But it does open up that possibility later if we want it.

Change-Id: I1e56a80cc8daa90fa7ac0dc985d31f22123c0a55
This commit is contained in:
Dave Borowitz
2016-03-23 09:53:31 -04:00
parent f536ee0d73
commit 976c714dd8
3 changed files with 38 additions and 35 deletions

View File

@@ -30,8 +30,8 @@ import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.notes.NoteMap;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
@@ -112,33 +112,26 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
}
@Override
protected void onLoad() throws IOException, ConfigInvalidException {
protected void onLoad(RevWalk walk)
throws IOException, ConfigInvalidException {
ObjectId rev = getRevision();
if (rev == null) {
loadDefaults();
return;
}
try (RevWalk walk = new RevWalk(reader)) {
RevCommit tipCommit = walk.parseCommit(rev);
revisionNoteMap = RevisionNoteMap.parse(
noteUtil, getChangeId(), reader, NoteMap.read(reader, tipCommit),
true);
Multimap<RevId, PatchLineComment> cs = ArrayListMultimap.create();
for (RevisionNote rn : revisionNoteMap.revisionNotes.values()) {
for (PatchLineComment c : rn.comments) {
cs.put(c.getRevId(), c);
}
RevCommit tipCommit = walk.parseCommit(rev);
ObjectReader reader = walk.getObjectReader();
revisionNoteMap = RevisionNoteMap.parse(
noteUtil, getChangeId(), reader, NoteMap.read(reader, tipCommit),
true);
Multimap<RevId, PatchLineComment> cs = ArrayListMultimap.create();
for (RevisionNote rn : revisionNoteMap.revisionNotes.values()) {
for (PatchLineComment c : rn.comments) {
cs.put(c.getRevId(), c);
}
comments = ImmutableListMultimap.copyOf(cs);
}
}
@Override
protected boolean onSave(CommitBuilder commit) throws IOException,
ConfigInvalidException {
throw new UnsupportedOperationException(
getClass().getSimpleName() + " is read-only");
comments = ImmutableListMultimap.copyOf(cs);
}
@Override