LockFailureException: Expose ref names
Change-Id: I0bc3c077fe8e0a05e5b36987c959193058ce363e
This commit is contained in:
@@ -840,7 +840,7 @@ public class ExternalIdsUpdate {
|
||||
case FORCED:
|
||||
break;
|
||||
case LOCK_FAILURE:
|
||||
throw new LockFailureException("Updating external IDs failed with " + res);
|
||||
throw new LockFailureException("Updating external IDs failed with " + res, u);
|
||||
case IO_FAILURE:
|
||||
case NOT_ATTEMPTED:
|
||||
case REJECTED:
|
||||
|
||||
@@ -14,13 +14,38 @@
|
||||
|
||||
package com.google.gerrit.server.git;
|
||||
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.io.IOException;
|
||||
import org.eclipse.jgit.lib.BatchRefUpdate;
|
||||
import org.eclipse.jgit.lib.RefUpdate;
|
||||
import org.eclipse.jgit.transport.ReceiveCommand;
|
||||
|
||||
/** Thrown when updating a ref in Git fails with LOCK_FAILURE. */
|
||||
public class LockFailureException extends IOException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public LockFailureException(String message) {
|
||||
private final ImmutableList<String> refs;
|
||||
|
||||
public LockFailureException(String message, RefUpdate refUpdate) {
|
||||
super(message);
|
||||
refs = ImmutableList.of(refUpdate.getName());
|
||||
}
|
||||
|
||||
public LockFailureException(String message, BatchRefUpdate batchRefUpdate) {
|
||||
super(message);
|
||||
refs =
|
||||
batchRefUpdate
|
||||
.getCommands()
|
||||
.stream()
|
||||
.filter(c -> c.getResult() == ReceiveCommand.Result.LOCK_FAILURE)
|
||||
.map(ReceiveCommand::getRefName)
|
||||
.collect(toImmutableList());
|
||||
}
|
||||
|
||||
/** Subset of ref names that caused the lock failure. */
|
||||
public ImmutableList<String> getFailedRefs() {
|
||||
return refs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,7 +395,8 @@ public abstract class VersionedMetaData {
|
||||
+ " in "
|
||||
+ db.getDirectory()
|
||||
+ ": "
|
||||
+ ru.getResult());
|
||||
+ ru.getResult(),
|
||||
ru);
|
||||
case FORCED:
|
||||
case IO_FAILURE:
|
||||
case NOT_ATTEMPTED:
|
||||
|
||||
@@ -74,7 +74,7 @@ public class RefUpdateUtil {
|
||||
}
|
||||
|
||||
if (lockFailure + aborted == bru.getCommands().size()) {
|
||||
throw new LockFailureException("Update aborted with one or more lock failures: " + bru);
|
||||
throw new LockFailureException("Update aborted with one or more lock failures: " + bru, bru);
|
||||
} else if (failure > 0) {
|
||||
throw new IOException("Update failed: " + bru);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user