Allow admins to disable magic ref check on upload

Some sites manage to run their repositories in a way that prevents
users from ever being able to create refs/for, refs/drafts or
refs/publish names in a repository. Allow admins on those servers
to disable this (somewhat) expensive check before every upload.

Change-Id: Ibf51f9fa214aa07ec7bae9c40d6ef8ce6265e816
This commit is contained in:
Shawn Pearce
2013-02-27 16:20:26 -08:00
parent 9baff9d299
commit 5cb31bfbc0
4 changed files with 60 additions and 7 deletions

View File

@@ -23,5 +23,6 @@ public class GitModule extends FactoryModule {
factory(RenameGroupOp.Factory.class);
factory(MetaDataUpdate.InternalFactory.class);
bind(MetaDataUpdate.Server.class);
bind(ReceiveConfig.class);
}
}

View File

@@ -59,7 +59,6 @@ import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountResolver;
import com.google.gerrit.server.config.AllProjectsName;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.TrackingFooters;
import com.google.gerrit.server.events.CommitReceivedEvent;
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
@@ -90,7 +89,6 @@ import com.google.inject.assistedinject.Assisted;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.BatchRefUpdate;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
@@ -251,6 +249,7 @@ public class ReceiveCommits {
private final RequestScopePropagator requestScopePropagator;
private final SshInfo sshInfo;
private final AllProjectsName allProjectsName;
private final ReceiveConfig receiveConfig;
private final ProjectControl projectControl;
private final Project project;
@@ -307,7 +306,7 @@ public class ReceiveCommits {
final RequestScopePropagator requestScopePropagator,
final SshInfo sshInfo,
final AllProjectsName allProjectsName,
final @GerritServerConfig Config config,
ReceiveConfig config,
@Assisted final ProjectControl projectControl,
@Assisted final Repository repo,
final SubmoduleOp.Factory subOpFactory) throws IOException {
@@ -333,6 +332,7 @@ public class ReceiveCommits {
this.requestScopePropagator = requestScopePropagator;
this.sshInfo = sshInfo;
this.allProjectsName = allProjectsName;
this.receiveConfig = config;
this.projectControl = projectControl;
this.project = projectControl.getProject();
@@ -350,8 +350,7 @@ public class ReceiveCommits {
rp.setCheckReceivedObjects(true);
if (!projectControl.allRefsAreVisible()) {
rp.setCheckReferencedObjectsAreReachable(config.getBoolean("receive",
null, "checkReferencedObjectsAreReachable", true));
rp.setCheckReferencedObjectsAreReachable(config.checkReferencedObjectsAreReachable);
rp.setAdvertiseRefsHook(new VisibleRefFilter(tagCache, changeCache, repo, projectControl, db, false));
}
List<AdvertiseRefsHook> advHooks = new ArrayList<AdvertiseRefsHook>(3);
@@ -485,8 +484,10 @@ public class ReceiveCommits {
if (result != Capable.OK) {
return result;
}
return MagicBranch.checkMagicBranchRefs(repo, project);
if (receiveConfig.checkMagicRefs) {
result = MagicBranch.checkMagicBranchRefs(repo, project);
}
return result;
}
private void addMessage(String message) {

View File

@@ -0,0 +1,37 @@
// 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.server.git;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.jgit.lib.Config;
@Singleton
class ReceiveConfig {
final boolean checkMagicRefs;
final boolean checkReferencedObjectsAreReachable;
@Inject
ReceiveConfig(@GerritServerConfig Config config) {
checkMagicRefs = config.getBoolean(
"receive", null, "checkMagicRefs",
true);
checkReferencedObjectsAreReachable = config.getBoolean(
"receive", null, "checkReferencedObjectsAreReachable",
true);
}
}