Move "refs/..." constants to a RefNames class

This class lives in gerrit-reviewdb because "refs/changes/" needs to be
referenced from PatchSet in reviewdb/client (and other UI classes).

Rename constants to all use REFS_* instead of being inconsistent.

Change-Id: I76e6ee7e63a4549b51a43698fb50b54a19dabfc6
This commit is contained in:
Dave Borowitz 2013-12-11 08:55:24 -08:00
parent 2f7cb5997f
commit 31b599b40f
40 changed files with 150 additions and 105 deletions

View File

@ -16,7 +16,6 @@ package com.google.gerrit.acceptance.rest.project;
import static com.google.gerrit.acceptance.rest.project.ProjectAssert.assertProjectInfo;
import static com.google.gerrit.acceptance.rest.project.ProjectAssert.assertProjectOwners;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@ -30,6 +29,7 @@ import com.google.gerrit.acceptance.RestSession;
import com.google.gerrit.acceptance.TestAccount;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
import com.google.gerrit.reviewdb.client.Project.SubmitType;
import com.google.gerrit.server.account.GroupCache;
@ -180,7 +180,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
ProjectInput in = new ProjectInput();
in.permissions_only = true;
session.put("/projects/" + newProjectName, in);
assertHead(newProjectName, GitRepositoryManager.REF_CONFIG);
assertHead(newProjectName, RefNames.REFS_CONFIG);
}
@Test

View File

@ -27,9 +27,9 @@ import com.google.gerrit.acceptance.SshSession;
import com.google.gerrit.acceptance.TestAccount;
import com.google.gerrit.acceptance.git.PushOneCommit;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.config.AllProjectsNameProvider;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState;
import com.google.gwtorm.server.SchemaFactory;
@ -73,7 +73,7 @@ public class ProjectLevelConfigIT extends AbstractDaemonTest {
project = "p";
createProject(sshSession, project, null, true);
git = cloneProject(sshSession.getUrl() + "/" + project);
fetch(git, GitRepositoryManager.REF_CONFIG + ":refs/heads/config");
fetch(git, RefNames.REFS_CONFIG + ":refs/heads/config");
checkout(git, "refs/heads/config");
db = reviewDbProvider.open();
@ -93,7 +93,7 @@ public class ProjectLevelConfigIT extends AbstractDaemonTest {
PushOneCommit push =
new PushOneCommit(db, admin.getIdent(), "Create Project Level Config",
configName, cfg.toText());
push.to(git, GitRepositoryManager.REF_CONFIG);
push.to(git, RefNames.REFS_CONFIG);
ProjectState state = projectCache.get(new Project.NameKey(project));
assertEquals(cfg.toText(), state.getConfig(configName).get().toText());
@ -117,19 +117,19 @@ public class ProjectLevelConfigIT extends AbstractDaemonTest {
Git parentGit =
cloneProject(sshSession.getUrl() + "/" + allProjects.get().get(), false);
fetch(parentGit, GitRepositoryManager.REF_CONFIG + ":refs/heads/config");
fetch(parentGit, RefNames.REFS_CONFIG + ":refs/heads/config");
checkout(parentGit, "refs/heads/config");
PushOneCommit push =
new PushOneCommit(db, admin.getIdent(), "Create Project Level Config",
configName, parentCfg.toText());
push.to(parentGit, GitRepositoryManager.REF_CONFIG);
push.to(parentGit, RefNames.REFS_CONFIG);
Config cfg = new Config();
cfg.setString("s1", null, "k1", "childValue1");
cfg.setString("s2", "ss", "k3", "childValue2");
push = new PushOneCommit(db, admin.getIdent(), "Create Project Level Config",
configName, cfg.toText());
push.to(git, GitRepositoryManager.REF_CONFIG);
push.to(git, RefNames.REFS_CONFIG);
ProjectState state = projectCache.get(new Project.NameKey(project));

View File

@ -23,6 +23,7 @@ import com.google.gerrit.common.data.AccessSection;
import com.google.gerrit.common.data.ProjectAccess;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Style.Display;
@ -125,7 +126,7 @@ public class ProjectAccessEditor extends Composite implements
history.getStyle().setDisplay(Display.BLOCK);
gitweb.setText(c.getLinkName());
gitweb.setHref(c.toFileHistory(new Branch.NameKey(value.getProjectName(),
"refs/meta/config"), "project.config"));
RefNames.REFS_CONFIG), "project.config"));
} else {
history.getStyle().setDisplay(Display.NONE);
}

View File

