Merge "Allow per project maxObjectSizeLimit."

This commit is contained in:
Sasa Zivkov
2013-07-02 11:22:32 +00:00
committed by Gerrit Code Review
4 changed files with 32 additions and 1 deletions

View File

@@ -2099,6 +2099,10 @@ limit.
Gerrit administrators can use this setting to prevent developers Gerrit administrators can use this setting to prevent developers
from pushing objects which are too large to Gerrit. 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. Default is zero.
+ +
Common unit suffixes of 'k', 'm', or 'g' are supported. Common unit suffixes of 'k', 'm', or 'g' are supported.

View File

@@ -107,6 +107,7 @@ public class ProjectConfig extends VersionedMetaData {
private static final String RECEIVE = "receive"; private static final String RECEIVE = "receive";
private static final String KEY_REQUIRE_SIGNED_OFF_BY = "requireSignedOffBy"; private static final String KEY_REQUIRE_SIGNED_OFF_BY = "requireSignedOffBy";
private static final String KEY_REQUIRE_CHANGE_ID = "requireChangeId"; 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 = private static final String KEY_REQUIRE_CONTRIBUTOR_AGREEMENT =
"requireContributorAgreement"; "requireContributorAgreement";
@@ -145,6 +146,7 @@ public class ProjectConfig extends VersionedMetaData {
private List<CommentLinkInfo> commentLinkSections; private List<CommentLinkInfo> commentLinkSections;
private List<ValidationError> validationErrors; private List<ValidationError> validationErrors;
private ObjectId rulesId; private ObjectId rulesId;
private long maxObjectSizeLimit;
public static ProjectConfig read(MetaDataUpdate update) throws IOException, public static ProjectConfig read(MetaDataUpdate update) throws IOException,
ConfigInvalidException { ConfigInvalidException {
@@ -318,6 +320,14 @@ public class ProjectConfig extends VersionedMetaData {
return rulesId; 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. * Check all GroupReferences use current group name, repairing stale ones.
* *
@@ -386,6 +396,8 @@ public class ProjectConfig extends VersionedMetaData {
loadNotifySections(rc, groupsByName); loadNotifySections(rc, groupsByName);
loadLabelSections(rc); loadLabelSections(rc);
loadCommentLinkSections(rc); loadCommentLinkSections(rc);
maxObjectSizeLimit = rc.getLong(RECEIVE, null, KEY_MAX_OBJECT_SIZE_LIMIT, 0);
} }
private void loadAccountsSection( private void loadAccountsSection(

View File

@@ -216,6 +216,10 @@ public class ProjectState {
return config; return config;
} }
public long getMaxObjectSizeLimit() {
return config.getMaxObjectSizeLimit();
}
/** Get the sections that pertain only to this project. */ /** Get the sections that pertain only to this project. */
List<SectionMatcher> getLocalAccessSections() { List<SectionMatcher> getLocalAccessSections() {
List<SectionMatcher> sm = localAccessSections; List<SectionMatcher> sm = localAccessSections;

View File

@@ -94,7 +94,7 @@ final class Receive extends AbstractGitCommand {
final ReceivePack rp = receive.getReceivePack(); final ReceivePack rp = receive.getReceivePack();
rp.setRefLogIdent(currentUser.newRefLogIdent()); rp.setRefLogIdent(currentUser.newRefLogIdent());
rp.setTimeout(config.getTimeout()); rp.setTimeout(config.getTimeout());
rp.setMaxObjectSizeLimit(config.getMaxObjectSizeLimit()); rp.setMaxObjectSizeLimit(getMaxObjectSizeLimit());
try { try {
receive.advertiseHistory(); receive.advertiseHistory();
rp.receive(in, out, err); 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);
}
}
} }