Use string constants for refs/*, refs/heads/, refs/tags/
These are fairly well-known strings, used often enough in the code, so use constants that correspond to them. Change-Id: I00bc6a2034ab3041816b6cc1492b7f2117d1952f Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -114,25 +114,25 @@ class AddRefRight extends Handler<ProjectDetail> {
|
|||||||
if (categoryId.equals(ApprovalCategory.SUBMIT)
|
if (categoryId.equals(ApprovalCategory.SUBMIT)
|
||||||
|| categoryId.equals(ApprovalCategory.PUSH_HEAD)) {
|
|| categoryId.equals(ApprovalCategory.PUSH_HEAD)) {
|
||||||
// Explicitly related to a branch head.
|
// Explicitly related to a branch head.
|
||||||
refPattern = "refs/heads/*";
|
refPattern = Constants.R_HEADS + "*";
|
||||||
|
|
||||||
} else if (!at.getCategory().isAction()) {
|
} else if (!at.getCategory().isAction()) {
|
||||||
// Non actions are approval votes on a change, assume these apply
|
// Non actions are approval votes on a change, assume these apply
|
||||||
// to branch heads only.
|
// to branch heads only.
|
||||||
refPattern = "refs/heads/*";
|
refPattern = Constants.R_HEADS + "*";
|
||||||
|
|
||||||
} else if (categoryId.equals(ApprovalCategory.PUSH_TAG)) {
|
} else if (categoryId.equals(ApprovalCategory.PUSH_TAG)) {
|
||||||
// Explicitly related to the tag namespace.
|
// Explicitly related to the tag namespace.
|
||||||
refPattern = "refs/tags/*";
|
refPattern = Constants.R_TAGS + "*";
|
||||||
|
|
||||||
} else if (categoryId.equals(ApprovalCategory.READ)
|
} else if (categoryId.equals(ApprovalCategory.READ)
|
||||||
|| categoryId.equals(ApprovalCategory.OWN)) {
|
|| categoryId.equals(ApprovalCategory.OWN)) {
|
||||||
// Currently these are project-wide rights, so apply that way.
|
// Currently these are project-wide rights, so apply that way.
|
||||||
refPattern = "refs/*";
|
refPattern = RefRight.ALL;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Assume project wide for the default.
|
// Assume project wide for the default.
|
||||||
refPattern = "refs/*";
|
refPattern = RefRight.ALL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (refPattern.startsWith("/")) {
|
while (refPattern.startsWith("/")) {
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ import java.util.Comparator;
|
|||||||
|
|
||||||
/** Grant to use an {@link ApprovalCategory} in the scope of a git ref. */
|
/** Grant to use an {@link ApprovalCategory} in the scope of a git ref. */
|
||||||
public final class RefRight {
|
public final class RefRight {
|
||||||
|
/** Pattern that matches all references in a project. */
|
||||||
|
public static final String ALL = "refs/*";
|
||||||
|
|
||||||
public static class RefPattern extends
|
public static class RefPattern extends
|
||||||
StringKey<com.google.gwtorm.client.Key<?>> {
|
StringKey<com.google.gwtorm.client.Key<?>> {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ public class SchemaCreator {
|
|||||||
c.approvalCategories().insert(Collections.singleton(cat));
|
c.approvalCategories().insert(Collections.singleton(cat));
|
||||||
c.approvalCategoryValues().insert(vals);
|
c.approvalCategoryValues().insert(vals);
|
||||||
|
|
||||||
final RefRight.RefPattern pattern = new RefRight.RefPattern("refs/*");
|
final RefRight.RefPattern pattern = new RefRight.RefPattern(RefRight.ALL);
|
||||||
{
|
{
|
||||||
final RefRight read =
|
final RefRight read =
|
||||||
new RefRight(new RefRight.Key(DEFAULT_WILD_NAME, pattern,
|
new RefRight(new RefRight.Key(DEFAULT_WILD_NAME, pattern,
|
||||||
@@ -327,8 +327,8 @@ public class SchemaCreator {
|
|||||||
|
|
||||||
RefRight right =
|
RefRight right =
|
||||||
new RefRight(new RefRight.Key(sConfig.wildProjectName,
|
new RefRight(new RefRight.Key(sConfig.wildProjectName,
|
||||||
new RefRight.RefPattern("refs/*"), ApprovalCategory.FORGE_IDENTITY,
|
new RefRight.RefPattern(RefRight.ALL),
|
||||||
sConfig.registeredGroupId));
|
ApprovalCategory.FORGE_IDENTITY, sConfig.registeredGroupId));
|
||||||
right.setMinValue(ApprovalCategory.FORGE_AUTHOR);
|
right.setMinValue(ApprovalCategory.FORGE_AUTHOR);
|
||||||
right.setMaxValue(ApprovalCategory.FORGE_AUTHOR);
|
right.setMaxValue(ApprovalCategory.FORGE_AUTHOR);
|
||||||
c.refRights().insert(Collections.singleton(right));
|
c.refRights().insert(Collections.singleton(right));
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import com.google.gwtorm.jdbc.JdbcSchema;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.lib.Constants;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
@@ -85,20 +87,20 @@ class Schema_25 extends SchemaVersion {
|
|||||||
|| category.equals(ApprovalCategory.PUSH_HEAD)
|
|| category.equals(ApprovalCategory.PUSH_HEAD)
|
||||||
|| nonActions.contains(category)) {
|
|| nonActions.contains(category)) {
|
||||||
// Explicitly related to a branch head.
|
// Explicitly related to a branch head.
|
||||||
ref = new RefRight.RefPattern("refs/heads/*");
|
ref = new RefRight.RefPattern(Constants.R_HEADS + "*");
|
||||||
|
|
||||||
} else if (category.equals(ApprovalCategory.PUSH_TAG)) {
|
} else if (category.equals(ApprovalCategory.PUSH_TAG)) {
|
||||||
// Explicitly related to the tag namespace.
|
// Explicitly related to the tag namespace.
|
||||||
ref = new RefRight.RefPattern("refs/tags/*");
|
ref = new RefRight.RefPattern(Constants.R_TAGS + "/*");
|
||||||
|
|
||||||
} else if (category.equals(ApprovalCategory.READ)
|
} else if (category.equals(ApprovalCategory.READ)
|
||||||
|| category.equals(ApprovalCategory.OWN)) {
|
|| category.equals(ApprovalCategory.OWN)) {
|
||||||
// Currently these are project-wide rights, so apply that way.
|
// Currently these are project-wide rights, so apply that way.
|
||||||
ref = new RefRight.RefPattern("refs/*");
|
ref = new RefRight.RefPattern(RefRight.ALL);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Assume project wide for the default.
|
// Assume project wide for the default.
|
||||||
ref = new RefRight.RefPattern("refs/*");
|
ref = new RefRight.RefPattern(RefRight.ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
RefRight.Key key = new RefRight.Key(project, ref, category, group);
|
RefRight.Key key = new RefRight.Key(project, ref, category, group);
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ class Schema_28 extends SchemaVersion {
|
|||||||
|
|
||||||
RefRight right =
|
RefRight right =
|
||||||
new RefRight(new RefRight.Key(sConfig.wildProjectName,
|
new RefRight(new RefRight.Key(sConfig.wildProjectName,
|
||||||
new RefRight.RefPattern("refs/*"), ApprovalCategory.FORGE_IDENTITY,
|
new RefRight.RefPattern(RefRight.ALL),
|
||||||
sConfig.registeredGroupId));
|
ApprovalCategory.FORGE_IDENTITY, sConfig.registeredGroupId));
|
||||||
right.setMinValue(ApprovalCategory.FORGE_AUTHOR);
|
right.setMinValue(ApprovalCategory.FORGE_AUTHOR);
|
||||||
right.setMaxValue(ApprovalCategory.FORGE_AUTHOR);
|
right.setMaxValue(ApprovalCategory.FORGE_AUTHOR);
|
||||||
c.refRights().insert(Collections.singleton(right));
|
c.refRights().insert(Collections.singleton(right));
|
||||||
|
|||||||
@@ -115,8 +115,8 @@ final class AdminCreateProject extends BaseCommand {
|
|||||||
final Project.NameKey newProjectNameKey = new Project.NameKey(projectName);
|
final Project.NameKey newProjectNameKey = new Project.NameKey(projectName);
|
||||||
|
|
||||||
final RefRight.Key prk =
|
final RefRight.Key prk =
|
||||||
new RefRight.Key(newProjectNameKey, new RefRight.RefPattern("refs/*"),
|
new RefRight.Key(newProjectNameKey, new RefRight.RefPattern(
|
||||||
ApprovalCategory.OWN, ownerId);
|
RefRight.ALL), ApprovalCategory.OWN, ownerId);
|
||||||
final RefRight pr = new RefRight(prk);
|
final RefRight pr = new RefRight(prk);
|
||||||
pr.setMaxValue((short) 1);
|
pr.setMaxValue((short) 1);
|
||||||
pr.setMinValue((short) 1);
|
pr.setMinValue((short) 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user