Make MergeConflictException a ResourceConflictException

This means we don't have to unwrap this exception type when used from
a BatchUpdate, since BatchUpdate propagates RestApiExceptions.

Change-Id: I3b655308ec22913bee0b9114074d192360466893
This commit is contained in:
Dave Borowitz
2015-10-28 15:48:07 -04:00
parent a7e5f122fa
commit f0112b9a74
7 changed files with 18 additions and 20 deletions

View File

@@ -12,11 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.git;
package com.google.gerrit.extensions.restapi;
/** Indicates that the commit cannot be merged without conflicts. */
public class MergeConflictException extends Exception {
/**
* Indicates that a commit cannot be merged without conflicts.
* <p>
* Messages should be viewable by end users.
*/
public class MergeConflictException extends ResourceConflictException {
private static final long serialVersionUID = 1L;
public MergeConflictException(String msg) {
super(msg, null);
}

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server.change;
import com.google.common.base.Strings;
import com.google.gerrit.common.FooterConstants;
import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.extensions.restapi.MergeConflictException;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change;
@@ -33,7 +34,6 @@ import com.google.gerrit.server.git.BatchUpdate;
import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.MergeConflictException;
import com.google.gerrit.server.git.MergeException;
import com.google.gerrit.server.git.MergeIdenticalTreeException;
import com.google.gerrit.server.git.MergeUtil;

View File

@@ -33,7 +33,6 @@ import com.google.gerrit.reviewdb.client.RevId;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.git.BatchUpdate;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.MergeConflictException;
import com.google.gerrit.server.git.UpdateException;
import com.google.gerrit.server.git.validators.CommitValidators;
import com.google.gerrit.server.project.ChangeControl;
@@ -108,10 +107,6 @@ public class Rebase implements RestModifyView<RevisionResource, RebaseInput>,
.setRunHooks(true)
.setValidatePolicy(CommitValidators.Policy.GERRIT));
bu.execute();
} catch (UpdateException e) {
if (e.getCause() instanceof MergeConflictException) {
throw new ResourceConflictException(e.getCause().getMessage());
}
}
return json.create(OPTIONS).format(change.getId());
}

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server.change;
import static com.google.common.base.Preconditions.checkState;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.restapi.MergeConflictException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.reviewdb.client.PatchSet;
@@ -25,7 +26,6 @@ import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.git.BatchUpdate;
import com.google.gerrit.server.git.BatchUpdate.ChangeContext;
import com.google.gerrit.server.git.BatchUpdate.RepoContext;
import com.google.gerrit.server.git.MergeConflictException;
import com.google.gerrit.server.git.MergeUtil;
import com.google.gerrit.server.git.validators.CommitValidators;
import com.google.gerrit.server.project.ChangeControl;

View File

@@ -23,6 +23,7 @@ import com.google.common.collect.Iterables;
import com.google.gerrit.common.FooterConstants;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.extensions.restapi.MergeConflictException;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change;

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.server.git.strategy;
import com.google.common.collect.Lists;
import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.extensions.restapi.MergeConflictException;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
@@ -29,7 +30,6 @@ import com.google.gerrit.server.git.BatchUpdate.RepoContext;
import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.CommitMergeStatus;
import com.google.gerrit.server.git.GroupCollector;
import com.google.gerrit.server.git.MergeConflictException;
import com.google.gerrit.server.git.MergeException;
import com.google.gerrit.server.git.MergeIdenticalTreeException;
import com.google.gerrit.server.git.MergeTip;

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.server.git.strategy;
import com.google.common.collect.Lists;
import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.extensions.restapi.MergeConflictException;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
@@ -24,7 +25,6 @@ import com.google.gerrit.server.change.RebaseChangeOp;
import com.google.gerrit.server.git.BatchUpdate;
import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.CommitMergeStatus;
import com.google.gerrit.server.git.MergeConflictException;
import com.google.gerrit.server.git.MergeException;
import com.google.gerrit.server.git.MergeTip;
import com.google.gerrit.server.git.RebaseSorter;
@@ -111,15 +111,12 @@ public class RebaseIfNecessary extends SubmitStrategy {
newCommits.put(newPatchSet.getId().getParentKey(),
mergeTip.getCurrentTip());
setRefLogIdent();
} catch (UpdateException e) {
if (e.getCause() instanceof MergeConflictException) {
} catch (MergeConflictException e) {
n.setStatusCode(CommitMergeStatus.REBASE_MERGE_CONFLICT);
}
throw new MergeException("Cannot rebase " + n.name(), e);
throw new MergeException(
"Cannot rebase " + n.name() + ": " + e.getMessage(), e);
} catch (NoSuchChangeException | OrmException | IOException
| RestApiException e) {
// TODO(dborowitz): Allow Submit to unwrap ResourceConflictException
// so it can turn into a 409.
| RestApiException | UpdateException e) {
throw new MergeException("Cannot rebase " + n.name(), e);
}
}