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

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

Introduction

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

Prototype

public void setRefFilter(@Nullable RefFilter refFilter) 

Source Link

Document

Set the filter used while advertising the refs to the client.

Usage

From source file:org.guvnor.structure.backend.repositories.git.GitRepositoryBuilder.java

License:Apache License

private FileSystemHooks.FileSystemHook filterBranchAccessCallback() {
    return ctx -> {
        final UploadPack uploadPack = (UploadPack) ctx.getParamValue(FileSystemHooksConstants.UPLOAD_PACK);
        final User user = (User) ctx.getParamValue(FileSystemHooksConstants.USER);
        uploadPack.setRefFilter(refs -> refs.entrySet().stream()
                .filter(ref -> !HiddenBranchRefFilter.isHidden(ref.getKey())).filter(ref -> {
                    final Optional<String> branchName = GitPathUtil
                            .extractBranchFromRef(ref.getValue().getName());
                    if (branchName.isPresent()) {
                        return branchAccessAuthorizer.authorize(user.getIdentifier(), repo.getSpace().getName(),
                                repo.getIdentifier(), repo.getAlias(), branchName.get(),
                                BranchAccessAuthorizer.AccessType.READ);
                    }/*from ww  w.  j a v  a2s  .c  o  m*/

                    return true;
                }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
    };
}