Don't throw IOException from ChangeInserter.createChange
This IOException is only thrown when the UTF-8 encoding is not available which is an illegal state. Hence we should rather wrap the IOException into an IllegalStateException. This makes the method signature cleaner and callers don't need to handle the IOException. In JGit the ChangeIdUtil.computeChangeId method was updated so that it no longer throws the IOException [1]. Once we upgrade to a JGit version that contains this change we can remove the exception handling completely. [1] https://git.eclipse.org/r/64670 Change-Id: I2839b1f640159a30d791c5063351162f004a65b0 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -149,7 +149,7 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Change createChange(Context ctx) throws IOException {
|
||||
public Change createChange(Context ctx) {
|
||||
change = new Change(
|
||||
getChangeKey(commit),
|
||||
changeId,
|
||||
@@ -163,18 +163,22 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
|
||||
return change;
|
||||
}
|
||||
|
||||
private static Change.Key getChangeKey(RevCommit commit) throws IOException {
|
||||
private static Change.Key getChangeKey(RevCommit commit) {
|
||||
List<String> idList = commit.getFooterLines(FooterConstants.CHANGE_ID);
|
||||
if (!idList.isEmpty()) {
|
||||
return new Change.Key(idList.get(idList.size() - 1).trim());
|
||||
}
|
||||
|
||||
try {
|
||||
ObjectId id = ChangeIdUtil.computeChangeId(commit.getTree(), commit,
|
||||
commit.getAuthorIdent(), commit.getCommitterIdent(),
|
||||
commit.getShortMessage());
|
||||
StringBuilder changeId = new StringBuilder();
|
||||
changeId.append("I").append(ObjectId.toString(id));
|
||||
return new Change.Key(changeId.toString());
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Change getChange() {
|
||||
|
@@ -236,7 +236,7 @@ public class CherryPickChange {
|
||||
ObjectInserter oi, Project.NameKey project,
|
||||
CodeReviewCommit cherryPickCommit, String refName,
|
||||
IdentifiedUser identifiedUser, String topic, Branch.NameKey sourceBranch)
|
||||
throws RestApiException, UpdateException, OrmException, IOException {
|
||||
throws RestApiException, UpdateException, OrmException {
|
||||
Change.Id changeId = new Change.Id(seq.nextChangeId());
|
||||
ChangeInserter ins = changeInserterFactory.create(
|
||||
changeId, cherryPickCommit, refName)
|
||||
|
@@ -231,7 +231,7 @@ public class BatchUpdate implements AutoCloseable {
|
||||
}
|
||||
|
||||
public abstract static class InsertChangeOp extends Op {
|
||||
public abstract Change createChange(Context ctx) throws IOException;
|
||||
public abstract Change createChange(Context ctx);
|
||||
}
|
||||
|
||||
private static class ChainedReceiveCommands {
|
||||
@@ -481,7 +481,7 @@ public class BatchUpdate implements AutoCloseable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public BatchUpdate insertChange(InsertChangeOp op) throws IOException {
|
||||
public BatchUpdate insertChange(InsertChangeOp op) {
|
||||
Context ctx = new Context();
|
||||
Change c = op.createChange(ctx);
|
||||
checkArgument(!newChanges.containsKey(c.getId()),
|
||||
|
@@ -1751,8 +1751,8 @@ public class ReceiveCommits {
|
||||
ListenableFuture<Void> future = changeUpdateExector.submit(
|
||||
requestScopePropagator.wrap(new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws IOException, OrmException,
|
||||
RestApiException, UpdateException {
|
||||
public Void call() throws OrmException, RestApiException,
|
||||
UpdateException {
|
||||
if (caller == Thread.currentThread()) {
|
||||
insertChange(ReceiveCommits.this.db);
|
||||
} else {
|
||||
@@ -1768,7 +1768,7 @@ public class ReceiveCommits {
|
||||
}
|
||||
|
||||
private void insertChange(ReviewDb threadLocalDb)
|
||||
throws IOException, OrmException, RestApiException, UpdateException {
|
||||
throws OrmException, RestApiException, UpdateException {
|
||||
final PatchSet ps = ins.setGroups(groups).getPatchSet();
|
||||
final Account.Id me = user.getAccountId();
|
||||
final List<FooterLine> footerLines = commit.getFooterLines();
|
||||
|
Reference in New Issue
Block a user