DependencyResolver: Resolve using ChangeNotes input
Instead of taking a PatchSet.Id as input, prefer a ChangeNotes object
and deprecate the less efficient API.
Change-Id: Idc9d5ba4d84ba52ec20d204fb0b19da6035ff4c2
diff --git a/src/main/java/com/googlesource/gerrit/plugins/depends/on/ChangeMessageStore.java b/src/main/java/com/googlesource/gerrit/plugins/depends/on/ChangeMessageStore.java
index c7fa832..6633132 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/depends/on/ChangeMessageStore.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/depends/on/ChangeMessageStore.java
@@ -134,10 +134,9 @@
/** If needed, create a comment on the change with a DependsOn for the dependencies. */
@Override
- public boolean resolveDependencies(PatchSet.Id patchSetId, Set<Set<BranchNameKey>> deliverables)
+ public boolean resolveDependencies(ChangeNotes changeNotes, Set<Set<BranchNameKey>> deliverables)
throws InvalidChangeOperationException, StorageException {
- Change.Id cid = patchSetId.changeId();
- Set<DependsOn> deps = load(cid);
+ Set<DependsOn> deps = load(changeNotes);
if (Resolver.isResolved(deps)) {
return false;
}
@@ -146,22 +145,25 @@
return false; // Nothing resolved this pass
}
// ToDo: add info about the resolved depends-on (deliverable, branch, and ChangeId?)
- store(patchSetId, resolved, "Auto-updating resolved Depends-on");
+ store(changeNotes, resolved, "Auto-updating resolved Depends-on");
return true;
}
+ /** If needed, create a comment on the change with a DependsOn for the dependencies. */
+ @Deprecated
+ @Override
+ public boolean resolveDependencies(PatchSet.Id patchSetId, Set<Set<BranchNameKey>> deliverables)
+ throws InvalidChangeOperationException, StorageException {
+ return resolveDependencies(
+ changeNotesFactory.createCheckedUsingIndexLookup(patchSetId.changeId()), deliverables);
+ }
+
@Override
public boolean hasUnresolvedDependsOn(Change.Id changeId) {
return !Resolver.isResolved(load(changeId));
}
/** Create a comment on the change with a DependsOn for the deps. */
- public void store(PatchSet.Id patchSetId, Set<DependsOn> deps, String message)
- throws InvalidChangeOperationException, StorageException {
- store(changeNotesFactory.createCheckedUsingIndexLookup(patchSetId.changeId()), deps, message);
- }
-
- /** Create a comment on the change with a DependsOn for the deps. */
public void store(ChangeNotes changeNotes, Set<DependsOn> deps, String message)
throws InvalidChangeOperationException, StorageException {
StringBuilder comment = new StringBuilder();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/depends/on/Module.java b/src/main/java/com/googlesource/gerrit/plugins/depends/on/Module.java
index 2b40b88..0ac50e2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/depends/on/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/depends/on/Module.java
@@ -26,6 +26,7 @@
import com.google.gerrit.server.DynamicOptions.DynamicBean;
import com.google.gerrit.server.change.ChangePluginDefinedInfoFactory;
import com.google.gerrit.server.events.EventListener;
+import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.query.change.ChangeQueryBuilder.ChangeHasOperandFactory;
@@ -79,6 +80,14 @@
}
@Override
+ public boolean resolveDependencies(
+ ChangeNotes changeNotes, Set<Set<BranchNameKey>> deliverables)
+ throws InvalidChangeOperationException {
+ return changeMessageStore.resolveDependencies(changeNotes, deliverables);
+ }
+
+ @Deprecated
+ @Override
public boolean resolveDependencies(PatchSet.Id patchSetId, Set<Set<BranchNameKey>> deliverables)
throws InvalidChangeOperationException, StorageException, NoSuchChangeException {
return changeMessageStore.resolveDependencies(patchSetId, deliverables);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/depends/on/extensions/DependencyResolver.java b/src/main/java/com/googlesource/gerrit/plugins/depends/on/extensions/DependencyResolver.java
index bf92899..3cde2eb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/depends/on/extensions/DependencyResolver.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/depends/on/extensions/DependencyResolver.java
@@ -19,12 +19,17 @@
import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.server.DynamicOptions.DynamicBean;
+import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.project.InvalidChangeOperationException;
import java.util.Set;
public interface DependencyResolver extends DynamicBean {
- public boolean resolveDependencies(PatchSet.Id patchSetId, Set<Set<BranchNameKey>> deliverables)
+ boolean resolveDependencies(ChangeNotes changeNotes, Set<Set<BranchNameKey>> deliverables)
throws InvalidChangeOperationException, StorageException;
- public boolean hasUnresolvedDependsOn(Change.Id changeId) throws StorageException;
+ @Deprecated
+ boolean resolveDependencies(PatchSet.Id patchSetId, Set<Set<BranchNameKey>> deliverables)
+ throws InvalidChangeOperationException, StorageException;
+
+ boolean hasUnresolvedDependsOn(Change.Id changeId) throws StorageException;
}