Handle changes with non-existing current revision
We have a few changes that have a current revision that does not match
the revision of any of the patch sets in the change. This is a data
inconsistency and as result the import of such a change fails. Be more
tolerant, log a warning and use the last revision as current patch
set in this case so that this import is not failing.
Change-Id: Ifda86d116d1147362d7b3312d0e11e7a2bd54cc1
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayRevisionsStep.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayRevisionsStep.java
index 084d3cb..f13d4d3 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayRevisionsStep.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ReplayRevisionsStep.java
@@ -91,6 +91,7 @@
db.changes().beginTransaction(change.getId());
try {
+ PatchSetInfo info = null;
for (RevisionInfo r : revisions) {
if (r.draft != null && r.draft) {
// no import of draft patch sets
@@ -128,7 +129,7 @@
ps.setRevision(new RevId(commit.name()));
ps.setDraft(r.draft != null && r.draft);
- PatchSetInfo info = patchSetInfoFactory.get(commit, ps.getId());
+ info = patchSetInfoFactory.get(commit, ps.getId());
if (changeInfo.currentRevision.equals(info.getRevId())) {
change.setCurrentPatchSet(info);
}
@@ -138,6 +139,15 @@
updateRef(repo, ps);
}
+ if (change.currentPatchSetId() == null) {
+ log.warn(String.format(
+ "[%s] Current revision %s of change %s not found."
+ + " Setting lastest revision %s as current patch set.",
+ pluginName, changeInfo.currentRevision, changeInfo.id,
+ info.getRevId()));
+ change.setCurrentPatchSet(info);
+ }
+
db.patchSets().insert(patchSets);
db.commit();
} finally {