VisibleRefFilter: break out special cases to methods
This clarifies the code a bit by moving a few blocks into their own methods, rather than being inlined in the main filter(). Change-Id: Id81c291a0ec0848d2a965313fa5f33ddbdbf4f7f
This commit is contained in:
@@ -16,9 +16,10 @@ package com.google.gerrit.server.git;
|
||||
|
||||
import static com.google.gerrit.reviewdb.client.RefNames.REFS_CACHE_AUTOMERGE;
|
||||
import static com.google.gerrit.reviewdb.client.RefNames.REFS_CHANGES;
|
||||
import static com.google.gerrit.reviewdb.client.RefNames.REFS_CONFIG;
|
||||
import static com.google.gerrit.reviewdb.client.RefNames.REFS_USERS_SELF;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
@@ -85,24 +86,12 @@ public class VisibleRefFilter extends AbstractAdvertiseRefsHook {
|
||||
}
|
||||
|
||||
public Map<String, Ref> filter(Map<String, Ref> refs, boolean filterTagsSeparately) {
|
||||
if (projectCtl.getProjectState().isAllUsers()
|
||||
&& projectCtl.getUser().isIdentifiedUser()) {
|
||||
Ref userRef =
|
||||
refs.get(RefNames.refsUsers(projectCtl.getUser().getAccountId()));
|
||||
if (userRef != null) {
|
||||
SymbolicRef refsUsersSelf =
|
||||
new SymbolicRef(RefNames.REFS_USERS_SELF, userRef);
|
||||
refs = new HashMap<>(refs);
|
||||
refs.put(refsUsersSelf.getName(), refsUsersSelf);
|
||||
}
|
||||
if (projectCtl.getProjectState().isAllUsers()) {
|
||||
refs = addUsersSelfSymref(refs);
|
||||
}
|
||||
|
||||
if (projectCtl.allRefsAreVisible(ImmutableSet.of(RefNames.REFS_CONFIG))) {
|
||||
Map<String, Ref> r = Maps.newHashMap(refs);
|
||||
if (!projectCtl.controlForRef(RefNames.REFS_CONFIG).isVisible()) {
|
||||
r.remove(RefNames.REFS_CONFIG);
|
||||
}
|
||||
return r;
|
||||
if (projectCtl.allRefsAreVisible(ImmutableSet.of(REFS_CONFIG))) {
|
||||
return fastHideRefsMetaConfig(refs);
|
||||
}
|
||||
|
||||
Account.Id userId;
|
||||
@@ -174,6 +163,28 @@ public class VisibleRefFilter extends AbstractAdvertiseRefsHook {
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<String, Ref> fastHideRefsMetaConfig(Map<String, Ref> refs) {
|
||||
if (refs.containsKey(REFS_CONFIG)
|
||||
&& !projectCtl.controlForRef(REFS_CONFIG).isVisible()) {
|
||||
Map<String, Ref> r = new HashMap<>(refs);
|
||||
r.remove(REFS_CONFIG);
|
||||
return r;
|
||||
}
|
||||
return refs;
|
||||
}
|
||||
|
||||
private Map<String, Ref> addUsersSelfSymref(Map<String, Ref> refs) {
|
||||
if (projectCtl.getUser().isIdentifiedUser()) {
|
||||
Ref r = refs.get(RefNames.refsUsers(projectCtl.getUser().getAccountId()));
|
||||
if (r != null) {
|
||||
SymbolicRef s = new SymbolicRef(REFS_USERS_SELF, r);
|
||||
refs = new HashMap<>(refs);
|
||||
refs.put(s.getName(), s);
|
||||
}
|
||||
}
|
||||
return refs;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Ref> getAdvertisedRefs(Repository repository,
|
||||
RevWalk revWalk) throws ServiceMayNotContinueException {
|
||||
|
||||
Reference in New Issue
Block a user