Allow per project maxObjectSizeLimit.
Project owners can define receive.maxObjectSizeLimit in their project.config in order to further restrict the global receive.maxObjectSizeLimit setting from etc/gerrit.config. The project specific maxObjectSizeLimit is only honored if smaller than the global maxObjectSizeLimit, otherwise it is ignored. Change-Id: Ia14354e0c9b6bfb4fa62295162e8f2c127b09997
This commit is contained in:
parent
72e949f48b
commit
5a708a8b45
@ -2099,6 +2099,10 @@ limit.
|
||||
Gerrit administrators can use this setting to prevent developers
|
||||
from pushing objects which are too large to Gerrit.
|
||||
+
|
||||
This setting can also be set in the `project.config` in order to further
|
||||
reduce the global setting. The project specific setting is only honored
|
||||
when it further reduces the global limit.
|
||||
+
|
||||
Default is zero.
|
||||
+
|
||||
Common unit suffixes of 'k', 'm', or 'g' are supported.
|
||||
|
@ -107,6 +107,7 @@ public class ProjectConfig extends VersionedMetaData {
|
||||
private static final String RECEIVE = "receive";
|
||||
private static final String KEY_REQUIRE_SIGNED_OFF_BY = "requireSignedOffBy";
|
||||
private static final String KEY_REQUIRE_CHANGE_ID = "requireChangeId";
|
||||
private static final String KEY_MAX_OBJECT_SIZE_LIMIT = "maxObjectSizeLimit";
|
||||
private static final String KEY_REQUIRE_CONTRIBUTOR_AGREEMENT =
|
||||
"requireContributorAgreement";
|
||||
|
||||
@ -145,6 +146,7 @@ public class ProjectConfig extends VersionedMetaData {
|
||||
private List<CommentLinkInfo> commentLinkSections;
|
||||
private List<ValidationError> validationErrors;
|
||||
private ObjectId rulesId;
|
||||
private long maxObjectSizeLimit;
|
||||
|
||||
public static ProjectConfig read(MetaDataUpdate update) throws IOException,
|
||||
ConfigInvalidException {
|
||||
@ -318,6 +320,14 @@ public class ProjectConfig extends VersionedMetaData {
|
||||
return rulesId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maxObjectSizeLimit for this project, if set. Zero if this
|
||||
* project doesn't define own maxObjectSizeLimit.
|
||||
*/
|
||||
public long getMaxObjectSizeLimit() {
|
||||
return maxObjectSizeLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all GroupReferences use current group name, repairing stale ones.
|
||||
*
|
||||
@ -386,6 +396,8 @@ public class ProjectConfig extends VersionedMetaData {
|
||||
loadNotifySections(rc, groupsByName);
|
||||
loadLabelSections(rc);
|
||||
loadCommentLinkSections(rc);
|
||||
|
||||
maxObjectSizeLimit = rc.getLong(RECEIVE, null, KEY_MAX_OBJECT_SIZE_LIMIT, 0);
|
||||
}
|
||||
|
||||
private void loadAccountsSection(
|
||||
|
@ -216,6 +216,10 @@ public class ProjectState {
|
||||
return config;
|
||||
}
|
||||
|
||||
public long getMaxObjectSizeLimit() {
|
||||
return config.getMaxObjectSizeLimit();
|
||||
}
|
||||
|
||||
/** Get the sections that pertain only to this project. */
|
||||
List<SectionMatcher> getLocalAccessSections() {
|
||||
List<SectionMatcher> sm = localAccessSections;
|
||||
|
@ -94,7 +94,7 @@ final class Receive extends AbstractGitCommand {
|
||||
final ReceivePack rp = receive.getReceivePack();
|
||||
rp.setRefLogIdent(currentUser.newRefLogIdent());
|
||||
rp.setTimeout(config.getTimeout());
|
||||
rp.setMaxObjectSizeLimit(config.getMaxObjectSizeLimit());
|
||||
rp.setMaxObjectSizeLimit(getMaxObjectSizeLimit());
|
||||
try {
|
||||
receive.advertiseHistory();
|
||||
rp.receive(in, out, err);
|
||||
@ -170,4 +170,15 @@ final class Receive extends AbstractGitCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private long getMaxObjectSizeLimit() {
|
||||
long global = config.getMaxObjectSizeLimit();
|
||||
long local = projectControl.getProjectState().getMaxObjectSizeLimit();
|
||||
if (global > 0 && local > 0) {
|
||||
return Math.min(global, local);
|
||||
} else {
|
||||
// zero means "no limit", in this case the max is more limiting
|
||||
return Math.max(global, local);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user