Set maxObjectSizeLimit from create-project and set-project SSH commands

Change-Id: Ic86015efec549711ab10ae363784746985772d23
This commit is contained in:
Sasa Zivkov 2013-07-01 15:01:59 +02:00
parent 5a708a8b45
commit a1ec941227
8 changed files with 71 additions and 1 deletions

View File

@ -21,6 +21,7 @@ SYNOPSIS
[--require-change-id | --id] [--require-change-id | --id]
[[--branch <REF> | -b <REF>] ...] [[--branch <REF> | -b <REF>] ...]
[--empty-commit] [--empty-commit]
[--max-object-size-limit <N>]
{ <NAME> | --name <NAME> } { <NAME> | --name <NAME> }
DESCRIPTION DESCRIPTION
@ -144,6 +145,15 @@ link:project-setup.html#submit_type[Change Submit Actions].
Creates an initial empty commit for the Git repository of the Creates an initial empty commit for the Git repository of the
project that is newly created. project that is newly created.
--max-object-size-limit::
Define maximum Git object size for this project. Pushes containing an
object larger than this limit will be rejected. This can be used to
further limit the global
link:config-gerrit.html#receive.maxObjectSizeLimit[receive.maxObjectSizeLimit]
and cannot be used to increase that globally set limit.
+
Common unit suffixes of 'k', 'm', or 'g' are supported.
EXAMPLES EXAMPLES
-------- --------

View File

@ -16,6 +16,7 @@ SYNOPSIS
[--content-merge <true|false|inherit>] [--content-merge <true|false|inherit>]
[--change-id <true|false|inherit>] [--change-id <true|false|inherit>]
[--project-state <STATE> | --ps <STATE>] [--project-state <STATE> | --ps <STATE>]
[--max-object-size-limit <N>]
<NAME> <NAME>
DESCRIPTION DESCRIPTION
@ -93,6 +94,15 @@ link:project-setup.html#submit_type[Change Submit Actions].
is granted, but all modification operations are disabled. is granted, but all modification operations are disabled.
* HIDDEN: the project is not visible for those who are not owners * HIDDEN: the project is not visible for those who are not owners
--max-object-size-limit::
Define maximum Git object size for this project. Pushes containing an
object larger than this limit will be rejected. This can be used to
further limit the global
link:config-gerrit.html#receive.maxObjectSizeLimit[receive.maxObjectSizeLimit]
and cannot be used to increase that globally set limit.
+
Common unit suffixes of 'k', 'm', or 'g' are supported.
EXAMPLES EXAMPLES
-------- --------
Change project `example` to be hidden, require change id, don't use content merge Change project `example` to be hidden, require change id, don't use content merge
@ -105,4 +115,4 @@ and use 'merge if necessary' as merge strategy:
GERRIT GERRIT
------ ------
Part of link:index.html[Gerrit Code Review] Part of link:index.html[Gerrit Code Review]

View File

