Add PatchList to StoredValues

commit_delta now stores PatchList so it doesn't need to be calculated
multiple times if the predicate is run multiple times

Change-Id: I17db4835bb29322d077873bddbd2690f9346f3f5
This commit is contained in:
Jason Tsay
2011-06-28 14:28:45 -07:00
parent 17e50aef6a
commit f815eab1b6
2 changed files with 20 additions and 10 deletions

View File

@@ -20,6 +20,7 @@ import com.google.gerrit.reviewdb.Change;
import com.google.gerrit.reviewdb.PatchSet;
import com.google.gerrit.reviewdb.PatchSetInfo;
import com.google.gerrit.reviewdb.ReviewDb;
import com.google.gerrit.server.patch.PatchList;
import com.google.gerrit.server.project.ChangeControl;
public final class StoredValues {
@@ -28,6 +29,7 @@ public final class StoredValues {
public static final StoredValue<PatchSet.Id> PATCH_SET_ID = create(PatchSet.Id.class);
public static final StoredValue<ChangeControl> CHANGE_CONTROL = create(ChangeControl.class);
public static final StoredValue<PatchSetInfo> PATCH_SET_INFO = create(PatchSetInfo.class);
public static final StoredValue<PatchList> PATCH_LIST = create(PatchList.class);
private StoredValues() {
}

View File

@@ -100,16 +100,7 @@ public class PRED_commit_delta_4 extends Predicate.P4 {
throw new JavaException(this, 1, err);
}
PatchListCache plCache = env.getInjector().getInstance(PatchListCache.class);
Change change = StoredValues.CHANGE.get(engine);
Project.NameKey projectKey = change.getProject();
ObjectId a = null;
ObjectId b = ObjectId.fromString(psInfo.getRevId());
Whitespace ws = Whitespace.IGNORE_NONE;
PatchListKey plKey = new PatchListKey(projectKey, a, b, ws);
PatchList pl = plCache.get(plKey);
PatchList pl = getPatchList(env, psInfo);
Iterator<PatchListEntry> iter = pl.getPatches().iterator();
engine.areg5 = new JavaObjectTerm(iter);
@@ -211,4 +202,21 @@ public class PRED_commit_delta_4 extends Predicate.P4 {
return psInfo;
}
protected PatchList getPatchList(PrologEnvironment env, PatchSetInfo psInfo) {
PatchList patchList = env.get(StoredValues.PATCH_LIST);
if (patchList == null) {
PatchListCache plCache = env.getInjector().getInstance(PatchListCache.class);
Change change = env.get(StoredValues.CHANGE);
Project.NameKey projectKey = change.getProject();
ObjectId a = null;
ObjectId b = ObjectId.fromString(psInfo.getRevId());
Whitespace ws = Whitespace.IGNORE_NONE;
PatchListKey plKey = new PatchListKey(projectKey, a, b, ws);
patchList = plCache.get(plKey);
env.set(StoredValues.PATCH_LIST, patchList);
}
return patchList;
}
}