MergeOp: Cache open repositories

Rather than repeatedly opening/closing repositories for the various
steps of MergeOp, just cache each open project. Even in a relatively
complicated submitWholeTopic case, we're unlikely to have so many of
these open at once that it presents an issue.

Keep track of this state in a single object, OpenRepo, that is easy to
pass around. For now, this just contains a few fields; it will grow
some functionality later as it subsumes more of the state currently
stored in MergeOp instance fields.

Make MergeOp AutoCloseable so we are sure to close repositories after
the op finishes. There are only a handful of callers, so they are easy
to migrate.

Change-Id: Ic6216310318918edb437f8196e5f58f6d7459e38
This commit is contained in:
Dave Borowitz
2015-12-17 16:46:00 -05:00
parent bd765c74f8
commit 4b1e2a460e
3 changed files with 91 additions and 82 deletions

View File

@@ -1819,8 +1819,8 @@ public class ReceiveCommits {
throws OrmException, ResourceConflictException {
Submit submit = submitProvider.get();
RevisionResource rsrc = new RevisionResource(changes.parse(changeCtl), ps);
try {
mergeOpProvider.get().merge(db, rsrc.getChange(),
try (MergeOp op = mergeOpProvider.get()) {
op.merge(db, rsrc.getChange(),
changeCtl.getUser().asIdentifiedUser(), false);
} catch (NoSuchChangeException e) {
throw new OrmException(e);