Line data Source code
1 : // Copyright (C) 2013 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.git.receive; 16 : 17 : import static com.google.gerrit.common.data.GlobalCapability.BATCH_CHANGES_LIMIT; 18 : 19 : import com.google.gerrit.server.CurrentUser; 20 : import com.google.gerrit.server.account.AccountLimits; 21 : import com.google.gerrit.server.config.GerritServerConfig; 22 : import com.google.inject.Inject; 23 : import com.google.inject.Singleton; 24 : import org.eclipse.jgit.lib.Config; 25 : 26 : @Singleton 27 : class ReceiveConfig { 28 : final boolean checkMagicRefs; 29 : final boolean checkReferencedObjectsAreReachable; 30 : final int maxBatchCommits; 31 : final boolean disablePrivateChanges; 32 : private final int systemMaxBatchChanges; 33 : private final AccountLimits.Factory limitsFactory; 34 : 35 : @Inject 36 138 : ReceiveConfig(@GerritServerConfig Config config, AccountLimits.Factory limitsFactory) { 37 138 : checkMagicRefs = config.getBoolean("receive", null, "checkMagicRefs", true); 38 138 : checkReferencedObjectsAreReachable = 39 138 : config.getBoolean("receive", null, "checkReferencedObjectsAreReachable", true); 40 138 : maxBatchCommits = config.getInt("receive", null, "maxBatchCommits", 10000); 41 138 : systemMaxBatchChanges = config.getInt("receive", "maxBatchChanges", 0); 42 138 : disablePrivateChanges = config.getBoolean("change", null, "disablePrivateChanges", false); 43 138 : this.limitsFactory = limitsFactory; 44 138 : } 45 : 46 : public int getEffectiveMaxBatchChangesLimit(CurrentUser user) { 47 89 : AccountLimits limits = limitsFactory.create(user); 48 89 : if (limits.hasExplicitRange(BATCH_CHANGES_LIMIT)) { 49 0 : return limits.getRange(BATCH_CHANGES_LIMIT).getMax(); 50 : } 51 89 : return systemMaxBatchChanges; 52 : } 53 : }