@ -107,6 +107,8 @@ public final class Project {
protected InheritableBoolean requireChangeID; protected InheritableBoolean requireChangeID;
protected String maxObjectSizeLimit;
protected InheritableBoolean useContentMerge; protected InheritableBoolean useContentMerge;
protected String defaultDashboardId; protected String defaultDashboardId;
@ -160,6 +162,10 @@ public final class Project {
return requireChangeID; return requireChangeID;
} }
public String getMaxObjectSizeLimit() {
return maxObjectSizeLimit;
}
public void setUseContributorAgreements(final InheritableBoolean u) { public void setUseContributorAgreements(final InheritableBoolean u) {
useContributorAgreements = u; useContributorAgreements = u;
} }
@ -176,6 +182,10 @@ public final class Project {
requireChangeID = cid; requireChangeID = cid;
} }
public void setMaxObjectSizeLimit(final String limit) {
maxObjectSizeLimit = limit;
}
public SubmitType getSubmitType() { public SubmitType getSubmitType() {
return submitType; return submitType;
} }
@ -224,6 +234,7 @@ public final class Project {
requireChangeID = update.requireChangeID; requireChangeID = update.requireChangeID;
submitType = update.submitType; submitType = update.submitType;
state = update.state; state = update.state;
maxObjectSizeLimit = update.maxObjectSizeLimit;
} }
/** /**

View File

@ -382,6 +382,7 @@ public class ProjectConfig extends VersionedMetaData {
p.setUseContributorAgreements(getEnum(rc, RECEIVE, null, KEY_REQUIRE_CONTRIBUTOR_AGREEMENT, Project.InheritableBoolean.INHERIT)); p.setUseContributorAgreements(getEnum(rc, RECEIVE, null, KEY_REQUIRE_CONTRIBUTOR_AGREEMENT, Project.InheritableBoolean.INHERIT));
p.setUseSignedOffBy(getEnum(rc, RECEIVE, null, KEY_REQUIRE_SIGNED_OFF_BY, Project.InheritableBoolean.INHERIT)); p.setUseSignedOffBy(getEnum(rc, RECEIVE, null, KEY_REQUIRE_SIGNED_OFF_BY, Project.InheritableBoolean.INHERIT));
p.setRequireChangeID(getEnum(rc, RECEIVE, null, KEY_REQUIRE_CHANGE_ID, Project.InheritableBoolean.INHERIT)); p.setRequireChangeID(getEnum(rc, RECEIVE, null, KEY_REQUIRE_CHANGE_ID, Project.InheritableBoolean.INHERIT));
p.setMaxObjectSizeLimit(rc.getString(RECEIVE, null, KEY_MAX_OBJECT_SIZE_LIMIT));
p.setSubmitType(getEnum(rc, SUBMIT, null, KEY_ACTION, defaultSubmitAction)); p.setSubmitType(getEnum(rc, SUBMIT, null, KEY_ACTION, defaultSubmitAction));
p.setUseContentMerge(getEnum(rc, SUBMIT, null, KEY_MERGE_CONTENT, Project.InheritableBoolean.INHERIT)); p.setUseContentMerge(getEnum(rc, SUBMIT, null, KEY_MERGE_CONTENT, Project.InheritableBoolean.INHERIT));
@ -723,6 +724,7 @@ public class ProjectConfig extends VersionedMetaData {
set(rc, RECEIVE, null, KEY_REQUIRE_CONTRIBUTOR_AGREEMENT, p.getUseContributorAgreements(), Project.InheritableBoolean.INHERIT); set(rc, RECEIVE, null, KEY_REQUIRE_CONTRIBUTOR_AGREEMENT, p.getUseContributorAgreements(), Project.InheritableBoolean.INHERIT);
set(rc, RECEIVE, null, KEY_REQUIRE_SIGNED_OFF_BY, p.getUseSignedOffBy(), Project.InheritableBoolean.INHERIT); set(rc, RECEIVE, null, KEY_REQUIRE_SIGNED_OFF_BY, p.getUseSignedOffBy(), Project.InheritableBoolean.INHERIT);
set(rc, RECEIVE, null, KEY_REQUIRE_CHANGE_ID, p.getRequireChangeID(), Project.InheritableBoolean.INHERIT); set(rc, RECEIVE, null, KEY_REQUIRE_CHANGE_ID, p.getRequireChangeID(), Project.InheritableBoolean.INHERIT);
set(rc, RECEIVE, null, KEY_MAX_OBJECT_SIZE_LIMIT, validMaxObjectSizeLimit(p.getMaxObjectSizeLimit()));
set(rc, SUBMIT, null, KEY_ACTION, p.getSubmitType(), defaultSubmitAction); set(rc, SUBMIT, null, KEY_ACTION, p.getSubmitType(), defaultSubmitAction);
set(rc, SUBMIT, null, KEY_MERGE_CONTENT, p.getUseContentMerge(), Project.InheritableBoolean.INHERIT); set(rc, SUBMIT, null, KEY_MERGE_CONTENT, p.getUseContentMerge(), Project.InheritableBoolean.INHERIT);
@ -744,6 +746,31 @@ public class ProjectConfig extends VersionedMetaData {
saveGroupList(); saveGroupList();
} }
private static final String validMaxObjectSizeLimit(String value)
throws ConfigInvalidException {
if (value == null) {
return null;
}
Config cfg = new Config();
cfg.fromText("[s]\nn=" + value);
try {
long s = cfg.getLong("s", "n", 0);
if (s < 0) {
throw new ConfigInvalidException(String.format(
"Negative value '%s' not allowed as %s", value,
KEY_MAX_OBJECT_SIZE_LIMIT));
}
if (s == 0) {
// return null for the default so that it is not persisted
return null;
}
return value;
} catch (IllegalArgumentException e) {
throw new ConfigInvalidException(
String.format("Value '%s' not parseable as a Long", value), e);
}
}
private void saveAccountsSection(Config rc, Set<AccountGroup.UUID> keepGroups) { private void saveAccountsSection(Config rc, Set<AccountGroup.UUID> keepGroups) {
if (accountsSection != null) { if (accountsSection != null) {
rc.setStringList(ACCOUNTS, null, KEY_SAME_GROUP_VISIBILITY, rc.setStringList(ACCOUNTS, null, KEY_SAME_GROUP_VISIBILITY,

View File

@ -35,6 +35,7 @@ public class CreateProjectArgs {
public InheritableBoolean contentMerge; public InheritableBoolean contentMerge;
public InheritableBoolean changeIdRequired; public InheritableBoolean changeIdRequired;
public boolean createEmptyCommit; public boolean createEmptyCommit;
public String maxObjectSizeLimit;
public CreateProjectArgs() { public CreateProjectArgs() {
contributorAgreements = InheritableBoolean.INHERIT; contributorAgreements = InheritableBoolean.INHERIT;

View File

@ -181,6 +181,7 @@ public class PerformCreateProject {
newProject.setUseSignedOffBy(createProjectArgs.signedOffBy); newProject.setUseSignedOffBy(createProjectArgs.signedOffBy);
newProject.setUseContentMerge(createProjectArgs.contentMerge); newProject.setUseContentMerge(createProjectArgs.contentMerge);
newProject.setRequireChangeID(createProjectArgs.changeIdRequired); newProject.setRequireChangeID(createProjectArgs.changeIdRequired);
newProject.setMaxObjectSizeLimit(createProjectArgs.maxObjectSizeLimit);
if (createProjectArgs.newParent != null) { if (createProjectArgs.newParent != null) {
newProject.setParentName(createProjectArgs.newParent.getProject() newProject.setParentName(createProjectArgs.newParent.getProject()
.getNameKey()); .getNameKey());

View File

@ -106,6 +106,9 @@ final class CreateProjectCommand extends SshCommand {
@Option(name = "--empty-commit", usage = "to create initial empty commit") @Option(name = "--empty-commit", usage = "to create initial empty commit")
private boolean createEmptyCommit; private boolean createEmptyCommit;
@Option(name = "--max-object-size-limit", usage = "max Git object size for this project")
private String maxObjectSizeLimit;
private String projectName; private String projectName;
@Argument(index = 0, metaVar = "NAME", usage = "name of project to be created") @Argument(index = 0, metaVar = "NAME", usage = "name of project to be created")
@ -143,6 +146,7 @@ final class CreateProjectCommand extends SshCommand {
args.changeIdRequired = requireChangeID; args.changeIdRequired = requireChangeID;
args.branch = branch; args.branch = branch;
args.createEmptyCommit = createEmptyCommit; args.createEmptyCommit = createEmptyCommit;
args.maxObjectSizeLimit = maxObjectSizeLimit;
final PerformCreateProject createProject = factory.create(args); final PerformCreateProject createProject = factory.create(args);
createProject.createProject(); createProject.createProject();

View File

@ -108,6 +108,9 @@ final class SetProjectCommand extends SshCommand {
@Option(name = "--project-state", aliases = {"--ps"}, usage = "project's visibility state") @Option(name = "--project-state", aliases = {"--ps"}, usage = "project's visibility state")
private State state; private State state;
@Option(name = "--max-object-size-limit", usage = "max Git object size for this project")
private String maxObjectSizeLimit;
@Inject @Inject
private MetaDataUpdate.User metaDataUpdateFactory; private MetaDataUpdate.User metaDataUpdateFactory;
@ -148,6 +151,9 @@ final class SetProjectCommand extends SshCommand {
if (state != null) { if (state != null) {
project.setState(state); project.setState(state);
} }
if (maxObjectSizeLimit != null) {
project.setMaxObjectSizeLimit(maxObjectSizeLimit);
}
md.setMessage("Project settings updated"); md.setMessage("Project settings updated");
config.commit(md); config.commit(md);
} finally { } finally {