SubmoduleOp: Make the constructor a pure one

Currently we're doing quite some work in the constructor, which is
discouraged. This commit moves the process of computing
SubscriptionGraph to the Factory's create method, which makes the
constructor a pure constructor.

Change-Id: I1582913841fcbf0e04d2da3c4537949c7987873c
This commit is contained in:
Yunjie Li
2020-06-08 23:46:16 -07:00
parent 3313e5f4b9
commit 4ad55592f7

View File

@@ -104,8 +104,15 @@ public class SubmoduleOp {
public SubmoduleOp create(Set<BranchNameKey> updatedBranches, MergeOpRepoManager orm) public SubmoduleOp create(Set<BranchNameKey> updatedBranches, MergeOpRepoManager orm)
throws SubmoduleConflictException { throws SubmoduleConflictException {
return new SubmoduleOp( SubscriptionGraph subscriptionGraph;
subscriptionGraphFactory, serverIdent.get(), cfg, updatedBranches, orm); if (cfg.getBoolean("submodule", "enableSuperProjectSubscriptions", true)) {
subscriptionGraph = subscriptionGraphFactory.compute(updatedBranches, orm);
} else {
logger.atFine().log("Updating superprojects disabled");
subscriptionGraph =
SubscriptionGraph.createEmptyGraph(ImmutableSet.copyOf(updatedBranches));
}
return new SubmoduleOp(serverIdent.get(), cfg, orm, subscriptionGraph);
} }
} }
@@ -119,12 +126,10 @@ public class SubmoduleOp {
private final BranchTips branchTips = new BranchTips(); private final BranchTips branchTips = new BranchTips();
private SubmoduleOp( private SubmoduleOp(
SubscriptionGraph.Factory subscriptionGraphFactory,
PersonIdent myIdent, PersonIdent myIdent,
Config cfg, Config cfg,
Set<BranchNameKey> updatedBranches, MergeOpRepoManager orm,
MergeOpRepoManager orm) SubscriptionGraph subscriptionGraph) {
throws SubmoduleConflictException {
this.myIdent = myIdent; this.myIdent = myIdent;
this.verboseSuperProject = this.verboseSuperProject =
cfg.getEnum("submodule", null, "verboseSuperprojectUpdate", VerboseSuperprojectUpdate.TRUE); cfg.getEnum("submodule", null, "verboseSuperprojectUpdate", VerboseSuperprojectUpdate.TRUE);
@@ -132,13 +137,7 @@ public class SubmoduleOp {
cfg.getLong("submodule", "maxCombinedCommitMessageSize", 256 << 10); cfg.getLong("submodule", "maxCombinedCommitMessageSize", 256 << 10);
this.maxCommitMessages = cfg.getLong("submodule", "maxCommitMessages", 1000); this.maxCommitMessages = cfg.getLong("submodule", "maxCommitMessages", 1000);
this.orm = orm; this.orm = orm;
if (cfg.getBoolean("submodule", "enableSuperProjectSubscriptions", true)) { this.subscriptionGraph = subscriptionGraph;
this.subscriptionGraph = subscriptionGraphFactory.compute(updatedBranches, orm);
} else {
logger.atFine().log("Updating superprojects disabled");
this.subscriptionGraph =
SubscriptionGraph.createEmptyGraph(ImmutableSet.copyOf(updatedBranches));
}
} }
@UsedAt(UsedAt.Project.PLUGIN_DELETE_PROJECT) @UsedAt(UsedAt.Project.PLUGIN_DELETE_PROJECT)