Support fetch of refs/users/self from All-Users repository
Allow a user to fetch its refs/users/YY/XXXXXXX branch as refs/users/self. The user branch contains the sharded account ID in the ref name, but this is an implementation detail that should be hidden from the user. On the other hand users should be able to access their user branch easily. Change-Id: I0f5a9f1456a86873ff91ad418aa60b1eee568109 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -29,6 +29,7 @@ import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.RefDatabase;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.lib.SymbolicRef;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
import org.eclipse.jgit.transport.AbstractAdvertiseRefsHook;
|
||||
import org.eclipse.jgit.transport.ServiceMayNotContinueException;
|
||||
@@ -69,6 +70,18 @@ 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.allRefsAreVisible(ImmutableSet.of(RefNames.REFS_CONFIG))) {
|
||||
Map<String, Ref> r = Maps.newHashMap(refs);
|
||||
if (!projectCtl.controlForRef(RefNames.REFS_CONFIG).isVisible()) {
|
||||
@@ -97,7 +110,8 @@ public class VisibleRefFilter extends AbstractAdvertiseRefsHook {
|
||||
Account.Id accountId;
|
||||
if (ref.getName().startsWith(RefNames.REFS_CACHE_AUTOMERGE)) {
|
||||
continue;
|
||||
} else if ((accountId = Account.Id.fromRef(ref.getName())) != null) {
|
||||
} else if ((accountId =
|
||||
Account.Id.fromRef(ref.getLeaf().getName())) != null) {
|
||||
// Reference related to an account is visible only for the current
|
||||
// account.
|
||||
//
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.google.gerrit.rules.RulesCache;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.account.CapabilityCollection;
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.config.AllUsersName;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.git.BranchOrderSection;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
@@ -80,6 +81,7 @@ public class ProjectState {
|
||||
}
|
||||
|
||||
private final boolean isAllProjects;
|
||||
private final boolean isAllUsers;
|
||||
private final SitePaths sitePaths;
|
||||
private final AllProjectsName allProjectsName;
|
||||
private final ProjectCache projectCache;
|
||||
@@ -113,6 +115,7 @@ public class ProjectState {
|
||||
final SitePaths sitePaths,
|
||||
final ProjectCache projectCache,
|
||||
final AllProjectsName allProjectsName,
|
||||
final AllUsersName allUsersName,
|
||||
final ProjectControl.AssistedFactory projectControlFactory,
|
||||
final PrologEnvironment.Factory envFactory,
|
||||
final GitRepositoryManager gitMgr,
|
||||
@@ -122,6 +125,7 @@ public class ProjectState {
|
||||
this.sitePaths = sitePaths;
|
||||
this.projectCache = projectCache;
|
||||
this.isAllProjects = config.getProject().getNameKey().equals(allProjectsName);
|
||||
this.isAllUsers = config.getProject().getNameKey().equals(allUsersName);
|
||||
this.allProjectsName = allProjectsName;
|
||||
this.projectControlFactory = projectControlFactory;
|
||||
this.envFactory = envFactory;
|
||||
@@ -362,6 +366,10 @@ public class ProjectState {
|
||||
return isAllProjects;
|
||||
}
|
||||
|
||||
public boolean isAllUsers() {
|
||||
return isAllUsers;
|
||||
}
|
||||
|
||||
public boolean isUseContributorAgreements() {
|
||||
return getInheritableBoolean(new Function<Project, InheritableBoolean>() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user