use of com.google.gerrit.server.git.receive.AsyncReceiveCommits in project gerrit by GerritCodeReview.
the class Receive method runImpl.
@Override
protected void runImpl() throws IOException, Failure {
CurrentUser currentUser = session.getUser();
try {
permissionBackend.user(currentUser).project(project.getNameKey()).check(ProjectPermission.RUN_RECEIVE_PACK);
} catch (AuthException e) {
throw new Failure(1, "fatal: receive-pack not permitted on this server", e);
} catch (PermissionBackendException e) {
throw new Failure(1, "fatal: unable to check permissions " + e);
}
AsyncReceiveCommits arc = factory.create(projectState, currentUser.asIdentifiedUser(), repo, null);
try {
Capable r = arc.canUpload();
if (r != Capable.OK) {
throw die(r.getMessage());
}
} catch (PermissionBackendException e) {
throw die(e.getMessage());
}
ReceivePack rp = arc.getReceivePack();
try {
rp.receive(in, out, err);
session.setPeerAgent(rp.getPeerUserAgent());
} catch (UnpackException badStream) {
// we want to present this error to the user
if (badStream.getCause() instanceof TooLargeObjectInPackException) {
StringBuilder msg = new StringBuilder();
msg.append("Receive error on project \"").append(projectState.getName()).append("\"");
msg.append(" (user ");
msg.append(currentUser.getUserName().orElse(null));
msg.append(" account ");
msg.append(currentUser.getAccountId());
msg.append("): ");
msg.append(badStream.getCause().getMessage());
logger.atInfo().log(msg.toString());
throw new UnloggedFailure(128, "error: " + badStream.getCause().getMessage());
}
StringBuilder msg = new StringBuilder();
msg.append("Unpack error on project \"").append(projectState.getName()).append("\":\n");
msg.append(" AdvertiseRefsHook: ").append(rp.getAdvertiseRefsHook());
if (rp.getAdvertiseRefsHook() == AdvertiseRefsHook.DEFAULT) {
msg.append("DEFAULT");
} else {
msg.append(rp.getAdvertiseRefsHook().getClass());
}
msg.append("\n");
IOException detail = new IOException(msg.toString(), badStream);
throw new Failure(128, "fatal: Unpack error, check server log", detail);
}
}
Aggregations