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

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

Introduction

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

Prototype

public void setMaxPackSizeLimit(long limit) 

Source Link

Document

Set the maximum allowed pack size.

Usage

From source file:com.googlesource.gerrit.plugins.quota.MaxRepositorySizeQuota.java

License:Apache License

@Override
public void init(Project.NameKey project, ReceivePack rp) {
    QuotaSection quotaSection = quotaFinder.firstMatching(project);
    if (quotaSection == null) {
        return;// w w w . j  a  v  a2  s.  co  m
    }

    Long maxRepoSize = quotaSection.getMaxRepoSize();
    Long maxTotalSize = quotaSection.getMaxTotalSize();
    if (maxRepoSize == null && maxTotalSize == null) {
        return;
    }

    try {
        Long maxPackSize1 = null;
        if (maxRepoSize != null) {
            maxPackSize1 = Math.max(0, maxRepoSize - cache.get(project).get());
        }

        Long maxPackSize2 = null;
        if (maxTotalSize != null) {
            long totalSize = 0;
            for (Project.NameKey p : projectCache.all()) {
                if (quotaSection.matches(p)) {
                    totalSize += cache.get(p).get();
                }
            }
            maxPackSize2 = Math.max(0, maxTotalSize - totalSize);
        }

        long maxPackSize = Ordering.<Long>natural().nullsLast().min(maxPackSize1, maxPackSize2);
        rp.setMaxPackSizeLimit(maxPackSize);
    } catch (ExecutionException e) {
        log.warn("Couldn't setMaxPackSizeLimit on receive-pack for " + project.get(), e);
    }
}