Move addition of refs/users/self symlink out of filtering logic
Gerrit moved to a model where it wraps around RefDatabase to tell JGit which refs are visible to a user. This was done in I0bb85de2b. This meant moving filtering code from a AdvertiseRefsHook into a wrapper of RefDatabase. There is one case in which the logic that got moved would not only filter refs but add a ref in addition that is not present in the input: when authenticated users interact with All-Users. In this case, Gerrit adds a refs/users/self symbolic reference to make it easier to interact with one's account data. This led to a problem with the new inferface and smelled as a whole since concerns weren't clearly separated. The problem with the new interface would occur when using RefDatabase#exactRef - a method that expects {0,1} refs but got two for All-Users since refs/users/self was added. This change fixes the issue by separating the addition of the symref into an AdvertiseRefsHook and leaving ref filtering by just that. RefAdvertisementIT has different tests for testing the advertisement of refs/users/self and PushAccountIT covers push cases. The tests succeeded before, because the problem could only be encountered when the in-memory ref cache on the push path is not used. We add a config to run push tests without in-memory ref cache to make sure the code path that failed previosuly gets executed now. Bug: Issue 12027 Change-Id: I07777b698ddb86ad5cec1407ac5671874866fee5
This commit is contained in:

committed by
David Pursehouse

parent
e4821b1285
commit
3ceb65aaf0
@@ -35,6 +35,7 @@ import com.google.gerrit.server.git.PermissionAwareRepositoryManager;
|
||||
import com.google.gerrit.server.git.ReceivePackInitializer;
|
||||
import com.google.gerrit.server.git.TransferConfig;
|
||||
import com.google.gerrit.server.git.UploadPackInitializer;
|
||||
import com.google.gerrit.server.git.UsersSelfAdvertiseRefsHook;
|
||||
import com.google.gerrit.server.git.receive.AsyncReceiveCommits;
|
||||
import com.google.gerrit.server.git.validators.UploadValidators;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
@@ -200,6 +201,7 @@ class InProcessProtocol extends TestProtocol<Context> {
|
||||
private final ThreadLocalRequestContext threadContext;
|
||||
private final ProjectCache projectCache;
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final UsersSelfAdvertiseRefsHook usersSelfAdvertiseRefsHook;
|
||||
|
||||
@Inject
|
||||
Upload(
|
||||
@@ -209,7 +211,8 @@ class InProcessProtocol extends TestProtocol<Context> {
|
||||
UploadValidators.Factory uploadValidatorsFactory,
|
||||
ThreadLocalRequestContext threadContext,
|
||||
ProjectCache projectCache,
|
||||
PermissionBackend permissionBackend) {
|
||||
PermissionBackend permissionBackend,
|
||||
UsersSelfAdvertiseRefsHook usersSelfAdvertiseRefsHook) {
|
||||
this.transferConfig = transferConfig;
|
||||
this.uploadPackInitializers = uploadPackInitializers;
|
||||
this.preUploadHooks = preUploadHooks;
|
||||
@@ -217,6 +220,7 @@ class InProcessProtocol extends TestProtocol<Context> {
|
||||
this.threadContext = threadContext;
|
||||
this.projectCache = projectCache;
|
||||
this.permissionBackend = permissionBackend;
|
||||
this.usersSelfAdvertiseRefsHook = usersSelfAdvertiseRefsHook;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -250,6 +254,9 @@ class InProcessProtocol extends TestProtocol<Context> {
|
||||
UploadPack up = new UploadPack(permissionAwareRepository);
|
||||
up.setPackConfig(transferConfig.getPackConfig());
|
||||
up.setTimeout(transferConfig.getTimeout());
|
||||
if (projectState.isAllUsers()) {
|
||||
up.setAdvertiseRefsHook(usersSelfAdvertiseRefsHook);
|
||||
}
|
||||
List<PreUploadHook> hooks = Lists.newArrayList(preUploadHooks);
|
||||
hooks.add(
|
||||
uploadValidatorsFactory.create(
|
||||
|
Reference in New Issue
Block a user