Move Change out of AbstractChangeNotes

In order to load all draft PatchLineComments for a given author, we
will need to be able to scan all the refs in their namespace of the
All-Users repository and load the drafts in without access to a Change
object (we will just have the ChangeId from the refname). Therefore, I
removed that field from AbstractChangeNotes and put the Change object
just in ChangeNotes because some callers of ChangeNotes need the
Change object. I put the ChangeId in the AbstractChangeNotes instead,
since both ChangeNotes and DraftCommentNotes need that.

Change-Id: Icd3b72b10dd39a205c3ec420b25a6740b9d376af
This commit is contained in:
Yacob Yonas
2014-07-18 14:55:33 -07:00
parent 1ef3b37c88
commit 1cae3dab65
4 changed files with 21 additions and 19 deletions

View File

@@ -29,19 +29,15 @@ import java.io.IOException;
public abstract class AbstractChangeNotes<T> extends VersionedMetaData {
private boolean loaded;
protected final GitRepositoryManager repoManager;
private final Change change;
private final Change.Id changeId;
AbstractChangeNotes(GitRepositoryManager repoManager, Change change) {
AbstractChangeNotes(GitRepositoryManager repoManager, Change.Id changeId) {
this.repoManager = repoManager;
this.change = new Change(change);
this.changeId = changeId;
}
public Change.Id getChangeId() {
return change.getId();
}
public Change getChange() {
return change;
return changeId;
}
public T load() throws OrmException {

View File

@@ -91,8 +91,8 @@ public class ChangeDraftUpdate extends AbstractChangeUpdate {
IdentifiedUser user = (IdentifiedUser) ctl.getCurrentUser();
this.accountId = user.getAccountId();
this.changeNotes = getChangeNotes().load();
this.draftNotes = draftNotesFactory.create(ctl.getChange(),
accountId).load();
this.draftNotes = draftNotesFactory.create(ctl.getChange().getId(),
user.getAccountId()).load();
this.upsertComments = Lists.newArrayList();
this.deleteComments = Lists.newArrayList();

View File

@@ -490,6 +490,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
}
}
private final Change change;
private ImmutableListMultimap<PatchSet.Id, PatchSetApproval> approvals;
private ImmutableSetMultimap<ReviewerState, Account.Id> reviewers;
private ImmutableList<SubmitRecord> submitRecords;
@@ -505,8 +506,13 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
@VisibleForTesting
public ChangeNotes(GitRepositoryManager repoManager,
AllUsersNameProvider allUsersProvider, Change change) {
super(repoManager, change);
super(repoManager, change.getId());
this.allUsers = allUsersProvider.get();
this.change = new Change(change);
}
public Change getChange() {
return change;
}
public ImmutableListMultimap<PatchSet.Id, PatchSetApproval> getApprovals() {
@@ -565,7 +571,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
if (draftCommentNotes == null ||
!author.equals(draftCommentNotes.getAuthor())) {
draftCommentNotes = new DraftCommentNotes(repoManager, allUsers,
getChange(), author);
getChangeId(), author);
draftCommentNotes.load();
}
}

View File

@@ -62,8 +62,8 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
this.draftsProject = allUsers.get();
}
public DraftCommentNotes create(Change change, Account.Id accountId) {
return new DraftCommentNotes(repoManager, draftsProject, change,
public DraftCommentNotes create(Change.Id changeId, Account.Id accountId) {
return new DraftCommentNotes(repoManager, draftsProject, changeId,
accountId);
}
}
@@ -79,10 +79,10 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
private final Multimap<PatchSet.Id, PatchLineComment> draftPsComments;
private NoteMap noteMap;
private Parser(Change change, RevWalk walk, ObjectId tip,
private Parser(Change.Id changeId, RevWalk walk, ObjectId tip,
GitRepositoryManager repoManager, AllUsersName draftsProject,
Account.Id author) throws RepositoryNotFoundException, IOException {
this.changeId = change.getId();
this.changeId = changeId;
this.walk = walk;
this.tip = tip;
this.repo = repoManager.openRepository(draftsProject);
@@ -109,8 +109,8 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
private NoteMap noteMap;
DraftCommentNotes(GitRepositoryManager repoManager,
AllUsersName draftsProject, Change change, Account.Id author) {
super(repoManager, change);
AllUsersName draftsProject, Change.Id changeId, Account.Id author) {
super(repoManager, changeId);
this.draftsProject = draftsProject;
this.author = author;
@@ -167,7 +167,7 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
}
RevWalk walk = new RevWalk(reader);
Parser parser = new Parser(getChange(), walk, rev, repoManager,
Parser parser = new Parser(getChangeId(), walk, rev, repoManager,
draftsProject, author);
parser.parseDraftComments();