Inject ChangeNotes into ChangeControl

Almost all of the places that will need a ChangeNotes (when we start
reading from that class) should already have a ChangeControl, so this
is a convenient way to ship it around.

To deal with the migration, do not eagerly load ChangeNotes from the
constructor. We could lazily load on e.g. getApprovals(), but that
would require catching OrmException in more places.

Change-Id: I545b555e8369f7f0f775b5188079ea3e93ed9cef
This commit is contained in:
Dave Borowitz
2013-12-19 14:14:06 -08:00
parent 0ff2ac5be2
commit f9ae78e51a
4 changed files with 74 additions and 42 deletions

View File

@@ -78,21 +78,8 @@ public class ChangeNotes extends VersionedMetaData {
this.repoManager = repoManager;
}
// TODO(dborowitz): Wrap fewer exceptions if/when we kill gwtorm.
public ChangeNotes load(Change change) throws OrmException {
Repository repo;
try {
repo = repoManager.openRepository(change.getProject());
} catch (IOException e) {
throw new OrmException(e);
}
try {
return new ChangeNotes(repo, change);
} catch (ConfigInvalidException | IOException e) {
throw new OrmException(e);
} finally {
repo.close();
}
public ChangeNotes create(Change change) {
return new ChangeNotes(repoManager, change);
}
}
@@ -241,15 +228,41 @@ public class ChangeNotes extends VersionedMetaData {
}
}
private final GitRepositoryManager repoManager;
private final Change change;
private boolean loaded;
private ImmutableListMultimap<PatchSet.Id, PatchSetApproval> approvals;
private ImmutableSetMultimap<ReviewerState, Account.Id> reviewers;
@VisibleForTesting
ChangeNotes(Repository repo, Change change)
throws ConfigInvalidException, IOException {
ChangeNotes(GitRepositoryManager repoManager, Change change) {
this.repoManager = repoManager;
this.change = change;
load(repo);
}
// TODO(dborowitz): Wrap fewer exceptions if/when we kill gwtorm.
public ChangeNotes load() throws OrmException {
if (!loaded) {
Repository repo;
try {
repo = repoManager.openRepository(change.getProject());
} catch (IOException e) {
throw new OrmException(e);
}
try {
load(repo);
loaded = true;
} catch (ConfigInvalidException | IOException e) {
throw new OrmException(e);
} finally {
repo.close();
}
}
return this;
}
public Change getChange() {
return change;
}
public ImmutableListMultimap<PatchSet.Id, PatchSetApproval> getApprovals() {