@ -34,6 +34,7 @@ import com.google.gerrit.client.ui.OnEditEnabler;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
@ -394,7 +395,7 @@ public class ProjectBranchesScreen extends ProjectScreen {
final FlexCellFormatter fmt = table.getFlexCellFormatter();
String iconCellStyle = Gerrit.RESOURCES.css().iconCell();
String dataCellStyle = Gerrit.RESOURCES.css().dataCell();
if ("refs/meta/config".equals(k.getShortName())
if (RefNames.REFS_CONFIG.equals(k.getShortName())
|| "HEAD".equals(k.getShortName())) {
iconCellStyle = Gerrit.RESOURCES.css().specialBranchIconCell();
dataCellStyle = Gerrit.RESOURCES.css().specialBranchDataCell();

View File

@ -27,10 +27,10 @@ import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.httpd.rpc.Handler;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.account.GroupBackend;
import com.google.gerrit.server.account.GroupControl;
import com.google.gerrit.server.config.AllProjectsName;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.MetaDataUpdate;
import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.project.NoSuchProjectException;
@ -113,7 +113,7 @@ class ProjectAccessFactory extends Handler<ProjectAccess> {
md.close();
}
final RefControl metaConfigControl = pc.controlForRef(GitRepositoryManager.REF_CONFIG);
final RefControl metaConfigControl = pc.controlForRef(RefNames.REFS_CONFIG);
List<AccessSection> local = new ArrayList<AccessSection>();
Set<String> ownerOf = new HashSet<String>();
Map<AccountGroup.UUID, Boolean> visibleGroups = new HashMap<>();

View File

@ -26,6 +26,7 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchSetAncestor;
import com.google.gerrit.reviewdb.client.PatchSetInfo;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.RevId;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ChangeUtil;
@ -35,7 +36,6 @@ import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.change.MergeabilityChecker;
import com.google.gerrit.server.change.PostReviewers;
import com.google.gerrit.server.config.AllProjectsNameProvider;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.MetaDataUpdate;
import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.group.SystemGroupBackend;
@ -134,7 +134,7 @@ public class ReviewProjectAccess extends ProjectAccessHandler<Change.Id> {
user.getAccountId(),
new Branch.NameKey(
config.getProject().getNameKey(),
GitRepositoryManager.REF_CONFIG),
RefNames.REFS_CONFIG),
TimeUtil.nowTs());
ps.setCreatedOn(change.getCreatedOn());

View File

@ -18,6 +18,7 @@ java_library(
deps = [
'//gerrit-common:annotations',
'//gerrit-common:server',
'//gerrit-reviewdb:server',
'//gerrit-server:server',
'//lib:guava',
'//lib/guice:guice',

View File

@ -14,8 +14,8 @@
package com.google.gerrit.pgm.init;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.git.VersionedMetaData;
import com.google.inject.Inject;
@ -59,7 +59,7 @@ public class AllProjectsConfig extends VersionedMetaData {
@Override
protected String getRefName() {
return GitRepositoryManager.REF_CONFIG;
return RefNames.REFS_CONFIG;
}
public Config load() throws IOException, ConfigInvalidException {

View File

@ -14,6 +14,8 @@
package com.google.gerrit.reviewdb.client;
import static com.google.gerrit.reviewdb.client.RefNames.REFS_CHANGES;
import com.google.gwtorm.client.Column;
import com.google.gwtorm.client.IntKey;
@ -21,8 +23,6 @@ import java.sql.Timestamp;
/** A single revision of a {@link Change}. */
public final class PatchSet {
private static final String REFS_CHANGES = "refs/changes/";
/** Is the reference name a change reference? */
public static boolean isRef(final String name) {
if (name == null || !name.startsWith(REFS_CHANGES)) {

View File

@ -0,0 +1,44 @@
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.reviewdb.client;
/** Constants and utilities for Gerrit-specific ref names. */
public class RefNames {
public static final String REFS_CHANGES = "refs/changes/";
/** Note tree listing commits we refuse {@code refs/meta/reject-commits} */
public static final String REFS_REJECT_COMMITS = "refs/meta/reject-commits";
/** Configuration settings for a project {@code refs/meta/config} */
public static final String REFS_CONFIG = "refs/meta/config";
/** Configurations of project-specific dashboards (canned search queries). */
public static final String REFS_DASHBOARDS = "refs/meta/dashboards/";
/**
* Prefix applied to merge commit base nodes.
* <p>
* References in this directory should take the form
* {@code refs/cache-automerge/xx/yyyy...} where xx is
* the first two digits of the merge commit's object
* name, and yyyyy... is the remaining 38. The reference
* should point to a treeish that is the automatic merge
* result of the merge commit's parents.
*/
public static final String REFS_CACHE_AUTOMERGE = "refs/cache-automerge/";
private RefNames() {
}
}

View File

@ -15,9 +15,9 @@
package com.google.gerrit.rules;
import com.google.gerrit.common.Version;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.util.TimeUtil;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@ -79,7 +79,7 @@ public class PrologCompiler implements Callable<PrologCompiler.Status> {
}
public Status call() throws IOException, CompileException {
ObjectId metaConfig = git.resolve(GitRepositoryManager.REF_CONFIG);
ObjectId metaConfig = git.resolve(RefNames.REFS_CONFIG);
if (metaConfig == null) {
return Status.NO_RULES;
}

View File

@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.git.GitRepositoryManager;
@ -66,7 +67,7 @@ import java.util.Map;
* <p>
* Rules are loaded from the {@code site_path/cache/rules/rules-SHA1.jar}, where
* {@code SHA1} is the SHA1 of the Prolog {@code rules.pl} in a project's
* {@link GitRepositoryManager#REF_CONFIG} branch.
* {@link RefNames#REFS_CONFIG} branch.
*/
@Singleton
public class RulesCache {

View File

@ -29,11 +29,11 @@ import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.extensions.restapi.TopLevelResource;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.account.GroupBackend;
import com.google.gerrit.server.account.GroupControl;
import com.google.gerrit.server.config.AllProjectsName;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.MetaDataUpdate;
import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.group.GroupJson;
@ -154,7 +154,7 @@ public class ListAccess implements RestReadView<TopLevelResource> {
public ProjectAccessInfo(ProjectControl pc, ProjectConfig config) {
final RefControl metaConfigControl =
pc.controlForRef(GitRepositoryManager.REF_CONFIG);
pc.controlForRef(RefNames.REFS_CONFIG);
local = Maps.newHashMap();
ownerOf = Sets.newHashSet();
Map<AccountGroup.UUID, Boolean> visibleGroups =

View File

@ -28,11 +28,11 @@ import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.change.Mergeable.MergeableInfo;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.MetaDataUpdate;
import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.git.WorkQueue.Executor;
@ -110,11 +110,11 @@ public class MergeabilityChecker implements GitReferenceUpdatedListener {
@Override
public void onGitReferenceUpdated(GitReferenceUpdatedListener.Event event) {
String ref = event.getRefName();
if (ref.startsWith(Constants.R_HEADS) || ref.equals(GitRepositoryManager.REF_CONFIG)) {
if (ref.startsWith(Constants.R_HEADS) || ref.equals(RefNames.REFS_CONFIG)) {
executor.submit(new BranchUpdateTask(schemaFactory,
new Project.NameKey(event.getProjectName()), ref));
}
if (ref.equals(GitRepositoryManager.REF_CONFIG)) {
if (ref.equals(RefNames.REFS_CONFIG)) {
Project.NameKey p = new Project.NameKey(event.getProjectName());
try {
ProjectConfig oldCfg = parseConfig(p, event.getOldObjectId());
@ -124,7 +124,7 @@ public class MergeabilityChecker implements GitReferenceUpdatedListener {
new ProjectUpdateTask(schemaFactory, p).call();
} catch (Exception e) {
String msg = "Failed to update mergeability flags for project " + p.get()
+ " on update of " + GitRepositoryManager.REF_CONFIG;
+ " on update of " + RefNames.REFS_CONFIG;
log.error(msg, e);
Throwables.propagateIfPossible(e);
throw new RuntimeException(msg, e);
@ -132,7 +132,7 @@ public class MergeabilityChecker implements GitReferenceUpdatedListener {
}
} catch (ConfigInvalidException | IOException e) {
String msg = "Failed to update mergeability flags for project " + p.get()
+ " on update of " + GitRepositoryManager.REF_CONFIG;
+ " on update of " + RefNames.REFS_CONFIG;
log.error(msg, e);
throw new RuntimeException(msg, e);
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.git;
import static com.google.gerrit.server.git.GitRepositoryManager.REF_REJECT_COMMITS;
import static com.google.gerrit.reviewdb.client.RefNames.REFS_REJECT_COMMITS;
import com.google.gerrit.common.errors.PermissionDeniedException;
import com.google.gerrit.reviewdb.client.Project;
@ -96,7 +96,7 @@ public class BanCommit {
NotesBranchUtil notesBranchUtil = notesBranchUtilFactory.create(project,
repo, inserter);
NoteMap newlyCreated =
notesBranchUtil.commitNewNotes(banCommitNotes, REF_REJECT_COMMITS,
notesBranchUtil.commitNewNotes(banCommitNotes, REFS_REJECT_COMMITS,
createPersonIdent(), buildCommitMessage(commitsToBan, reason));
for (Note n : banCommitNotes) {

View File

@ -19,6 +19,7 @@ import com.google.common.cache.LoadingCache;
import com.google.gerrit.extensions.events.GitReferenceUpdatedListener;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.cache.CacheModule;
import com.google.gwtorm.server.SchemaFactory;
@ -72,7 +73,7 @@ public class ChangeCache implements GitReferenceUpdatedListener {
@Override
public void onGitReferenceUpdated(GitReferenceUpdatedListener.Event event) {
if (event.getRefName().startsWith("refs/changes/")) {
if (event.getRefName().startsWith(RefNames.REFS_CHANGES)) {
cache.invalidate(new Project.NameKey(event.getProjectName()));
}
}

View File

@ -31,27 +31,6 @@ import java.util.SortedSet;
* environment.
*/
public interface GitRepositoryManager {
/** Note tree listing commits we refuse {@code refs/meta/reject-commits} */
public static final String REF_REJECT_COMMITS = "refs/meta/reject-commits";
/** Configuration settings for a project {@code refs/meta/config} */
public static final String REF_CONFIG = "refs/meta/config";
/** Configurations of project-specific dashboards (canned search queries). */
public static String REFS_DASHBOARDS = "refs/meta/dashboards/";
/**
* Prefix applied to merge commit base nodes.
* <p>
* References in this directory should take the form
* {@code refs/cache-automerge/xx/yyyy...} where xx is
* the first two digits of the merge commit's object
* name, and yyyyy... is the remaining 38. The reference
* should point to a treeish that is the automatic merge
* result of the merge commit's parents.
*/
public static final String REFS_CACHE_AUTOMERGE = "refs/cache-automerge/";
/**
* Get (or open) a repository by name.
*

View File

@ -39,6 +39,7 @@ import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.Project.SubmitType;
import com.google.gerrit.reviewdb.client.RevId;
import com.google.gerrit.reviewdb.server.ReviewDb;
@ -579,7 +580,7 @@ public class MergeOp {
}
if (mergeTip != null && (branchTip == null || branchTip != mergeTip)) {
if (GitRepositoryManager.REF_CONFIG.equals(branchUpdate.getName())) {
if (RefNames.REFS_CONFIG.equals(branchUpdate.getName())) {
try {
ProjectConfig cfg =
new ProjectConfig(destProject.getProject().getNameKey());
@ -606,7 +607,7 @@ public class MergeOp {
mergeTip);
}
if (GitRepositoryManager.REF_CONFIG.equals(branchUpdate.getName())) {
if (RefNames.REFS_CONFIG.equals(branchUpdate.getName())) {
projectCache.evict(destProject.getProject());
destProject = projectCache.get(destProject.getProject().getNameKey());
repoManager.setProjectDescription(

View File

@ -40,6 +40,7 @@ import com.google.gerrit.common.data.PermissionRule;
import com.google.gerrit.common.data.PermissionRule.Action;
import com.google.gerrit.common.data.RefConfigSection;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.AccountProjectWatch.NotifyType;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.Project.State;
@ -370,7 +371,7 @@ public class ProjectConfig extends VersionedMetaData {
@Override
protected String getRefName() {
return GitRepositoryManager.REF_CONFIG;
return RefNames.REFS_CONFIG;
}
@Override

View File

@ -15,6 +15,7 @@
package com.google.gerrit.server.git;
import com.google.common.collect.Iterables;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.project.ProjectState;
import org.eclipse.jgit.errors.ConfigInvalidException;
@ -38,7 +39,7 @@ public class ProjectLevelConfig extends VersionedMetaData {
@Override
protected String getRefName() {
return GitRepositoryManager.REF_CONFIG;
return RefNames.REFS_CONFIG;
}
@Override

View File

@ -14,6 +14,7 @@
package com.google.gerrit.server.git;
import static com.google.gerrit.reviewdb.client.RefNames.REFS_CHANGES;
import static com.google.gerrit.server.git.MultiProgressMonitor.UNKNOWN;
import static com.google.gerrit.server.mail.MailUtil.getRecipientsFromApprovals;
import static com.google.gerrit.server.mail.MailUtil.getRecipientsFromFooters;
@ -58,6 +59,7 @@ import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.client.PatchSetInfo;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.RevId;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ApprovalsUtil;
@ -156,8 +158,8 @@ public class ReceiveCommits {
private static final Logger log =
LoggerFactory.getLogger(ReceiveCommits.class);
public static final Pattern NEW_PATCHSET =
Pattern.compile("^refs/changes/(?:[0-9][0-9]/)?([1-9][0-9]*)(?:/new)?$");
public static final Pattern NEW_PATCHSET = Pattern.compile(
"^" + REFS_CHANGES + "(?:[0-9][0-9]/)?([1-9][0-9]*)(?:/new)?$");
private static final FooterKey CHANGE_ID = new FooterKey("Change-Id");
@ -168,12 +170,12 @@ public class ReceiveCommits {
private enum Error {
CONFIG_UPDATE("You are not allowed to perform this operation.\n"
+ "Configuration changes can only be pushed by project owners\n"
+ "who also have 'Push' rights on " + GitRepositoryManager.REF_CONFIG),
+ "who also have 'Push' rights on " + RefNames.REFS_CONFIG),
UPDATE("You are not allowed to perform this operation.\n"
+ "To push into this reference you need 'Push' rights."),
DELETE("You need 'Push' rights with the 'Force Push'\n"
+ "flag set to delete references."),
DELETE_CHANGES("Cannot delete from 'refs/changes'"),
DELETE_CHANGES("Cannot delete from '" + REFS_CHANGES + "'"),
CODE_REVIEW("You need 'Push' rights to upload code review requests.\n"
+ "Verify that you are pushing to the right branch.");
@ -397,8 +399,8 @@ public class ReceiveCommits {
Map<String, Ref> filteredRefs = Maps.newHashMapWithExpectedSize(refs.size());
for (Map.Entry<String, Ref> e : refs.entrySet()) {
String name = e.getKey();
if (!name.startsWith("refs/changes/")
&& !name.startsWith(GitRepositoryManager.REFS_CACHE_AUTOMERGE)) {
if (!name.startsWith(REFS_CHANGES)
&& !name.startsWith(RefNames.REFS_CACHE_AUTOMERGE)) {
filteredRefs.put(name, e.getValue());
}
}
@ -914,8 +916,8 @@ public class ReceiveCommits {
validateNewCommits(ctl, cmd);
batch.addCommand(cmd);
} else {
if (GitRepositoryManager.REF_CONFIG.equals(ctl.getRefName())) {
errors.put(Error.CONFIG_UPDATE, GitRepositoryManager.REF_CONFIG);
if (RefNames.REFS_CONFIG.equals(ctl.getRefName())) {
errors.put(Error.CONFIG_UPDATE, RefNames.REFS_CONFIG);
} else {
errors.put(Error.UPDATE, ctl.getRefName());
}
@ -944,13 +946,13 @@ public class ReceiveCommits {
private void parseDelete(final ReceiveCommand cmd) {
RefControl ctl = projectControl.controlForRef(cmd.getRefName());
if (ctl.getRefName().startsWith("refs/changes/")) {
if (ctl.getRefName().startsWith(REFS_CHANGES)) {
errors.put(Error.DELETE_CHANGES, ctl.getRefName());
reject(cmd, "cannot delete changes");
} else if (ctl.canDelete()) {
batch.addCommand(cmd);
} else {
if (GitRepositoryManager.REF_CONFIG.equals(ctl.getRefName())) {
if (RefNames.REFS_CONFIG.equals(ctl.getRefName())) {
reject(cmd, "cannot delete project configuration");
} else {
errors.put(Error.DELETE, ctl.getRefName());
@ -1222,7 +1224,7 @@ public class ReceiveCommits {
*/
private NoteMap loadRejectCommitsMap() throws IOException {
try {
Ref ref = repo.getRef(GitRepositoryManager.REF_REJECT_COMMITS);
Ref ref = repo.getRef(RefNames.REFS_REJECT_COMMITS);
if (ref == null) {
return NoteMap.newEmptyMap();
}
@ -1232,7 +1234,7 @@ public class ReceiveCommits {
return NoteMap.read(rw.getObjectReader(), map);
} catch (IOException badMap) {
throw new IOException("Cannot load "
+ GitRepositoryManager.REF_REJECT_COMMITS, badMap);
+ RefNames.REFS_REJECT_COMMITS, badMap);
}
}
@ -1424,7 +1426,7 @@ public class ReceiveCommits {
for (Ref ref : allRefs.values()) {
if (ref.getObjectId() == null) {
continue;
} else if (ref.getName().startsWith("refs/changes/")) {
} else if (ref.getName().startsWith(REFS_CHANGES)) {
existing.add(ref.getObjectId());
} else if (ref.getName().startsWith(R_HEADS)
|| (forRef != null && forRef.equals(ref.getName()))) {
@ -2057,7 +2059,7 @@ public class ReceiveCommits {
&& ctl.canUploadMerges()
&& !projectControl.getProjectState().isUseSignedOffBy()
&& Iterables.isEmpty(rejectCommits)
&& !GitRepositoryManager.REF_CONFIG.equals(ctl.getRefName())
&& !RefNames.REFS_CONFIG.equals(ctl.getRefName())
&& !(MagicBranch.isMagicBranch(cmd.getRefName())
|| NEW_PATCHSET.matcher(cmd.getRefName()).matches())) {
return;
@ -2233,7 +2235,7 @@ public class ReceiveCommits {
private SetMultimap<ObjectId, Ref> changeRefsById() throws IOException {
if (refsById == null) {
refsById = HashMultimap.create();
for (Ref r : repo.getRefDatabase().getRefs("refs/changes/").values()) {
for (Ref r : repo.getRefDatabase().getRefs(REFS_CHANGES).values()) {
if (PatchSet.isRef(r.getName())) {
refsById.put(r.getObjectId(), r);
}
@ -2340,6 +2342,6 @@ public class ReceiveCommits {
}
private static boolean isConfig(final ReceiveCommand cmd) {
return cmd.getRefName().equals(GitRepositoryManager.REF_CONFIG);
return cmd.getRefName().equals(RefNames.REFS_CONFIG);
}
}

View File

@ -21,6 +21,7 @@ import com.google.common.collect.Sets;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.util.MagicBranch;
import com.google.gwtorm.server.OrmException;
@ -164,8 +165,8 @@ public class ReceiveCommitsAdvertiseRefsHook implements AdvertiseRefsHook {
}
private static boolean skip(String name) {
return name.startsWith("refs/changes/")
|| name.startsWith(GitRepositoryManager.REFS_CACHE_AUTOMERGE)
return name.startsWith(RefNames.REFS_CHANGES)
|| name.startsWith(RefNames.REFS_CACHE_AUTOMERGE)
|| MagicBranch.isMagicBranch(name);
}
}

View File

@ -19,9 +19,11 @@ import com.google.common.collect.Maps;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.project.ProjectControl;
import com.google.gwtorm.server.OrmException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefDatabase;
@ -68,9 +70,9 @@ public class VisibleRefFilter extends AbstractAdvertiseRefsHook {
public Map<String, Ref> filter(Map<String, Ref> refs, boolean filterTagsSeperately) {
if (projectCtl.allRefsAreVisibleExcept(
ImmutableSet.of(GitRepositoryManager.REF_CONFIG))) {
ImmutableSet.of(RefNames.REFS_CONFIG))) {
Map<String, Ref> r = Maps.newHashMap(refs);
r.remove(GitRepositoryManager.REF_CONFIG);
r.remove(RefNames.REFS_CONFIG);
return r;
}
@ -79,7 +81,7 @@ public class VisibleRefFilter extends AbstractAdvertiseRefsHook {
final List<Ref> deferredTags = new ArrayList<Ref>();
for (Ref ref : refs.values()) {
if (ref.getName().startsWith(GitRepositoryManager.REFS_CACHE_AUTOMERGE)) {
if (ref.getName().startsWith(RefNames.REFS_CACHE_AUTOMERGE)) {
continue;
} else if (PatchSet.isRef(ref.getName())) {
// Reference to a patch set is visible if the change is visible.

View File

@ -18,12 +18,12 @@ import com.google.common.base.CharMatcher;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.events.CommitReceivedEvent;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.git.ReceiveCommits;
import com.google.gerrit.server.git.ValidationError;
@ -311,7 +311,7 @@ public class CommitValidators {
CommitReceivedEvent receiveEvent) throws CommitValidationException {
IdentifiedUser currentUser = (IdentifiedUser) refControl.getCurrentUser();
if (GitRepositoryManager.REF_CONFIG.equals(refControl.getRefName())) {
if (RefNames.REFS_CONFIG.equals(refControl.getRefName())) {
List<CommitValidationMessage> messages =
new LinkedList<CommitValidationMessage>();

View File

@ -22,12 +22,12 @@ import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.config.AllProjectsName;
import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.CommitMergeStatus;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState;
@ -96,7 +96,7 @@ public class MergeValidators {
final Branch.NameKey destBranch,
final PatchSet.Id patchSetId)
throws MergeValidationException {
if (GitRepositoryManager.REF_CONFIG.equals(destBranch.get())) {
if (RefNames.REFS_CONFIG.equals(destBranch.get())) {
final Project.NameKey newParent;
try {
ProjectConfig cfg =

View File

@ -18,6 +18,7 @@ package com.google.gerrit.server.patch;
import com.google.common.cache.CacheLoader;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.inject.Inject;
@ -249,7 +250,7 @@ public class PatchListLoader extends CacheLoader<PatchListKey, PatchList> {
public static RevTree automerge(Repository repo, RevWalk rw, RevCommit b,
boolean save) throws IOException {
String hash = b.name();
String refName = GitRepositoryManager.REFS_CACHE_AUTOMERGE
String refName = RefNames.REFS_CACHE_AUTOMERGE
+ hash.substring(0, 2)
+ "/"
+ hash.substring(2);

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.project;
import static com.google.gerrit.server.git.GitRepositoryManager.REFS_DASHBOARDS;
import static com.google.gerrit.reviewdb.client.RefNames.REFS_DASHBOARDS;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.project;
import static com.google.gerrit.server.git.GitRepositoryManager.REFS_DASHBOARDS;
import static com.google.gerrit.reviewdb.client.RefNames.REFS_DASHBOARDS;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;

View File

@ -18,6 +18,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.inject.Inject;
@ -115,7 +116,7 @@ public class ListBranches implements RestReadView<ProjectResource> {
if (refControl.isVisible()) {
if (ref.getName().startsWith(Constants.R_HEADS)) {
branches.add(createBranchInfo(ref, refControl, targets));
} else if (GitRepositoryManager.REF_CONFIG.equals(ref.getName())) {
} else if (RefNames.REFS_CONFIG.equals(ref.getName())) {
configBranch = createBranchInfo(ref, refControl, targets);
}
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.project;
import static com.google.gerrit.server.git.GitRepositoryManager.REFS_DASHBOARDS;
import static com.google.gerrit.reviewdb.client.RefNames.REFS_DASHBOARDS;
import com.google.common.collect.Lists;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;

View File

@ -26,6 +26,7 @@ import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.extensions.restapi.TopLevelResource;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.OutputFormat;
import com.google.gerrit.server.StringUtil;
@ -85,7 +86,7 @@ public class ListProjects implements RestReadView<TopLevelResource> {
Ref head = git.getRef(Constants.HEAD);
return head != null
&& head.isSymbolic()
&& GitRepositoryManager.REF_CONFIG.equals(head.getLeaf().getName());
&& RefNames.REFS_CONFIG.equals(head.getLeaf().getName());
}
},
ALL {

View File

@ -26,6 +26,7 @@ import com.google.gerrit.extensions.events.NewProjectCreatedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.Project.SubmitType;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.IdentifiedUser;
@ -109,7 +110,7 @@ public class PerformCreateProject {
final Project.NameKey nameKey = createProjectArgs.getProject();
try {
final String head =
createProjectArgs.permissionsOnly ? GitRepositoryManager.REF_CONFIG
createProjectArgs.permissionsOnly ? RefNames.REFS_CONFIG
: createProjectArgs.branch.get(0);
final Repository repo = repoManager.createRepository(nameKey);
try {

View File

@ -30,6 +30,7 @@ import com.google.gerrit.common.data.Permission;
import com.google.gerrit.common.data.PermissionRule;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
import com.google.gerrit.rules.PrologEnvironment;
import com.google.gerrit.rules.RulesCache;
@ -164,7 +165,7 @@ public class ProjectState {
try {
Repository git = gitMgr.openRepository(getProject().getNameKey());
try {
Ref ref = git.getRef(GitRepositoryManager.REF_CONFIG);
Ref ref = git.getRef(RefNames.REFS_CONFIG);
if (ref == null || ref.getObjectId() == null) {
return true;
}

View File

@ -23,10 +23,10 @@ import com.google.gerrit.common.data.PermissionRule;
import com.google.gerrit.common.data.RefConfigSection;
import com.google.gerrit.common.errors.InvalidNameException;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.InternalUser;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.group.SystemGroupBackend;
import dk.brics.automaton.RegExp;
@ -161,7 +161,7 @@ public class RefControl {
/** @return true if this user can submit patch sets to this ref */
public boolean canSubmit() {
if (GitRepositoryManager.REF_CONFIG.equals(refName)) {
if (RefNames.REFS_CONFIG.equals(refName)) {
// Always allow project owners to submit configuration changes.
// Submitting configuration changes modifies the access control
// rules. Allowing this to be done by a non-project-owner opens
@ -175,7 +175,7 @@ public class RefControl {
/** @return true if the user can update the reference as a fast-forward. */
public boolean canUpdate() {
if (GitRepositoryManager.REF_CONFIG.equals(refName)
if (RefNames.REFS_CONFIG.equals(refName)
&& !projectControl.isOwner()) {
// Pushing requires being at least project owner, in addition to push.
// Pushing configuration changes modifies the access control
@ -211,7 +211,7 @@ public class RefControl {
}
private boolean canPushWithForce() {
if (!canWrite() || (GitRepositoryManager.REF_CONFIG.equals(refName)
if (!canWrite() || (RefNames.REFS_CONFIG.equals(refName)
&& !projectControl.isOwner())) {
// Pushing requires being at least project owner, in addition to push.
// Pushing configuration changes modifies the access control
@ -294,7 +294,7 @@ public class RefControl {
* @return {@code true} if the user specified can delete a Git ref.
*/
public boolean canDelete() {
if (!canWrite() || (GitRepositoryManager.REF_CONFIG.equals(refName))) {
if (!canWrite() || (RefNames.REFS_CONFIG.equals(refName))) {
// Never allow removal of the refs/meta/config branch.
// Deleting the branch would destroy all Gerrit specific
// metadata about the project, including its access rules.

View File

@ -29,6 +29,7 @@ import com.google.gerrit.common.data.Permission;
import com.google.gerrit.common.data.PermissionRule;
import com.google.gerrit.common.data.PermissionRule.Action;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.config.AllProjectsName;
@ -97,7 +98,7 @@ public class AllProjectsCreator {
initAllProjects(git);
RefUpdate u = git.updateRef(Constants.HEAD);
u.link(GitRepositoryManager.REF_CONFIG);
u.link(RefNames.REFS_CONFIG);
} catch (RepositoryNotFoundException err) {
String name = allProjectsName.get();
throw new IOException("Cannot create repository " + name, err);
@ -131,7 +132,7 @@ public class AllProjectsCreator {
AccessSection all = config.getAccessSection(AccessSection.ALL, true);
AccessSection heads = config.getAccessSection(AccessSection.HEADS, true);
AccessSection tags = config.getAccessSection("refs/tags/*", true);
AccessSection meta = config.getAccessSection(GitRepositoryManager.REF_CONFIG, true);
AccessSection meta = config.getAccessSection(RefNames.REFS_CONFIG, true);
AccessSection magic = config.getAccessSection("refs/for/" + AccessSection.ALL, true);
grant(config, cap, GlobalCapability.ADMINISTRATE_SERVER, admin);

View File

@ -32,6 +32,7 @@ import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.common.data.Permission;
import com.google.gerrit.common.data.PermissionRule;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.PatchSetApproval.LabelId;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
@ -186,7 +187,7 @@ class Schema_53 extends SchemaVersion {
// Grant out read on the config branch by default.
//
if (config.getProject().getNameKey().equals(systemConfig.wildProjectName)) {
AccessSection meta = config.getAccessSection(GitRepositoryManager.REF_CONFIG, true);
AccessSection meta = config.getAccessSection(RefNames.REFS_CONFIG, true);
Permission read = meta.getPermission(READ, true);
read.getRule(config.resolve(projectOwners), true);
}

View File

@ -15,6 +15,7 @@
package com.google.gerrit.server.schema;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.inject.Inject;
@ -44,8 +45,8 @@ public class Schema_56 extends SchemaVersion {
keysOne = new HashSet<String>();
keysTwo = new HashSet<String>();
keysOne.add(GitRepositoryManager.REF_CONFIG);
keysTwo.add(GitRepositoryManager.REF_CONFIG);
keysOne.add(RefNames.REFS_CONFIG);
keysTwo.add(RefNames.REFS_CONFIG);
keysTwo.add(Constants.HEAD);
}
@ -73,10 +74,10 @@ public class Schema_56 extends SchemaVersion {
try {
RefUpdate update = git.updateRef(Constants.HEAD);
update.disableRefLog();
update.link(GitRepositoryManager.REF_CONFIG);
update.link(RefNames.REFS_CONFIG);
} catch (IOException err) {
ui.message("warning: " + name.get() + ": Cannot update HEAD to "
+ GitRepositoryManager.REF_CONFIG + ": " + err.getMessage());
+ RefNames.REFS_CONFIG + ": " + err.getMessage());
}
}
} finally {

View File

@ -28,6 +28,7 @@ import com.google.gerrit.common.data.Permission;
import com.google.gerrit.common.data.PermissionRule;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
import org.eclipse.jgit.errors.ConfigInvalidException;
@ -208,12 +209,12 @@ public class ProjectConfigTest extends LocalDiskRepositoryTestCase {
md.setMessage("Edit\n");
cfg.commit(md);
Ref ref = db.getRef(GitRepositoryManager.REF_CONFIG);
Ref ref = db.getRef(RefNames.REFS_CONFIG);
return util.getRevWalk().parseCommit(ref.getObjectId());
}
private void update(RevCommit rev) throws Exception {
RefUpdate u = db.updateRef(GitRepositoryManager.REF_CONFIG);
RefUpdate u = db.updateRef(RefNames.REFS_CONFIG);
u.disableRefLog();
u.setNewObjectId(rev);
switch (u.forceUpdate()) {

@ -1 +1 @@
Subproject commit 7eb3360a89282ceaa404bcade5137cc5eb62945f
Subproject commit 6287d6a8941f68ba8a3a8c27f2a979c02ede489a

@ -1 +1 @@
Subproject commit 400f47b99183a9141a192956bac6863f1c2fc14d
Subproject commit 330228ed74629db4ed43e48d2d10925c0d7d2ff8