Example usage for org.eclipse.jgit.transport UploadPack setPreUploadHook

List of usage examples for org.eclipse.jgit.transport UploadPack setPreUploadHook

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport UploadPack setPreUploadHook.

Prototype

public void setPreUploadHook(@Nullable PreUploadHook hook) 

Source Link

Document

Set the hook that controls how this instance will behave.

Usage

From source file:com.google.gerrit.sshd.commands.Upload.java

License:Apache License

@Override
protected void runImpl() throws IOException, Failure {
    if (!projectControl.canRunUploadPack()) {
        throw new Failure(1, "fatal: upload-pack not permitted on this server");
    }//w  w w.  j a  v a  2s . co  m

    final UploadPack up = new UploadPack(repo);
    if (!projectControl.allRefsAreVisible()) {
        up.setAdvertiseRefsHook(
                new VisibleRefFilter(tagCache, changeCache, repo, projectControl, db.get(), true));
    }
    up.setPackConfig(config.getPackConfig());
    up.setTimeout(config.getTimeout());

    List<PreUploadHook> allPreUploadHooks = Lists.newArrayList(preUploadHooks);
    allPreUploadHooks.add(uploadValidatorsFactory.create(project, repo, session.getRemoteAddressAsString()));
    up.setPreUploadHook(PreUploadHookChain.newChain(allPreUploadHooks));
    try {
        up.upload(in, out, err);
    } catch (UploadValidationException e) {
        // UploadValidationException is used by the UploadValidators to
        // stop the uploadPack. We do not want this exception to go beyond this
        // point otherwise it would print a stacktrace in the logs and return an
        // internal server error to the client.
        if (!e.isOutput()) {
            up.sendMessage(e.getMessage());
        }
    }
}