Refactor DeleteDraft into gerrit-server

This change moves logic that was duplicated over the ssh command and the
rpc handler into a DeleteDraft class in gerrit-server.

Change-Id: I308f5371697776cd210199910fc787fc1220fbf1
This commit is contained in:
Conley Owens
2012-01-24 10:59:10 -08:00
committed by Edwin Kempin
parent b917a2ac5a
commit 852e88bc9b
6 changed files with 161 additions and 72 deletions

View File

@@ -286,37 +286,7 @@ public class ChangeUtil {
db.changes().delete(Collections.singleton(change));
}
public static void deleteDraftPatchSet(final PatchSet.Id patchSetId,
GitRepositoryManager gitManager,
final ReplicationQueue replication,
final PatchSetInfoFactory patchSetInfoFactory,
final ReviewDb db) throws NoSuchChangeException, OrmException,
PatchSetInfoNotAvailableException, IOException {
final Change.Id changeId = patchSetId.getParentKey();
final Change change = db.changes().get(changeId);
final PatchSet patch = db.patchSets().get(patchSetId);
deleteOnlyDraftPatchSet(patch, change, gitManager, replication, db);
List<PatchSet> restOfPatches = db.patchSets().byChange(changeId).toList();
if (restOfPatches.size() == 0) {
deleteDraftChange(patchSetId, gitManager, replication, db);
} else {
PatchSet.Id highestId = null;
for (PatchSet ps : restOfPatches) {
if (highestId == null || ps.getPatchSetId() > highestId.get()) {
highestId = ps.getId();
}
}
if (change.currentPatchSetId().equals(patchSetId)) {
change.removeLastPatchSetId();
change.setCurrentPatchSet(patchSetInfoFactory.get(db, change.currPatchSetId()));
db.changes().update(Collections.singleton(change));
}
}
}
private static void deleteOnlyDraftPatchSet(final PatchSet patch,
public static void deleteOnlyDraftPatchSet(final PatchSet patch,
final Change change, GitRepositoryManager gitManager,
final ReplicationQueue replication, final ReviewDb db)
throws NoSuchChangeException, OrmException, IOException {