Mergeable: Factor out some methods to make code more readable
Change-Id: Iba4a2f73d479a5054de99c9b412b70483ca05054 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -101,34 +101,16 @@ public class Mergeable implements RestReadView<RevisionResource> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ChangeData cd = changeDataFactory.create(db.get(), resource.getControl());
|
ChangeData cd = changeDataFactory.create(db.get(), resource.getControl());
|
||||||
SubmitTypeRecord rec = new SubmitRuleEvaluator(cd)
|
result.submitType = getSubmitType(cd, ps);
|
||||||
.setPatchSet(ps)
|
|
||||||
.getSubmitType();
|
|
||||||
if (rec.status != SubmitTypeRecord.Status.OK) {
|
|
||||||
throw new OrmException("Submit type rule failed: " + rec);
|
|
||||||
}
|
|
||||||
result.submitType = rec.type;
|
|
||||||
|
|
||||||
try (Repository git = gitManager.openRepository(change.getProject())) {
|
try (Repository git = gitManager.openRepository(change.getProject())) {
|
||||||
ObjectId commit = toId(ps);
|
ObjectId commit = toId(ps);
|
||||||
if (commit == null) {
|
|
||||||
result.mergeable = false;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref ref = git.getRefDatabase().exactRef(change.getDest().get());
|
Ref ref = git.getRefDatabase().exactRef(change.getDest().get());
|
||||||
ProjectState projectState = projectCache.get(change.getProject());
|
ProjectState projectState = projectCache.get(change.getProject());
|
||||||
String strategy = mergeUtilFactory.create(projectState)
|
String strategy = mergeUtilFactory.create(projectState)
|
||||||
.mergeStrategyName();
|
.mergeStrategyName();
|
||||||
Boolean old =
|
result.mergeable =
|
||||||
cache.getIfPresent(commit, ref, result.submitType, strategy);
|
isMergable(git, change, commit, ref, result.submitType, strategy);
|
||||||
|
|
||||||
if (old == null) {
|
|
||||||
result.mergeable = refresh(change, commit, ref, result.submitType,
|
|
||||||
strategy, git, old);
|
|
||||||
} else {
|
|
||||||
result.mergeable = old;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (otherBranches) {
|
if (otherBranches) {
|
||||||
result.mergeableInto = new ArrayList<>();
|
result.mergeableInto = new ArrayList<>();
|
||||||
@@ -153,6 +135,31 @@ public class Mergeable implements RestReadView<RevisionResource> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SubmitType getSubmitType(ChangeData cd, PatchSet patchSet)
|
||||||
|
throws OrmException {
|
||||||
|
SubmitTypeRecord rec =
|
||||||
|
new SubmitRuleEvaluator(cd).setPatchSet(patchSet).getSubmitType();
|
||||||
|
if (rec.status != SubmitTypeRecord.Status.OK) {
|
||||||
|
throw new OrmException("Submit type rule failed: " + rec);
|
||||||
|
}
|
||||||
|
return rec.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isMergable(Repository git, Change change, ObjectId commit,
|
||||||
|
Ref ref, SubmitType submitType, String strategy)
|
||||||
|
throws IOException, OrmException {
|
||||||
|
if (commit == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean old = cache.getIfPresent(commit, ref, submitType, strategy);
|
||||||
|
if (old != null) {
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
return refresh(change, commit, ref, submitType,
|
||||||
|
strategy, git, old);
|
||||||
|
}
|
||||||
|
|
||||||
private static ObjectId toId(PatchSet ps) {
|
private static ObjectId toId(PatchSet ps) {
|
||||||
try {
|
try {
|
||||||
return ObjectId.fromString(ps.getRevision().get());
|
return ObjectId.fromString(ps.getRevision().get());
|
||||||
|
|||||||
Reference in New Issue
Block a user