MergeOp: Move destProject into OpenRepo
Less relying on global state being set correctly, more encapsulation. Change-Id: I62b921b8c5e2b739feadcacdf225df418dbbbc55
This commit is contained in:
@@ -128,11 +128,13 @@ public class MergeOp implements AutoCloseable {
|
|||||||
final CodeReviewRevWalk rw;
|
final CodeReviewRevWalk rw;
|
||||||
final RevFlag canMergeFlag;
|
final RevFlag canMergeFlag;
|
||||||
final ObjectInserter ins;
|
final ObjectInserter ins;
|
||||||
|
ProjectState project;
|
||||||
|
|
||||||
private final Map<Branch.NameKey, OpenBranch> branches;
|
private final Map<Branch.NameKey, OpenBranch> branches;
|
||||||
|
|
||||||
OpenRepo(Repository repo) {
|
OpenRepo(Repository repo, ProjectState project) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
|
this.project = project;
|
||||||
rw = CodeReviewCommit.newRevWalk(repo);
|
rw = CodeReviewCommit.newRevWalk(repo);
|
||||||
rw.sort(RevSort.TOPO);
|
rw.sort(RevSort.TOPO);
|
||||||
rw.sort(RevSort.COMMIT_TIME_DESC, true);
|
rw.sort(RevSort.COMMIT_TIME_DESC, true);
|
||||||
@@ -152,6 +154,10 @@ public class MergeOp implements AutoCloseable {
|
|||||||
return ob;
|
return ob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Project.NameKey getProjectName() {
|
||||||
|
return project.getProject().getNameKey();
|
||||||
|
}
|
||||||
|
|
||||||
void close() {
|
void close() {
|
||||||
ins.close();
|
ins.close();
|
||||||
rw.close();
|
rw.close();
|
||||||
@@ -228,7 +234,6 @@ public class MergeOp implements AutoCloseable {
|
|||||||
private String staticSubmissionId;
|
private String staticSubmissionId;
|
||||||
private String submissionId;
|
private String submissionId;
|
||||||
|
|
||||||
private ProjectState destProject;
|
|
||||||
private ReviewDb db;
|
private ReviewDb db;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -286,8 +291,12 @@ public class MergeOp implements AutoCloseable {
|
|||||||
throws NoSuchProjectException, IOException {
|
throws NoSuchProjectException, IOException {
|
||||||
OpenRepo repo = openRepos.get(project);
|
OpenRepo repo = openRepos.get(project);
|
||||||
if (repo == null) {
|
if (repo == null) {
|
||||||
|
ProjectState projectState = projectCache.get(project);
|
||||||
|
if (projectState == null) {
|
||||||
|
throw new NoSuchProjectException(project);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
repo = new OpenRepo(repoManager.openRepository(project));
|
repo = new OpenRepo(repoManager.openRepository(project), projectState);
|
||||||
} catch (RepositoryNotFoundException e) {
|
} catch (RepositoryNotFoundException e) {
|
||||||
throw new NoSuchProjectException(project);
|
throw new NoSuchProjectException(project);
|
||||||
}
|
}
|
||||||
@@ -303,15 +312,6 @@ public class MergeOp implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDestProject(Branch.NameKey destBranch)
|
|
||||||
throws IntegrationException {
|
|
||||||
destProject = projectCache.get(destBranch.getParentKey());
|
|
||||||
if (destProject == null) {
|
|
||||||
throw new IntegrationException(
|
|
||||||
"No such project: " + destBranch.getParentKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Optional<SubmitRecord> findOkRecord(Collection<SubmitRecord> in) {
|
private static Optional<SubmitRecord> findOkRecord(Collection<SubmitRecord> in) {
|
||||||
return Iterables.tryFind(in, new Predicate<SubmitRecord>() {
|
return Iterables.tryFind(in, new Predicate<SubmitRecord>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -477,7 +477,6 @@ public class MergeOp implements AutoCloseable {
|
|||||||
for (Project.NameKey project : br.keySet()) {
|
for (Project.NameKey project : br.keySet()) {
|
||||||
OpenRepo or = openRepo(project);
|
OpenRepo or = openRepo(project);
|
||||||
for (Branch.NameKey branch : br.get(project)) {
|
for (Branch.NameKey branch : br.get(project)) {
|
||||||
setDestProject(branch);
|
|
||||||
BranchBatch submitting = validateChangeList(or, cbb.get(branch));
|
BranchBatch submitting = validateChangeList(or, cbb.get(branch));
|
||||||
toSubmit.put(branch, submitting);
|
toSubmit.put(branch, submitting);
|
||||||
|
|
||||||
@@ -499,7 +498,6 @@ public class MergeOp implements AutoCloseable {
|
|||||||
OpenBranch ob = or.getBranch(branch);
|
OpenBranch ob = or.getBranch(branch);
|
||||||
boolean updated = updateBranch(or, branch, caller);
|
boolean updated = updateBranch(or, branch, caller);
|
||||||
|
|
||||||
setDestProject(branch);
|
|
||||||
BranchBatch submitting = toSubmit.get(branch);
|
BranchBatch submitting = toSubmit.get(branch);
|
||||||
updateChangeStatus(ob, submitting.changes(), false, caller);
|
updateChangeStatus(ob, submitting.changes(), false, caller);
|
||||||
updateSubmoduleSubscriptions(ob, subOp);
|
updateSubmoduleSubscriptions(ob, subOp);
|
||||||
@@ -663,7 +661,7 @@ public class MergeOp implements AutoCloseable {
|
|||||||
MergeValidators mergeValidators = mergeValidatorsFactory.create();
|
MergeValidators mergeValidators = mergeValidatorsFactory.create();
|
||||||
try {
|
try {
|
||||||
mergeValidators.validatePreMerge(
|
mergeValidators.validatePreMerge(
|
||||||
or.repo, commit, destProject, destBranch, ps.getId());
|
or.repo, commit, or.project, destBranch, ps.getId());
|
||||||
} catch (MergeValidationException mve) {
|
} catch (MergeValidationException mve) {
|
||||||
logDebug("Revision {} of patch set {} failed validation: {}",
|
logDebug("Revision {} of patch set {} failed validation: {}",
|
||||||
idstr, ps.getId(), mve.getStatus());
|
idstr, ps.getId(), mve.getStatus());
|
||||||
@@ -755,13 +753,12 @@ public class MergeOp implements AutoCloseable {
|
|||||||
if (RefNames.REFS_CONFIG.equals(ob.update.getName())) {
|
if (RefNames.REFS_CONFIG.equals(ob.update.getName())) {
|
||||||
logDebug("Loading new configuration from {}", RefNames.REFS_CONFIG);
|
logDebug("Loading new configuration from {}", RefNames.REFS_CONFIG);
|
||||||
try {
|
try {
|
||||||
ProjectConfig cfg =
|
ProjectConfig cfg = new ProjectConfig(or.getProjectName());
|
||||||
new ProjectConfig(destProject.getProject().getNameKey());
|
|
||||||
cfg.load(or.repo, currentTip);
|
cfg.load(or.repo, currentTip);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IntegrationException("Submit would store invalid"
|
throw new IntegrationException("Submit would store invalid"
|
||||||
+ " project configuration " + currentTip.name() + " for "
|
+ " project configuration " + currentTip.name() + " for "
|
||||||
+ destProject.getProject().getName(), e);
|
+ or.getProjectName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -786,9 +783,9 @@ public class MergeOp implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (RefNames.REFS_CONFIG.equals(ob.update.getName())) {
|
if (RefNames.REFS_CONFIG.equals(ob.update.getName())) {
|
||||||
Project p = destProject.getProject();
|
Project p = or.project.getProject();
|
||||||
projectCache.evict(p);
|
projectCache.evict(p);
|
||||||
destProject = projectCache.get(p.getNameKey());
|
or.project = projectCache.get(p.getNameKey());
|
||||||
repoManager.setProjectDescription(
|
repoManager.setProjectDescription(
|
||||||
p.getNameKey(), p.getDescription());
|
p.getNameKey(), p.getDescription());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user