Use PatchsetUtil to get PatchSets for a change
This fixes importing if NoteDb read is enabled. The change owner is
used as the user for creating the ChangeControl.
Change-Id: I4c0f05a9d39b51c8fd5abefb3430b67e416f45bc
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java
index 49f969c..2584978 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java
@@ -35,8 +35,10 @@
import com.google.gerrit.reviewdb.client.PatchLineComment;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.server.ReviewDb;
+import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.PatchLineCommentsUtil;
+import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.patch.PatchListCache;
import com.google.gerrit.server.project.ChangeControl;
@@ -74,6 +76,7 @@
private final ChangeUpdate.Factory updateFactory;
private final PatchLineCommentsUtil plcUtil;
private final PatchListCache patchListCache;
+ private final PatchSetUtil psUtil;
private final Change change;
private final ChangeInfo changeInfo;
private final GerritApi api;
@@ -87,6 +90,7 @@
ChangeUpdate.Factory updateFactory,
PatchLineCommentsUtil plcUtil,
PatchListCache patchListCache,
+ PatchSetUtil psUtil,
@Assisted Change change,
@Assisted ChangeInfo changeInfo,
@Assisted GerritApi api,
@@ -98,6 +102,7 @@
this.updateFactory = updateFactory;
this.plcUtil = plcUtil;
this.patchListCache = patchListCache;
+ this.psUtil = psUtil;
this.change = change;
this.changeInfo = changeInfo;
this.api = api;
@@ -107,7 +112,9 @@
void replay()
throws RestApiException, OrmException, IOException, NoSuchChangeException,
NoSuchAccountException, ConfigInvalidException, InvalidSshKeyException {
- for (PatchSet ps : db.patchSets().byChange(change.getId())) {
+ ChangeControl ctrl = control(change, change.getOwner());
+ for (PatchSet ps : ChangeUtil.PS_ID_ORDER
+ .sortedCopy(psUtil.byChange(db, ctrl.getNotes()))) {
Iterable<CommentInfo> comments = api.getComments(
changeInfo._number, ps.getRevision().get());
if (resume) {