Search in sources :

Example 1 with ReceiveCommits

use of com.google.gerrit.server.git.ReceiveCommits in project gerrit by GerritCodeReview.

the class Receive method runImpl.

@Override
protected void runImpl() throws IOException, Failure {
    if (!projectControl.canRunReceivePack()) {
        throw new Failure(1, "fatal: receive-pack not permitted on this server");
    }
    final ReceiveCommits receive = factory.create(projectControl, repo).getReceiveCommits();
    Capable r = receive.canUpload();
    if (r != Capable.OK) {
        throw die(r.getMessage());
    }
    receive.init();
    receive.addReviewers(reviewerId);
    receive.addExtraCC(ccId);
    ReceivePack rp = receive.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(projectControl.getProject().getName()).append("\"");
            msg.append(" (user ");
            msg.append(currentUser.getAccount().getUserName());
            msg.append(" account ");
            msg.append(currentUser.getAccountId());
            msg.append("): ");
            msg.append(badStream.getCause().getMessage());
            log.info(msg.toString());
            throw new UnloggedFailure(128, "error: " + badStream.getCause().getMessage());
        }
        // This may have been triggered by branch level access controls.
        // Log what the heck is going on, as detailed as we can.
        //
        StringBuilder msg = new StringBuilder();
        msg.append("Unpack error on project \"").append(projectControl.getProject().getName()).append("\":\n");
        msg.append("  AdvertiseRefsHook: ").append(rp.getAdvertiseRefsHook());
        if (rp.getAdvertiseRefsHook() == AdvertiseRefsHook.DEFAULT) {
            msg.append("DEFAULT");
        } else if (rp.getAdvertiseRefsHook() instanceof VisibleRefFilter) {
            msg.append("VisibleRefFilter");
        } else {
            msg.append(rp.getAdvertiseRefsHook().getClass());
        }
        msg.append("\n");
        if (rp.getAdvertiseRefsHook() instanceof VisibleRefFilter) {
            Map<String, Ref> adv = rp.getAdvertisedRefs();
            msg.append("  Visible references (").append(adv.size()).append("):\n");
            for (Ref ref : adv.values()) {
                msg.append("  - ").append(ref.getObjectId().abbreviate(8).name()).append(" ").append(ref.getName()).append("\n");
            }
            Map<String, Ref> allRefs = rp.getRepository().getRefDatabase().getRefs(RefDatabase.ALL);
            List<Ref> hidden = new ArrayList<>();
            for (Ref ref : allRefs.values()) {
                if (!adv.containsKey(ref.getName())) {
                    hidden.add(ref);
                }
            }
            msg.append("  Hidden references (").append(hidden.size()).append("):\n");
            for (Ref ref : hidden) {
                msg.append("  - ").append(ref.getObjectId().abbreviate(8).name()).append(" ").append(ref.getName()).append("\n");
            }
        }
        IOException detail = new IOException(msg.toString(), badStream);
        throw new Failure(128, "fatal: Unpack error, check server log", detail);
    }
}
Also used : TooLargeObjectInPackException(org.eclipse.jgit.errors.TooLargeObjectInPackException) IOException(java.io.IOException) AsyncReceiveCommits(com.google.gerrit.server.git.AsyncReceiveCommits) ReceiveCommits(com.google.gerrit.server.git.ReceiveCommits) Ref(org.eclipse.jgit.lib.Ref) Capable(com.google.gerrit.common.data.Capable) UnpackException(org.eclipse.jgit.errors.UnpackException) VisibleRefFilter(com.google.gerrit.server.git.VisibleRefFilter) ArrayList(java.util.ArrayList) List(java.util.List) ReceivePack(org.eclipse.jgit.transport.ReceivePack) Map(java.util.Map)

Aggregations

Capable (com.google.gerrit.common.data.Capable)1 AsyncReceiveCommits (com.google.gerrit.server.git.AsyncReceiveCommits)1 ReceiveCommits (com.google.gerrit.server.git.ReceiveCommits)1 VisibleRefFilter (com.google.gerrit.server.git.VisibleRefFilter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 TooLargeObjectInPackException (org.eclipse.jgit.errors.TooLargeObjectInPackException)1 UnpackException (org.eclipse.jgit.errors.UnpackException)1 Ref (org.eclipse.jgit.lib.Ref)1 ReceivePack (org.eclipse.jgit.transport.ReceivePack)1