Example usage for org.eclipse.jgit.transport ReceivePack setBiDirectionalPipe

List of usage examples for org.eclipse.jgit.transport ReceivePack setBiDirectionalPipe

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport ReceivePack setBiDirectionalPipe.

Prototype

public void setBiDirectionalPipe(boolean twoWay) 

Source Link

Document

Whether this class will assume the socket is a fully bidirectional pipe between the two peers and takes advantage of that by first transmitting the known refs, then waiting to read commands.

Usage

From source file:org.webcat.core.git.http.ReceivePackRequestHandler.java

License:Open Source License

/**
 * Handles the request and generates the ReceivePack response.
 *
 * @param request the request//from ww  w . j a  v  a2 s.c om
 * @param response the response
 * @throws Exception if an error occurs
 */
public void handleRequest(WORequest request, WOResponse response) throws Exception {
    String contentType = request.headerForKey(HttpSupport.HDR_CONTENT_TYPE);

    if (RECEIVE_PACK_REQUEST_TYPE.equals(contentType)) {
        final Repository repo = RepositoryRequestUtils.repositoryFromRequest(request);

        ReceivePack rp = new ReceivePack(repo);
        rp.setBiDirectionalPipe(false);
        rp.setPostReceiveHook(new PostReceiveHook() {
            public void onPostReceive(ReceivePack pack, Collection<ReceiveCommand> commands) {
                // Once the pack is received, force a pull of the working
                // copy so that anyone using Web-DAV will get synched.
                GitUtilities.workingCopyForRepository(repo, true);
            }
        });

        response.setHeader(RECEIVE_PACK_RESULT_TYPE, HttpSupport.HDR_CONTENT_TYPE);

        InputStream input = RequestUtils.inputStreamForRequest(request);
        SmartGZIPOutputStream output = new SmartGZIPOutputStream(request, response);

        rp.receive(input, output, null);

        output.close();
    } else {
        response.setStatus(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE);
    }
}

From source file:playRepository.RepositoryService.java

License:Apache License

private static void receivePack(final InputStream input, Repository repository, final OutputStream output,
        final PreReceiveHook preReceiveHook, final PostReceiveHook postReceiveHook) {
    final ReceivePack receivePack = new ReceivePack(repository);
    receivePack.setBiDirectionalPipe(false);
    new Thread() {
        @Override//from  w w  w  . j a  v a2  s.  c  o  m
        public void run() {
            try {
                receivePack.setPreReceiveHook(preReceiveHook);
                receivePack.setPostReceiveHook(postReceiveHook);
                receivePack.receive(input, output, null);
            } catch (IOException e) {
                Logger.error("receivePack failed", e);
            }

            closeStreams("receivePack", input, output);
        }
    }.start();
}