Replace ProjectControl with ProjectState in Args4J stack
This commit replaces ProjectControl with ProjectState in all classes that depend on the Args4J argument 'PROJECT' and uses Provider<CurrentUser> or CurrentUser where applicable. This commit is a step towards using PermissionBackend instead of ProjectControl. Change-Id: If8ca1c8bac37caeff6d00abb1796570152858118
This commit is contained in:
		@@ -34,8 +34,8 @@ import com.google.gerrit.server.git.validators.UploadValidators;
 | 
			
		||||
import com.google.gerrit.server.permissions.PermissionBackend;
 | 
			
		||||
import com.google.gerrit.server.permissions.PermissionBackendException;
 | 
			
		||||
import com.google.gerrit.server.permissions.ProjectPermission;
 | 
			
		||||
import com.google.gerrit.server.project.NoSuchProjectException;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectCache;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.inject.AbstractModule;
 | 
			
		||||
import com.google.inject.Inject;
 | 
			
		||||
import com.google.inject.Provider;
 | 
			
		||||
@@ -80,7 +80,7 @@ import org.eclipse.jgit.transport.resolver.UploadPackFactory;
 | 
			
		||||
public class GitOverHttpServlet extends GitServlet {
 | 
			
		||||
  private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
  private static final String ATT_CONTROL = ProjectControl.class.getName();
 | 
			
		||||
  private static final String ATT_STATE = ProjectState.class.getName();
 | 
			
		||||
  private static final String ATT_ARC = AsyncReceiveCommits.class.getName();
 | 
			
		||||
  private static final String ID_CACHE = "adv_bases";
 | 
			
		||||
 | 
			
		||||
@@ -145,18 +145,18 @@ public class GitOverHttpServlet extends GitServlet {
 | 
			
		||||
    private final GitRepositoryManager manager;
 | 
			
		||||
    private final PermissionBackend permissionBackend;
 | 
			
		||||
    private final Provider<CurrentUser> userProvider;
 | 
			
		||||
    private final ProjectControl.GenericFactory projectControlFactory;
 | 
			
		||||
    private final ProjectCache projectCache;
 | 
			
		||||
 | 
			
		||||
    @Inject
 | 
			
		||||
    Resolver(
 | 
			
		||||
        GitRepositoryManager manager,
 | 
			
		||||
        PermissionBackend permissionBackend,
 | 
			
		||||
        Provider<CurrentUser> userProvider,
 | 
			
		||||
        ProjectControl.GenericFactory projectControlFactory) {
 | 
			
		||||
        ProjectCache projectCache) {
 | 
			
		||||
      this.manager = manager;
 | 
			
		||||
      this.permissionBackend = permissionBackend;
 | 
			
		||||
      this.userProvider = userProvider;
 | 
			
		||||
      this.projectControlFactory = projectControlFactory;
 | 
			
		||||
      this.projectCache = projectCache;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -182,13 +182,11 @@ public class GitOverHttpServlet extends GitServlet {
 | 
			
		||||
 | 
			
		||||
      try {
 | 
			
		||||
        Project.NameKey nameKey = new Project.NameKey(projectName);
 | 
			
		||||
        ProjectControl pc;
 | 
			
		||||
        try {
 | 
			
		||||
          pc = projectControlFactory.controlFor(nameKey, user);
 | 
			
		||||
        } catch (NoSuchProjectException err) {
 | 
			
		||||
          throw new RepositoryNotFoundException(projectName);
 | 
			
		||||
        ProjectState state = projectCache.checkedGet(nameKey);
 | 
			
		||||
        if (state == null) {
 | 
			
		||||
          throw new RepositoryNotFoundException(nameKey.get());
 | 
			
		||||
        }
 | 
			
		||||
        req.setAttribute(ATT_CONTROL, pc);
 | 
			
		||||
        req.setAttribute(ATT_STATE, state);
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
          permissionBackend.user(user).project(nameKey).check(ProjectPermission.ACCESS);
 | 
			
		||||
@@ -231,9 +229,9 @@ public class GitOverHttpServlet extends GitServlet {
 | 
			
		||||
      up.setTimeout(config.getTimeout());
 | 
			
		||||
      up.setPreUploadHook(PreUploadHookChain.newChain(Lists.newArrayList(preUploadHooks)));
 | 
			
		||||
      up.setPostUploadHook(PostUploadHookChain.newChain(Lists.newArrayList(postUploadHooks)));
 | 
			
		||||
      ProjectControl pc = (ProjectControl) req.getAttribute(ATT_CONTROL);
 | 
			
		||||
      ProjectState state = (ProjectState) req.getAttribute(ATT_STATE);
 | 
			
		||||
      for (UploadPackInitializer initializer : uploadPackInitializers) {
 | 
			
		||||
        initializer.init(pc.getProject().getNameKey(), up);
 | 
			
		||||
        initializer.init(state.getNameKey(), up);
 | 
			
		||||
      }
 | 
			
		||||
      return up;
 | 
			
		||||
    }
 | 
			
		||||
@@ -243,15 +241,18 @@ public class GitOverHttpServlet extends GitServlet {
 | 
			
		||||
    private final VisibleRefFilter.Factory refFilterFactory;
 | 
			
		||||
    private final UploadValidators.Factory uploadValidatorsFactory;
 | 
			
		||||
    private final PermissionBackend permissionBackend;
 | 
			
		||||
    private final Provider<CurrentUser> userProvider;
 | 
			
		||||
 | 
			
		||||
    @Inject
 | 
			
		||||
    UploadFilter(
 | 
			
		||||
        VisibleRefFilter.Factory refFilterFactory,
 | 
			
		||||
        UploadValidators.Factory uploadValidatorsFactory,
 | 
			
		||||
        PermissionBackend permissionBackend) {
 | 
			
		||||
        PermissionBackend permissionBackend,
 | 
			
		||||
        Provider<CurrentUser> userProvider) {
 | 
			
		||||
      this.refFilterFactory = refFilterFactory;
 | 
			
		||||
      this.uploadValidatorsFactory = uploadValidatorsFactory;
 | 
			
		||||
      this.permissionBackend = permissionBackend;
 | 
			
		||||
      this.userProvider = userProvider;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -259,13 +260,13 @@ public class GitOverHttpServlet extends GitServlet {
 | 
			
		||||
        throws IOException, ServletException {
 | 
			
		||||
      // The Resolver above already checked READ access for us.
 | 
			
		||||
      Repository repo = ServletUtils.getRepository(request);
 | 
			
		||||
      ProjectControl pc = (ProjectControl) request.getAttribute(ATT_CONTROL);
 | 
			
		||||
      ProjectState state = (ProjectState) request.getAttribute(ATT_STATE);
 | 
			
		||||
      UploadPack up = (UploadPack) request.getAttribute(ServletUtils.ATTRIBUTE_HANDLER);
 | 
			
		||||
 | 
			
		||||
      try {
 | 
			
		||||
        permissionBackend
 | 
			
		||||
            .user(pc.getUser())
 | 
			
		||||
            .project(pc.getProject().getNameKey())
 | 
			
		||||
            .user(userProvider)
 | 
			
		||||
            .project(state.getNameKey())
 | 
			
		||||
            .check(ProjectPermission.RUN_UPLOAD_PACK);
 | 
			
		||||
      } catch (AuthException e) {
 | 
			
		||||
        GitSmartHttpTools.sendError(
 | 
			
		||||
@@ -280,10 +281,10 @@ public class GitOverHttpServlet extends GitServlet {
 | 
			
		||||
      // We use getRemoteHost() here instead of getRemoteAddr() because REMOTE_ADDR
 | 
			
		||||
      // may have been overridden by a proxy server -- we'll try to avoid this.
 | 
			
		||||
      UploadValidators uploadValidators =
 | 
			
		||||
          uploadValidatorsFactory.create(pc.getProject(), repo, request.getRemoteHost());
 | 
			
		||||
          uploadValidatorsFactory.create(state.getProject(), repo, request.getRemoteHost());
 | 
			
		||||
      up.setPreUploadHook(
 | 
			
		||||
          PreUploadHookChain.newChain(Lists.newArrayList(up.getPreUploadHook(), uploadValidators)));
 | 
			
		||||
      up.setAdvertiseRefsHook(refFilterFactory.create(pc.getProjectState(), repo));
 | 
			
		||||
      up.setAdvertiseRefsHook(refFilterFactory.create(state, repo));
 | 
			
		||||
 | 
			
		||||
      next.doFilter(request, response);
 | 
			
		||||
    }
 | 
			
		||||
@@ -297,29 +298,27 @@ public class GitOverHttpServlet extends GitServlet {
 | 
			
		||||
 | 
			
		||||
  static class ReceiveFactory implements ReceivePackFactory<HttpServletRequest> {
 | 
			
		||||
    private final AsyncReceiveCommits.Factory factory;
 | 
			
		||||
    private final Provider<CurrentUser> userProvider;
 | 
			
		||||
 | 
			
		||||
    @Inject
 | 
			
		||||
    ReceiveFactory(AsyncReceiveCommits.Factory factory) {
 | 
			
		||||
    ReceiveFactory(AsyncReceiveCommits.Factory factory, Provider<CurrentUser> userProvider) {
 | 
			
		||||
      this.factory = factory;
 | 
			
		||||
      this.userProvider = userProvider;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ReceivePack create(HttpServletRequest req, Repository db)
 | 
			
		||||
        throws ServiceNotAuthorizedException {
 | 
			
		||||
      final ProjectControl pc = (ProjectControl) req.getAttribute(ATT_CONTROL);
 | 
			
		||||
      final ProjectState state = (ProjectState) req.getAttribute(ATT_STATE);
 | 
			
		||||
 | 
			
		||||
      if (!(pc.getUser().isIdentifiedUser())) {
 | 
			
		||||
      if (!(userProvider.get().isIdentifiedUser())) {
 | 
			
		||||
        // Anonymous users are not permitted to push.
 | 
			
		||||
        throw new ServiceNotAuthorizedException();
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      AsyncReceiveCommits arc =
 | 
			
		||||
          factory.create(
 | 
			
		||||
              pc.getProjectState(),
 | 
			
		||||
              pc.getUser().asIdentifiedUser(),
 | 
			
		||||
              db,
 | 
			
		||||
              null,
 | 
			
		||||
              ImmutableSetMultimap.of());
 | 
			
		||||
              state, userProvider.get().asIdentifiedUser(), db, null, ImmutableSetMultimap.of());
 | 
			
		||||
      ReceivePack rp = arc.getReceivePack();
 | 
			
		||||
      req.setAttribute(ATT_ARC, arc);
 | 
			
		||||
      return rp;
 | 
			
		||||
@@ -337,13 +336,16 @@ public class GitOverHttpServlet extends GitServlet {
 | 
			
		||||
  static class ReceiveFilter implements Filter {
 | 
			
		||||
    private final Cache<AdvertisedObjectsCacheKey, Set<ObjectId>> cache;
 | 
			
		||||
    private final PermissionBackend permissionBackend;
 | 
			
		||||
    private final Provider<CurrentUser> userProvider;
 | 
			
		||||
 | 
			
		||||
    @Inject
 | 
			
		||||
    ReceiveFilter(
 | 
			
		||||
        @Named(ID_CACHE) Cache<AdvertisedObjectsCacheKey, Set<ObjectId>> cache,
 | 
			
		||||
        PermissionBackend permissionBackend) {
 | 
			
		||||
        PermissionBackend permissionBackend,
 | 
			
		||||
        Provider<CurrentUser> userProvider) {
 | 
			
		||||
      this.cache = cache;
 | 
			
		||||
      this.permissionBackend = permissionBackend;
 | 
			
		||||
      this.userProvider = userProvider;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -354,13 +356,12 @@ public class GitOverHttpServlet extends GitServlet {
 | 
			
		||||
      AsyncReceiveCommits arc = (AsyncReceiveCommits) request.getAttribute(ATT_ARC);
 | 
			
		||||
      ReceivePack rp = arc.getReceivePack();
 | 
			
		||||
      rp.getAdvertiseRefsHook().advertiseRefs(rp);
 | 
			
		||||
      ProjectControl pc = (ProjectControl) request.getAttribute(ATT_CONTROL);
 | 
			
		||||
      Project.NameKey projectName = pc.getProject().getNameKey();
 | 
			
		||||
      ProjectState state = (ProjectState) request.getAttribute(ATT_STATE);
 | 
			
		||||
 | 
			
		||||
      try {
 | 
			
		||||
        permissionBackend
 | 
			
		||||
            .user(pc.getUser())
 | 
			
		||||
            .project(pc.getProject().getNameKey())
 | 
			
		||||
            .user(userProvider)
 | 
			
		||||
            .project(state.getNameKey())
 | 
			
		||||
            .check(ProjectPermission.RUN_RECEIVE_PACK);
 | 
			
		||||
      } catch (AuthException e) {
 | 
			
		||||
        GitSmartHttpTools.sendError(
 | 
			
		||||
@@ -388,13 +389,13 @@ public class GitOverHttpServlet extends GitServlet {
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (!(pc.getUser().isIdentifiedUser())) {
 | 
			
		||||
      if (!(userProvider.get().isIdentifiedUser())) {
 | 
			
		||||
        chain.doFilter(request, response);
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      AdvertisedObjectsCacheKey cacheKey =
 | 
			
		||||
          AdvertisedObjectsCacheKey.create(pc.getUser().getAccountId(), projectName);
 | 
			
		||||
          AdvertisedObjectsCacheKey.create(userProvider.get().getAccountId(), state.getNameKey());
 | 
			
		||||
 | 
			
		||||
      if (isGet) {
 | 
			
		||||
        cache.invalidate(cacheKey);
 | 
			
		||||
 
 | 
			
		||||
@@ -25,10 +25,10 @@ import com.google.gerrit.server.args4j.AccountIdHandler;
 | 
			
		||||
import com.google.gerrit.server.args4j.ChangeIdHandler;
 | 
			
		||||
import com.google.gerrit.server.args4j.ObjectIdHandler;
 | 
			
		||||
import com.google.gerrit.server.args4j.PatchSetIdHandler;
 | 
			
		||||
import com.google.gerrit.server.args4j.ProjectControlHandler;
 | 
			
		||||
import com.google.gerrit.server.args4j.ProjectHandler;
 | 
			
		||||
import com.google.gerrit.server.args4j.SocketAddressHandler;
 | 
			
		||||
import com.google.gerrit.server.args4j.TimestampHandler;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.util.cli.CmdLineParser;
 | 
			
		||||
import com.google.gerrit.util.cli.OptionHandlerUtil;
 | 
			
		||||
import com.google.gerrit.util.cli.OptionHandlers;
 | 
			
		||||
@@ -51,7 +51,7 @@ public class CmdLineParserModule extends FactoryModule {
 | 
			
		||||
    registerOptionHandler(Change.Id.class, ChangeIdHandler.class);
 | 
			
		||||
    registerOptionHandler(ObjectId.class, ObjectIdHandler.class);
 | 
			
		||||
    registerOptionHandler(PatchSet.Id.class, PatchSetIdHandler.class);
 | 
			
		||||
    registerOptionHandler(ProjectControl.class, ProjectControlHandler.class);
 | 
			
		||||
    registerOptionHandler(ProjectState.class, ProjectHandler.class);
 | 
			
		||||
    registerOptionHandler(SocketAddress.class, SocketAddressHandler.class);
 | 
			
		||||
    registerOptionHandler(Timestamp.class, TimestampHandler.class);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,8 @@ import com.google.gerrit.server.permissions.PermissionBackend;
 | 
			
		||||
import com.google.gerrit.server.permissions.PermissionBackendException;
 | 
			
		||||
import com.google.gerrit.server.permissions.ProjectPermission;
 | 
			
		||||
import com.google.gerrit.server.project.NoSuchProjectException;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectCache;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.inject.Inject;
 | 
			
		||||
import com.google.inject.Provider;
 | 
			
		||||
import com.google.inject.assistedinject.Assisted;
 | 
			
		||||
@@ -36,23 +37,23 @@ import org.kohsuke.args4j.spi.Setter;
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
import org.slf4j.LoggerFactory;
 | 
			
		||||
 | 
			
		||||
public class ProjectControlHandler extends OptionHandler<ProjectControl> {
 | 
			
		||||
  private static final Logger log = LoggerFactory.getLogger(ProjectControlHandler.class);
 | 
			
		||||
public class ProjectHandler extends OptionHandler<ProjectState> {
 | 
			
		||||
  private static final Logger log = LoggerFactory.getLogger(ProjectHandler.class);
 | 
			
		||||
 | 
			
		||||
  private final ProjectControl.GenericFactory projectControlFactory;
 | 
			
		||||
  private final ProjectCache projectCache;
 | 
			
		||||
  private final PermissionBackend permissionBackend;
 | 
			
		||||
  private final Provider<CurrentUser> user;
 | 
			
		||||
 | 
			
		||||
  @Inject
 | 
			
		||||
  public ProjectControlHandler(
 | 
			
		||||
      ProjectControl.GenericFactory projectControlFactory,
 | 
			
		||||
  public ProjectHandler(
 | 
			
		||||
      ProjectCache projectCache,
 | 
			
		||||
      PermissionBackend permissionBackend,
 | 
			
		||||
      Provider<CurrentUser> user,
 | 
			
		||||
      @Assisted final CmdLineParser parser,
 | 
			
		||||
      @Assisted final OptionDef option,
 | 
			
		||||
      @Assisted final Setter<ProjectControl> setter) {
 | 
			
		||||
      @Assisted final Setter<ProjectState> setter) {
 | 
			
		||||
    super(parser, option, setter);
 | 
			
		||||
    this.projectControlFactory = projectControlFactory;
 | 
			
		||||
    this.projectCache = projectCache;
 | 
			
		||||
    this.permissionBackend = permissionBackend;
 | 
			
		||||
    this.user = user;
 | 
			
		||||
  }
 | 
			
		||||
@@ -77,20 +78,21 @@ public class ProjectControlHandler extends OptionHandler<ProjectControl> {
 | 
			
		||||
    String nameWithoutSuffix = ProjectUtil.stripGitSuffix(projectName);
 | 
			
		||||
    Project.NameKey nameKey = new Project.NameKey(nameWithoutSuffix);
 | 
			
		||||
 | 
			
		||||
    ProjectControl control;
 | 
			
		||||
    ProjectState state;
 | 
			
		||||
    try {
 | 
			
		||||
      control = projectControlFactory.controlFor(nameKey, user.get());
 | 
			
		||||
      state = projectCache.checkedGet(nameKey);
 | 
			
		||||
      if (state == null) {
 | 
			
		||||
        throw new CmdLineException(owner, String.format("project %s not found", nameWithoutSuffix));
 | 
			
		||||
      }
 | 
			
		||||
      permissionBackend.user(user).project(nameKey).check(ProjectPermission.ACCESS);
 | 
			
		||||
    } catch (AuthException e) {
 | 
			
		||||
      throw new CmdLineException(owner, new NoSuchProjectException(nameKey).getMessage());
 | 
			
		||||
    } catch (NoSuchProjectException e) {
 | 
			
		||||
      throw new CmdLineException(owner, e.getMessage());
 | 
			
		||||
    } catch (PermissionBackendException | IOException e) {
 | 
			
		||||
      log.warn("Cannot load project " + nameWithoutSuffix, e);
 | 
			
		||||
      throw new CmdLineException(owner, new NoSuchProjectException(nameKey).getMessage());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    setter.addValue(control);
 | 
			
		||||
    setter.addValue(state);
 | 
			
		||||
    return 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -41,7 +41,6 @@ import com.google.gerrit.server.account.GetGroups;
 | 
			
		||||
import com.google.gerrit.server.account.GroupBackend;
 | 
			
		||||
import com.google.gerrit.server.account.GroupCache;
 | 
			
		||||
import com.google.gerrit.server.account.GroupControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gwtorm.server.OrmException;
 | 
			
		||||
import com.google.inject.Inject;
 | 
			
		||||
@@ -94,10 +93,6 @@ public class ListGroups implements RestReadView<TopLevelResource> {
 | 
			
		||||
    aliases = {"-p"},
 | 
			
		||||
    usage = "projects for which the groups should be listed"
 | 
			
		||||
  )
 | 
			
		||||
  public void addProject(ProjectControl project) {
 | 
			
		||||
    addProject(project.getProjectState());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void addProject(ProjectState project) {
 | 
			
		||||
    projects.add(project);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,6 @@ import com.google.gerrit.server.AccessPath;
 | 
			
		||||
import com.google.gerrit.server.IdentifiedUser;
 | 
			
		||||
import com.google.gerrit.server.git.GitRepositoryManager;
 | 
			
		||||
import com.google.gerrit.server.permissions.PermissionBackendException;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.sshd.SshScope.Context;
 | 
			
		||||
import com.google.inject.Inject;
 | 
			
		||||
@@ -31,7 +30,7 @@ import org.kohsuke.args4j.Argument;
 | 
			
		||||
 | 
			
		||||
public abstract class AbstractGitCommand extends BaseCommand {
 | 
			
		||||
  @Argument(index = 0, metaVar = "PROJECT.git", required = true, usage = "project name")
 | 
			
		||||
  protected ProjectControl projectControl;
 | 
			
		||||
  protected ProjectState projectState;
 | 
			
		||||
 | 
			
		||||
  @Inject private SshScope sshScope;
 | 
			
		||||
 | 
			
		||||
@@ -41,12 +40,9 @@ public abstract class AbstractGitCommand extends BaseCommand {
 | 
			
		||||
 | 
			
		||||
  @Inject private SshScope.Context context;
 | 
			
		||||
 | 
			
		||||
  @Inject private IdentifiedUser user;
 | 
			
		||||
 | 
			
		||||
  @Inject private IdentifiedUser.GenericFactory userFactory;
 | 
			
		||||
 | 
			
		||||
  protected Repository repo;
 | 
			
		||||
  protected ProjectState state;
 | 
			
		||||
  protected Project.NameKey projectName;
 | 
			
		||||
  protected Project project;
 | 
			
		||||
 | 
			
		||||
@@ -69,7 +65,7 @@ public abstract class AbstractGitCommand extends BaseCommand {
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public Project.NameKey getProjectName() {
 | 
			
		||||
              return projectControl.getProjectState().getNameKey();
 | 
			
		||||
              return projectState.getNameKey();
 | 
			
		||||
            }
 | 
			
		||||
          });
 | 
			
		||||
    } finally {
 | 
			
		||||
@@ -88,8 +84,7 @@ public abstract class AbstractGitCommand extends BaseCommand {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void service() throws IOException, PermissionBackendException, Failure {
 | 
			
		||||
    state = projectControl.getProjectState();
 | 
			
		||||
    project = state.getProject();
 | 
			
		||||
    project = projectState.getProject();
 | 
			
		||||
    projectName = project.getNameKey();
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
 
 | 
			
		||||
@@ -79,6 +79,8 @@ public abstract class BaseCommand implements Command {
 | 
			
		||||
 | 
			
		||||
  private ExitCallback exit;
 | 
			
		||||
 | 
			
		||||
  @Inject protected CurrentUser user;
 | 
			
		||||
 | 
			
		||||
  @Inject private SshScope sshScope;
 | 
			
		||||
 | 
			
		||||
  @Inject private CmdLineParser.Factory cmdLineParserFactory;
 | 
			
		||||
@@ -88,7 +90,6 @@ public abstract class BaseCommand implements Command {
 | 
			
		||||
  @Inject @CommandExecutor private ScheduledThreadPoolExecutor executor;
 | 
			
		||||
 | 
			
		||||
  @Inject private PermissionBackend permissionBackend;
 | 
			
		||||
  @Inject private CurrentUser user;
 | 
			
		||||
 | 
			
		||||
  @Inject private SshScope.Context context;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,7 @@ import com.google.gerrit.server.permissions.ChangePermission;
 | 
			
		||||
import com.google.gerrit.server.permissions.GlobalPermission;
 | 
			
		||||
import com.google.gerrit.server.permissions.PermissionBackend;
 | 
			
		||||
import com.google.gerrit.server.permissions.PermissionBackendException;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.sshd.BaseCommand.UnloggedFailure;
 | 
			
		||||
import com.google.gwtorm.server.OrmException;
 | 
			
		||||
import com.google.inject.Inject;
 | 
			
		||||
@@ -67,15 +67,15 @@ public class ChangeArgumentParser {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void addChange(
 | 
			
		||||
      String id, Map<Change.Id, ChangeResource> changes, ProjectControl projectControl)
 | 
			
		||||
      String id, Map<Change.Id, ChangeResource> changes, ProjectState projectState)
 | 
			
		||||
      throws UnloggedFailure, OrmException, PermissionBackendException {
 | 
			
		||||
    addChange(id, changes, projectControl, true);
 | 
			
		||||
    addChange(id, changes, projectState, true);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public void addChange(
 | 
			
		||||
      String id,
 | 
			
		||||
      Map<Change.Id, ChangeResource> changes,
 | 
			
		||||
      ProjectControl projectControl,
 | 
			
		||||
      ProjectState projectState,
 | 
			
		||||
      boolean useIndex)
 | 
			
		||||
      throws UnloggedFailure, OrmException, PermissionBackendException {
 | 
			
		||||
    List<ChangeNotes> matched = useIndex ? changeFinder.find(id) : changeFromNotesFactory(id);
 | 
			
		||||
@@ -89,7 +89,7 @@ public class ChangeArgumentParser {
 | 
			
		||||
    }
 | 
			
		||||
    for (ChangeNotes notes : matched) {
 | 
			
		||||
      if (!changes.containsKey(notes.getChangeId())
 | 
			
		||||
          && inProject(projectControl, notes.getProjectName())
 | 
			
		||||
          && inProject(projectState, notes.getProjectName())
 | 
			
		||||
          && (canMaintainServer
 | 
			
		||||
              || permissionBackend
 | 
			
		||||
                  .user(currentUser)
 | 
			
		||||
@@ -127,9 +127,9 @@ public class ChangeArgumentParser {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private boolean inProject(ProjectControl projectControl, Project.NameKey project) {
 | 
			
		||||
    if (projectControl != null) {
 | 
			
		||||
      return projectControl.getProject().getNameKey().equals(project);
 | 
			
		||||
  private boolean inProject(ProjectState projectState, Project.NameKey project) {
 | 
			
		||||
    if (projectState != null) {
 | 
			
		||||
      return projectState.getNameKey().equals(project);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // No --project option, so they want every project.
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,8 @@
 | 
			
		||||
 | 
			
		||||
package com.google.gerrit.sshd.commands;
 | 
			
		||||
 | 
			
		||||
import static java.util.stream.Collectors.toList;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.common.data.GlobalCapability;
 | 
			
		||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
 | 
			
		||||
import com.google.gerrit.extensions.common.ProjectInfo;
 | 
			
		||||
@@ -24,7 +26,6 @@ import com.google.gerrit.server.git.ProjectConfig;
 | 
			
		||||
import com.google.gerrit.server.permissions.PermissionBackendException;
 | 
			
		||||
import com.google.gerrit.server.project.ListChildProjects;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectCache;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectResource;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.sshd.CommandMetaData;
 | 
			
		||||
@@ -57,21 +58,21 @@ final class AdminSetParent extends SshCommand {
 | 
			
		||||
    metaVar = "NAME",
 | 
			
		||||
    usage = "new parent project"
 | 
			
		||||
  )
 | 
			
		||||
  private ProjectControl newParent;
 | 
			
		||||
  private ProjectState newParent;
 | 
			
		||||
 | 
			
		||||
  @Option(
 | 
			
		||||
    name = "--children-of",
 | 
			
		||||
    metaVar = "NAME",
 | 
			
		||||
    usage = "parent project for which the child projects should be reparented"
 | 
			
		||||
  )
 | 
			
		||||
  private ProjectControl oldParent;
 | 
			
		||||
  private ProjectState oldParent;
 | 
			
		||||
 | 
			
		||||
  @Option(
 | 
			
		||||
    name = "--exclude",
 | 
			
		||||
    metaVar = "NAME",
 | 
			
		||||
    usage = "child project of old parent project which should not be reparented"
 | 
			
		||||
  )
 | 
			
		||||
  private List<ProjectControl> excludedChildren = new ArrayList<>();
 | 
			
		||||
  private List<ProjectState> excludedChildren = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
  @Argument(
 | 
			
		||||
    index = 0,
 | 
			
		||||
@@ -80,7 +81,7 @@ final class AdminSetParent extends SshCommand {
 | 
			
		||||
    metaVar = "NAME",
 | 
			
		||||
    usage = "projects to modify"
 | 
			
		||||
  )
 | 
			
		||||
  private List<ProjectControl> children = new ArrayList<>();
 | 
			
		||||
  private List<ProjectState> children = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
  @Inject private ProjectCache projectCache;
 | 
			
		||||
 | 
			
		||||
@@ -125,10 +126,8 @@ final class AdminSetParent extends SshCommand {
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    final List<Project.NameKey> childProjects = new ArrayList<>();
 | 
			
		||||
    for (ProjectControl pc : children) {
 | 
			
		||||
      childProjects.add(pc.getProject().getNameKey());
 | 
			
		||||
    }
 | 
			
		||||
    final List<Project.NameKey> childProjects =
 | 
			
		||||
        children.stream().map(ProjectState::getNameKey).collect(toList());
 | 
			
		||||
    if (oldParent != null) {
 | 
			
		||||
      try {
 | 
			
		||||
        childProjects.addAll(getChildrenForReparenting(oldParent));
 | 
			
		||||
@@ -196,19 +195,18 @@ final class AdminSetParent extends SshCommand {
 | 
			
		||||
   * list of child projects does not contain projects that were specified to be excluded from
 | 
			
		||||
   * reparenting.
 | 
			
		||||
   */
 | 
			
		||||
  private List<Project.NameKey> getChildrenForReparenting(ProjectControl parent)
 | 
			
		||||
  private List<Project.NameKey> getChildrenForReparenting(ProjectState parent)
 | 
			
		||||
      throws PermissionBackendException {
 | 
			
		||||
    final List<Project.NameKey> childProjects = new ArrayList<>();
 | 
			
		||||
    final List<Project.NameKey> excluded = new ArrayList<>(excludedChildren.size());
 | 
			
		||||
    for (ProjectControl excludedChild : excludedChildren) {
 | 
			
		||||
    for (ProjectState excludedChild : excludedChildren) {
 | 
			
		||||
      excluded.add(excludedChild.getProject().getNameKey());
 | 
			
		||||
    }
 | 
			
		||||
    final List<Project.NameKey> automaticallyExcluded = new ArrayList<>(excludedChildren.size());
 | 
			
		||||
    if (newParentKey != null) {
 | 
			
		||||
      automaticallyExcluded.addAll(getAllParents(newParentKey));
 | 
			
		||||
    }
 | 
			
		||||
    for (ProjectInfo child :
 | 
			
		||||
        listChildProjects.apply(new ProjectResource(parent.getProjectState(), parent.getUser()))) {
 | 
			
		||||
    for (ProjectInfo child : listChildProjects.apply(new ProjectResource(parent, user))) {
 | 
			
		||||
      final Project.NameKey childName = new Project.NameKey(child.name);
 | 
			
		||||
      if (!excluded.contains(childName)) {
 | 
			
		||||
        if (!automaticallyExcluded.contains(childName)) {
 | 
			
		||||
 
 | 
			
		||||
@@ -20,8 +20,8 @@ import com.google.common.base.Joiner;
 | 
			
		||||
import com.google.common.collect.Lists;
 | 
			
		||||
import com.google.gerrit.server.project.BanCommit;
 | 
			
		||||
import com.google.gerrit.server.project.BanCommit.BanResultInfo;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectResource;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.sshd.CommandMetaData;
 | 
			
		||||
import com.google.gerrit.sshd.SshCommand;
 | 
			
		||||
import com.google.inject.Inject;
 | 
			
		||||
@@ -51,7 +51,7 @@ public class BanCommitCommand extends SshCommand {
 | 
			
		||||
    metaVar = "PROJECT",
 | 
			
		||||
    usage = "name of the project for which the commit should be banned"
 | 
			
		||||
  )
 | 
			
		||||
  private ProjectControl projectControl;
 | 
			
		||||
  private ProjectState projectState;
 | 
			
		||||
 | 
			
		||||
  @Argument(
 | 
			
		||||
    index = 1,
 | 
			
		||||
@@ -71,10 +71,7 @@ public class BanCommitCommand extends SshCommand {
 | 
			
		||||
          BanCommit.Input.fromCommits(Lists.transform(commitsToBan, ObjectId::getName));
 | 
			
		||||
      input.reason = reason;
 | 
			
		||||
 | 
			
		||||
      BanResultInfo r =
 | 
			
		||||
          banCommit.apply(
 | 
			
		||||
              new ProjectResource(projectControl.getProjectState(), projectControl.getUser()),
 | 
			
		||||
              input);
 | 
			
		||||
      BanResultInfo r = banCommit.apply(new ProjectResource(projectState, user), input);
 | 
			
		||||
      printCommits(r.newlyBanned, "The following commits were banned");
 | 
			
		||||
      printCommits(r.alreadyBanned, "The following commits were already banned");
 | 
			
		||||
      printCommits(r.ignored, "The following ids do not represent commits and were ignored");
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ package com.google.gerrit.sshd.commands;
 | 
			
		||||
import com.google.gerrit.extensions.api.GerritApi;
 | 
			
		||||
import com.google.gerrit.extensions.api.projects.BranchInput;
 | 
			
		||||
import com.google.gerrit.extensions.restapi.RestApiException;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.sshd.CommandMetaData;
 | 
			
		||||
import com.google.gerrit.sshd.SshCommand;
 | 
			
		||||
import com.google.inject.Inject;
 | 
			
		||||
@@ -28,7 +28,7 @@ import org.kohsuke.args4j.Argument;
 | 
			
		||||
public final class CreateBranchCommand extends SshCommand {
 | 
			
		||||
 | 
			
		||||
  @Argument(index = 0, required = true, metaVar = "PROJECT", usage = "name of the project")
 | 
			
		||||
  private ProjectControl project;
 | 
			
		||||
  private ProjectState project;
 | 
			
		||||
 | 
			
		||||
  @Argument(index = 1, required = true, metaVar = "NAME", usage = "name of branch to be created")
 | 
			
		||||
  private String name;
 | 
			
		||||
@@ -48,7 +48,7 @@ public final class CreateBranchCommand extends SshCommand {
 | 
			
		||||
    try {
 | 
			
		||||
      BranchInput in = new BranchInput();
 | 
			
		||||
      in.revision = revision;
 | 
			
		||||
      gApi.projects().name(project.getProject().getNameKey().get()).branch(name).create(in);
 | 
			
		||||
      gApi.projects().name(project.getName()).branch(name).create(in);
 | 
			
		||||
    } catch (RestApiException e) {
 | 
			
		||||
      throw die(e);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,7 @@ import com.google.gerrit.extensions.restapi.RestApiException;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.AccountGroup;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.Project;
 | 
			
		||||
import com.google.gerrit.server.permissions.PermissionBackendException;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.server.project.SuggestParentCandidates;
 | 
			
		||||
import com.google.gerrit.sshd.CommandMetaData;
 | 
			
		||||
import com.google.gerrit.sshd.SshCommand;
 | 
			
		||||
@@ -68,7 +68,7 @@ final class CreateProjectCommand extends SshCommand {
 | 
			
		||||
    metaVar = "NAME",
 | 
			
		||||
    usage = "parent project"
 | 
			
		||||
  )
 | 
			
		||||
  private ProjectControl newParent;
 | 
			
		||||
  private ProjectState newParent;
 | 
			
		||||
 | 
			
		||||
  @Option(name = "--permissions-only", usage = "create project for use only as parent")
 | 
			
		||||
  private boolean permissionsOnly;
 | 
			
		||||
@@ -188,7 +188,7 @@ final class CreateProjectCommand extends SshCommand {
 | 
			
		||||
          input.owners = Lists.transform(ownerIds, AccountGroup.UUID::get);
 | 
			
		||||
        }
 | 
			
		||||
        if (newParent != null) {
 | 
			
		||||
          input.parent = newParent.getProject().getName();
 | 
			
		||||
          input.parent = newParent.getName();
 | 
			
		||||
        }
 | 
			
		||||
        input.permissionsOnly = permissionsOnly;
 | 
			
		||||
        input.description = projectDescription;
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,7 @@ package com.google.gerrit.sshd.commands;
 | 
			
		||||
import static com.google.gerrit.common.data.GlobalCapability.MAINTAIN_SERVER;
 | 
			
		||||
import static com.google.gerrit.common.data.GlobalCapability.RUN_GC;
 | 
			
		||||
import static com.google.gerrit.sshd.CommandMetaData.Mode.MASTER_OR_SLAVE;
 | 
			
		||||
import static java.util.stream.Collectors.toList;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.Lists;
 | 
			
		||||
import com.google.gerrit.common.data.GarbageCollectionResult;
 | 
			
		||||
@@ -24,7 +25,7 @@ import com.google.gerrit.extensions.annotations.RequiresAnyCapability;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.Project;
 | 
			
		||||
import com.google.gerrit.server.git.GarbageCollection;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectCache;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.sshd.CommandMetaData;
 | 
			
		||||
import com.google.gerrit.sshd.SshCommand;
 | 
			
		||||
import com.google.inject.Inject;
 | 
			
		||||
@@ -54,7 +55,7 @@ public class GarbageCollectionCommand extends SshCommand {
 | 
			
		||||
    metaVar = "NAME",
 | 
			
		||||
    usage = "projects for which the Git garbage collection should be run"
 | 
			
		||||
  )
 | 
			
		||||
  private List<ProjectControl> projects = new ArrayList<>();
 | 
			
		||||
  private List<ProjectState> projects = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
  @Inject private ProjectCache projectCache;
 | 
			
		||||
 | 
			
		||||
@@ -80,10 +81,7 @@ public class GarbageCollectionCommand extends SshCommand {
 | 
			
		||||
    if (all) {
 | 
			
		||||
      projectNames = Lists.newArrayList(projectCache.all());
 | 
			
		||||
    } else {
 | 
			
		||||
      projectNames = Lists.newArrayListWithCapacity(projects.size());
 | 
			
		||||
      for (ProjectControl pc : projects) {
 | 
			
		||||
        projectNames.add(pc.getProject().getNameKey());
 | 
			
		||||
      }
 | 
			
		||||
      projectNames = projects.stream().map(ProjectState::getNameKey).collect(toList());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    GarbageCollectionResult result =
 | 
			
		||||
 
 | 
			
		||||
@@ -18,8 +18,8 @@ import static com.google.gerrit.common.data.GlobalCapability.MAINTAIN_SERVER;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.extensions.annotations.RequiresAnyCapability;
 | 
			
		||||
import com.google.gerrit.server.project.Index;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectResource;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.sshd.CommandMetaData;
 | 
			
		||||
import com.google.gerrit.sshd.SshCommand;
 | 
			
		||||
import com.google.inject.Inject;
 | 
			
		||||
@@ -40,7 +40,7 @@ final class IndexProjectCommand extends SshCommand {
 | 
			
		||||
    metaVar = "PROJECT",
 | 
			
		||||
    usage = "projects for which the changes should be indexed"
 | 
			
		||||
  )
 | 
			
		||||
  private List<ProjectControl> projects = new ArrayList<>();
 | 
			
		||||
  private List<ProjectState> projects = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  protected void run() throws UnloggedFailure, Failure, Exception {
 | 
			
		||||
@@ -50,15 +50,12 @@ final class IndexProjectCommand extends SshCommand {
 | 
			
		||||
    projects.stream().forEach(this::index);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void index(ProjectControl projectControl) {
 | 
			
		||||
  private void index(ProjectState projectState) {
 | 
			
		||||
    try {
 | 
			
		||||
      index.apply(
 | 
			
		||||
          new ProjectResource(projectControl.getProjectState(), projectControl.getUser()), null);
 | 
			
		||||
      index.apply(new ProjectResource(projectState, user), null);
 | 
			
		||||
    } catch (Exception e) {
 | 
			
		||||
      writeError(
 | 
			
		||||
          "error",
 | 
			
		||||
          String.format(
 | 
			
		||||
              "Unable to index %s: %s", projectControl.getProject().getName(), e.getMessage()));
 | 
			
		||||
          "error", String.format("Unable to index %s: %s", projectState.getName(), e.getMessage()));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -25,7 +25,7 @@ import com.google.gerrit.reviewdb.client.RefNames;
 | 
			
		||||
import com.google.gerrit.server.account.AccountResolver;
 | 
			
		||||
import com.google.gerrit.server.git.GitRepositoryManager;
 | 
			
		||||
import com.google.gerrit.server.git.VisibleRefFilter;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.server.util.ManualRequestContext;
 | 
			
		||||
import com.google.gerrit.server.util.OneOffRequestContext;
 | 
			
		||||
import com.google.gerrit.sshd.CommandMetaData;
 | 
			
		||||
@@ -59,7 +59,7 @@ public class LsUserRefs extends SshCommand {
 | 
			
		||||
    required = true,
 | 
			
		||||
    usage = "project for which the refs should be listed"
 | 
			
		||||
  )
 | 
			
		||||
  private ProjectControl projectControl;
 | 
			
		||||
  private ProjectState projectState;
 | 
			
		||||
 | 
			
		||||
  @Option(
 | 
			
		||||
    name = "--user",
 | 
			
		||||
@@ -87,13 +87,13 @@ public class LsUserRefs extends SshCommand {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Project.NameKey projectName = projectControl.getProject().getNameKey();
 | 
			
		||||
    Project.NameKey projectName = projectState.getNameKey();
 | 
			
		||||
    try (Repository repo = repoManager.openRepository(projectName);
 | 
			
		||||
        ManualRequestContext ctx = requestContext.openAs(userAccount.getId())) {
 | 
			
		||||
      try {
 | 
			
		||||
        Map<String, Ref> refsMap =
 | 
			
		||||
            refFilterFactory
 | 
			
		||||
                .create(projectControl.getProjectState(), repo)
 | 
			
		||||
                .create(projectState, repo)
 | 
			
		||||
                .filter(repo.getRefDatabase().getRefs(ALL), false);
 | 
			
		||||
 | 
			
		||||
        for (String ref : refsMap.keySet()) {
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,7 @@ import com.google.gerrit.server.ChangeFinder;
 | 
			
		||||
import com.google.gerrit.server.PatchSetUtil;
 | 
			
		||||
import com.google.gerrit.server.notedb.ChangeNotes;
 | 
			
		||||
import com.google.gerrit.server.project.NoSuchChangeException;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.server.query.change.ChangeData;
 | 
			
		||||
import com.google.gerrit.server.query.change.InternalChangeQuery;
 | 
			
		||||
import com.google.gerrit.sshd.BaseCommand.UnloggedFailure;
 | 
			
		||||
@@ -57,15 +57,15 @@ public class PatchSetParser {
 | 
			
		||||
    this.changeFinder = changeFinder;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public PatchSet parsePatchSet(String token, ProjectControl projectControl, String branch)
 | 
			
		||||
  public PatchSet parsePatchSet(String token, ProjectState projectState, String branch)
 | 
			
		||||
      throws UnloggedFailure, OrmException {
 | 
			
		||||
    // By commit?
 | 
			
		||||
    //
 | 
			
		||||
    if (token.matches("^([0-9a-fA-F]{4," + RevId.LEN + "})$")) {
 | 
			
		||||
      InternalChangeQuery query = queryProvider.get();
 | 
			
		||||
      List<ChangeData> cds;
 | 
			
		||||
      if (projectControl != null) {
 | 
			
		||||
        Project.NameKey p = projectControl.getProject().getNameKey();
 | 
			
		||||
      if (projectState != null) {
 | 
			
		||||
        Project.NameKey p = projectState.getNameKey();
 | 
			
		||||
        if (branch != null) {
 | 
			
		||||
          cds = query.byBranchCommit(p.get(), branch, token);
 | 
			
		||||
        } else {
 | 
			
		||||
@@ -77,7 +77,7 @@ public class PatchSetParser {
 | 
			
		||||
      List<PatchSet> matches = new ArrayList<>(cds.size());
 | 
			
		||||
      for (ChangeData cd : cds) {
 | 
			
		||||
        Change c = cd.change();
 | 
			
		||||
        if (!(inProject(c, projectControl) && inBranch(c, branch))) {
 | 
			
		||||
        if (!(inProject(c, projectState) && inBranch(c, branch))) {
 | 
			
		||||
          continue;
 | 
			
		||||
        }
 | 
			
		||||
        for (PatchSet ps : cd.patchSets()) {
 | 
			
		||||
@@ -106,19 +106,15 @@ public class PatchSetParser {
 | 
			
		||||
      } catch (IllegalArgumentException e) {
 | 
			
		||||
        throw error("\"" + token + "\" is not a valid patch set");
 | 
			
		||||
      }
 | 
			
		||||
      ChangeNotes notes = getNotes(projectControl, patchSetId.getParentKey());
 | 
			
		||||
      ChangeNotes notes = getNotes(projectState, patchSetId.getParentKey());
 | 
			
		||||
      PatchSet patchSet = psUtil.get(db.get(), notes, patchSetId);
 | 
			
		||||
      if (patchSet == null) {
 | 
			
		||||
        throw error("\"" + token + "\" no such patch set");
 | 
			
		||||
      }
 | 
			
		||||
      if (projectControl != null || branch != null) {
 | 
			
		||||
      if (projectState != null || branch != null) {
 | 
			
		||||
        Change change = notes.getChange();
 | 
			
		||||
        if (!inProject(change, projectControl)) {
 | 
			
		||||
          throw error(
 | 
			
		||||
              "change "
 | 
			
		||||
                  + change.getId()
 | 
			
		||||
                  + " not in project "
 | 
			
		||||
                  + projectControl.getProject().getName());
 | 
			
		||||
        if (!inProject(change, projectState)) {
 | 
			
		||||
          throw error("change " + change.getId() + " not in project " + projectState.getName());
 | 
			
		||||
        }
 | 
			
		||||
        if (!inBranch(change, branch)) {
 | 
			
		||||
          throw error("change " + change.getId() + " not in branch " + branch);
 | 
			
		||||
@@ -130,10 +126,10 @@ public class PatchSetParser {
 | 
			
		||||
    throw error("\"" + token + "\" is not a valid patch set");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private ChangeNotes getNotes(@Nullable ProjectControl projectControl, Change.Id changeId)
 | 
			
		||||
  private ChangeNotes getNotes(@Nullable ProjectState projectState, Change.Id changeId)
 | 
			
		||||
      throws OrmException, UnloggedFailure {
 | 
			
		||||
    if (projectControl != null) {
 | 
			
		||||
      return notesFactory.create(db.get(), projectControl.getProject().getNameKey(), changeId);
 | 
			
		||||
    if (projectState != null) {
 | 
			
		||||
      return notesFactory.create(db.get(), projectState.getNameKey(), changeId);
 | 
			
		||||
    }
 | 
			
		||||
    try {
 | 
			
		||||
      ChangeNotes notes = changeFinder.findOne(changeId);
 | 
			
		||||
@@ -143,12 +139,12 @@ public class PatchSetParser {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static boolean inProject(Change change, ProjectControl projectControl) {
 | 
			
		||||
    if (projectControl == null) {
 | 
			
		||||
  private static boolean inProject(Change change, ProjectState projectState) {
 | 
			
		||||
    if (projectState == null) {
 | 
			
		||||
      // No --project option, so they want every project.
 | 
			
		||||
      return true;
 | 
			
		||||
    }
 | 
			
		||||
    return projectControl.getProject().getNameKey().equals(change.getProject());
 | 
			
		||||
    return projectState.getNameKey().equals(change.getProject());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static boolean inBranch(Change change, String branch) {
 | 
			
		||||
 
 | 
			
		||||
@@ -93,8 +93,7 @@ final class Receive extends AbstractGitCommand {
 | 
			
		||||
      throw new Failure(1, "fatal: unable to check permissions " + e);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    AsyncReceiveCommits arc =
 | 
			
		||||
        factory.create(projectControl.getProjectState(), currentUser, repo, null, reviewers);
 | 
			
		||||
    AsyncReceiveCommits arc = factory.create(projectState, currentUser, repo, null, reviewers);
 | 
			
		||||
 | 
			
		||||
    Capable r = arc.canUpload();
 | 
			
		||||
    if (r != Capable.OK) {
 | 
			
		||||
@@ -111,9 +110,7 @@ final class Receive extends AbstractGitCommand {
 | 
			
		||||
      // we want to present this error to the user
 | 
			
		||||
      if (badStream.getCause() instanceof TooLargeObjectInPackException) {
 | 
			
		||||
        StringBuilder msg = new StringBuilder();
 | 
			
		||||
        msg.append("Receive error on project \"")
 | 
			
		||||
            .append(projectControl.getProject().getName())
 | 
			
		||||
            .append("\"");
 | 
			
		||||
        msg.append("Receive error on project \"").append(projectState.getName()).append("\"");
 | 
			
		||||
        msg.append(" (user ");
 | 
			
		||||
        msg.append(currentUser.getAccount().getUserName());
 | 
			
		||||
        msg.append(" account ");
 | 
			
		||||
@@ -128,9 +125,7 @@ final class Receive extends AbstractGitCommand {
 | 
			
		||||
      // Log what the heck is going on, as detailed as we can.
 | 
			
		||||
      //
 | 
			
		||||
      StringBuilder msg = new StringBuilder();
 | 
			
		||||
      msg.append("Unpack error on project \"")
 | 
			
		||||
          .append(projectControl.getProject().getName())
 | 
			
		||||
          .append("\":\n");
 | 
			
		||||
      msg.append("Unpack error on project \"").append(projectState.getName()).append("\":\n");
 | 
			
		||||
 | 
			
		||||
      msg.append("  AdvertiseRefsHook: ").append(rp.getAdvertiseRefsHook());
 | 
			
		||||
      if (rp.getAdvertiseRefsHook() == AdvertiseRefsHook.DEFAULT) {
 | 
			
		||||
 
 | 
			
		||||
@@ -34,7 +34,6 @@ import com.google.gerrit.server.OutputFormat;
 | 
			
		||||
import com.google.gerrit.server.config.AllProjectsName;
 | 
			
		||||
import com.google.gerrit.server.project.NoSuchChangeException;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectCache;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.server.util.LabelVote;
 | 
			
		||||
import com.google.gerrit.sshd.CommandMetaData;
 | 
			
		||||
@@ -81,7 +80,7 @@ public class ReviewCommand extends SshCommand {
 | 
			
		||||
  )
 | 
			
		||||
  void addPatchSetId(String token) {
 | 
			
		||||
    try {
 | 
			
		||||
      PatchSet ps = psParser.parsePatchSet(token, projectControl, branch);
 | 
			
		||||
      PatchSet ps = psParser.parsePatchSet(token, projectState, branch);
 | 
			
		||||
      patchSets.add(ps);
 | 
			
		||||
    } catch (UnloggedFailure e) {
 | 
			
		||||
      throw new IllegalArgumentException(e.getMessage(), e);
 | 
			
		||||
@@ -95,7 +94,7 @@ public class ReviewCommand extends SshCommand {
 | 
			
		||||
    aliases = "-p",
 | 
			
		||||
    usage = "project containing the specified patch set(s)"
 | 
			
		||||
  )
 | 
			
		||||
  private ProjectControl projectControl;
 | 
			
		||||
  private ProjectState projectState;
 | 
			
		||||
 | 
			
		||||
  @Option(name = "--branch", aliases = "-b", usage = "branch containing the specified patch set(s)")
 | 
			
		||||
  private String branch;
 | 
			
		||||
 
 | 
			
		||||
@@ -146,7 +146,6 @@ final class SetAccountCommand extends SshCommand {
 | 
			
		||||
 | 
			
		||||
  @Inject private DeleteSshKey deleteSshKey;
 | 
			
		||||
 | 
			
		||||
  private IdentifiedUser user;
 | 
			
		||||
  private AccountResource rsrc;
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
@@ -182,7 +181,7 @@ final class SetAccountCommand extends SshCommand {
 | 
			
		||||
      throws OrmException, IOException, UnloggedFailure, ConfigInvalidException,
 | 
			
		||||
          PermissionBackendException {
 | 
			
		||||
    user = genericUserFactory.create(id);
 | 
			
		||||
    rsrc = new AccountResource(user);
 | 
			
		||||
    rsrc = new AccountResource(user.asIdentifiedUser());
 | 
			
		||||
    try {
 | 
			
		||||
      for (String email : addEmails) {
 | 
			
		||||
        addEmail(email);
 | 
			
		||||
@@ -266,7 +265,7 @@ final class SetAccountCommand extends SshCommand {
 | 
			
		||||
          ConfigInvalidException, PermissionBackendException {
 | 
			
		||||
    AccountSshKey sshKey =
 | 
			
		||||
        new AccountSshKey(new AccountSshKey.Id(user.getAccountId(), i.seq), i.sshPublicKey);
 | 
			
		||||
    deleteSshKey.apply(new AccountResource.SshKey(user, sshKey), null);
 | 
			
		||||
    deleteSshKey.apply(new AccountResource.SshKey(user.asIdentifiedUser(), sshKey), null);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void addEmail(String email)
 | 
			
		||||
@@ -288,10 +287,10 @@ final class SetAccountCommand extends SshCommand {
 | 
			
		||||
    if (email.equals("ALL")) {
 | 
			
		||||
      List<EmailInfo> emails = getEmails.apply(rsrc);
 | 
			
		||||
      for (EmailInfo e : emails) {
 | 
			
		||||
        deleteEmail.apply(new AccountResource.Email(user, e.email), new Input());
 | 
			
		||||
        deleteEmail.apply(new AccountResource.Email(user.asIdentifiedUser(), e.email), new Input());
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      deleteEmail.apply(new AccountResource.Email(user, email), new Input());
 | 
			
		||||
      deleteEmail.apply(new AccountResource.Email(user.asIdentifiedUser(), email), new Input());
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -300,7 +299,7 @@ final class SetAccountCommand extends SshCommand {
 | 
			
		||||
          ConfigInvalidException {
 | 
			
		||||
    for (EmailInfo e : getEmails.apply(rsrc)) {
 | 
			
		||||
      if (e.email.equals(email)) {
 | 
			
		||||
        putPreferred.apply(new AccountResource.Email(user, email), null);
 | 
			
		||||
        putPreferred.apply(new AccountResource.Email(user.asIdentifiedUser(), email), null);
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -15,8 +15,8 @@
 | 
			
		||||
package com.google.gerrit.sshd.commands;
 | 
			
		||||
 | 
			
		||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectResource;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.server.project.SetHead;
 | 
			
		||||
import com.google.gerrit.server.project.SetHead.Input;
 | 
			
		||||
import com.google.gerrit.sshd.CommandMetaData;
 | 
			
		||||
@@ -29,7 +29,7 @@ import org.kohsuke.args4j.Option;
 | 
			
		||||
public class SetHeadCommand extends SshCommand {
 | 
			
		||||
 | 
			
		||||
  @Argument(index = 0, required = true, metaVar = "NAME", usage = "name of the project")
 | 
			
		||||
  private ProjectControl project;
 | 
			
		||||
  private ProjectState project;
 | 
			
		||||
 | 
			
		||||
  @Option(name = "--new-head", required = true, metaVar = "REF", usage = "new HEAD reference")
 | 
			
		||||
  private String newHead;
 | 
			
		||||
@@ -46,7 +46,7 @@ public class SetHeadCommand extends SshCommand {
 | 
			
		||||
    Input input = new SetHead.Input();
 | 
			
		||||
    input.ref = newHead;
 | 
			
		||||
    try {
 | 
			
		||||
      setHead.apply(new ProjectResource(project.getProjectState(), project.getUser()), input);
 | 
			
		||||
      setHead.apply(new ProjectResource(project, user), input);
 | 
			
		||||
    } catch (UnprocessableEntityException e) {
 | 
			
		||||
      throw die(e);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -17,12 +17,11 @@ package com.google.gerrit.sshd.commands;
 | 
			
		||||
import com.google.common.base.Strings;
 | 
			
		||||
import com.google.gerrit.extensions.api.projects.ConfigInput;
 | 
			
		||||
import com.google.gerrit.extensions.client.InheritableBoolean;
 | 
			
		||||
import com.google.gerrit.extensions.client.ProjectState;
 | 
			
		||||
import com.google.gerrit.extensions.client.SubmitType;
 | 
			
		||||
import com.google.gerrit.extensions.restapi.RestApiException;
 | 
			
		||||
import com.google.gerrit.server.permissions.PermissionBackendException;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectResource;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.server.project.PutConfig;
 | 
			
		||||
import com.google.gerrit.sshd.CommandMetaData;
 | 
			
		||||
import com.google.gerrit.sshd.SshCommand;
 | 
			
		||||
@@ -33,7 +32,7 @@ import org.kohsuke.args4j.Option;
 | 
			
		||||
@CommandMetaData(name = "set-project", description = "Change a project's settings")
 | 
			
		||||
final class SetProjectCommand extends SshCommand {
 | 
			
		||||
  @Argument(index = 0, required = true, metaVar = "NAME", usage = "name of the project")
 | 
			
		||||
  private ProjectControl projectControl;
 | 
			
		||||
  private ProjectState projectState;
 | 
			
		||||
 | 
			
		||||
  @Option(
 | 
			
		||||
    name = "--description",
 | 
			
		||||
@@ -149,20 +148,18 @@ final class SetProjectCommand extends SshCommand {
 | 
			
		||||
    configInput.useContentMerge = contentMerge;
 | 
			
		||||
    configInput.useContributorAgreements = contributorAgreements;
 | 
			
		||||
    configInput.useSignedOffBy = signedOffBy;
 | 
			
		||||
    configInput.state = state;
 | 
			
		||||
    configInput.state = state.getProject().getState();
 | 
			
		||||
    configInput.maxObjectSizeLimit = maxObjectSizeLimit;
 | 
			
		||||
    // Description is different to other parameters, null won't result in
 | 
			
		||||
    // keeping the existing description, it would delete it.
 | 
			
		||||
    if (Strings.emptyToNull(projectDescription) != null) {
 | 
			
		||||
      configInput.description = projectDescription;
 | 
			
		||||
    } else {
 | 
			
		||||
      configInput.description = projectControl.getProject().getDescription();
 | 
			
		||||
      configInput.description = projectState.getProject().getDescription();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      putConfig.apply(
 | 
			
		||||
          new ProjectResource(projectControl.getProjectState(), projectControl.getUser()),
 | 
			
		||||
          configInput);
 | 
			
		||||
      putConfig.apply(new ProjectResource(projectState, user), configInput);
 | 
			
		||||
    } catch (RestApiException | PermissionBackendException e) {
 | 
			
		||||
      throw die(e);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,7 @@ import com.google.gerrit.server.change.DeleteReviewer;
 | 
			
		||||
import com.google.gerrit.server.change.PostReviewers;
 | 
			
		||||
import com.google.gerrit.server.change.ReviewerResource;
 | 
			
		||||
import com.google.gerrit.server.permissions.PermissionBackendException;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectControl;
 | 
			
		||||
import com.google.gerrit.server.project.ProjectState;
 | 
			
		||||
import com.google.gerrit.sshd.ChangeArgumentParser;
 | 
			
		||||
import com.google.gerrit.sshd.CommandMetaData;
 | 
			
		||||
import com.google.gerrit.sshd.SshCommand;
 | 
			
		||||
@@ -46,7 +46,7 @@ public class SetReviewersCommand extends SshCommand {
 | 
			
		||||
  private static final Logger log = LoggerFactory.getLogger(SetReviewersCommand.class);
 | 
			
		||||
 | 
			
		||||
  @Option(name = "--project", aliases = "-p", usage = "project containing the change")
 | 
			
		||||
  private ProjectControl projectControl;
 | 
			
		||||
  private ProjectState projectState;
 | 
			
		||||
 | 
			
		||||
  @Option(
 | 
			
		||||
    name = "--add",
 | 
			
		||||
@@ -75,7 +75,7 @@ public class SetReviewersCommand extends SshCommand {
 | 
			
		||||
  )
 | 
			
		||||
  void addChange(String token) {
 | 
			
		||||
    try {
 | 
			
		||||
      changeArgumentParser.addChange(token, changes, projectControl);
 | 
			
		||||
      changeArgumentParser.addChange(token, changes, projectState);
 | 
			
		||||
    } catch (UnloggedFailure e) {
 | 
			
		||||
      throw new IllegalArgumentException(e.getMessage(), e);
 | 
			
		||||
    } catch (OrmException e) {
 | 
			
		||||
 
 | 
			
		||||
@@ -51,8 +51,8 @@ final class Upload extends AbstractGitCommand {
 | 
			
		||||
  protected void runImpl() throws IOException, Failure {
 | 
			
		||||
    try {
 | 
			
		||||
      permissionBackend
 | 
			
		||||
          .user(projectControl.getUser())
 | 
			
		||||
          .project(projectControl.getProject().getNameKey())
 | 
			
		||||
          .user(user)
 | 
			
		||||
          .project(projectState.getNameKey())
 | 
			
		||||
          .check(ProjectPermission.RUN_UPLOAD_PACK);
 | 
			
		||||
    } catch (AuthException e) {
 | 
			
		||||
      throw new Failure(1, "fatal: upload-pack not permitted on this server");
 | 
			
		||||
@@ -61,7 +61,7 @@ final class Upload extends AbstractGitCommand {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    final UploadPack up = new UploadPack(repo);
 | 
			
		||||
    up.setAdvertiseRefsHook(refFilterFactory.create(projectControl.getProjectState(), repo));
 | 
			
		||||
    up.setAdvertiseRefsHook(refFilterFactory.create(projectState, repo));
 | 
			
		||||
    up.setPackConfig(config.getPackConfig());
 | 
			
		||||
    up.setTimeout(config.getTimeout());
 | 
			
		||||
    up.setPostUploadHook(PostUploadHookChain.newChain(Lists.newArrayList(postUploadHooks)));
 | 
			
		||||
@@ -71,7 +71,7 @@ final class Upload extends AbstractGitCommand {
 | 
			
		||||
        uploadValidatorsFactory.create(project, repo, session.getRemoteAddressAsString()));
 | 
			
		||||
    up.setPreUploadHook(PreUploadHookChain.newChain(allPreUploadHooks));
 | 
			
		||||
    for (UploadPackInitializer initializer : uploadPackInitializers) {
 | 
			
		||||
      initializer.init(projectControl.getProject().getNameKey(), up);
 | 
			
		||||
      initializer.init(projectState.getNameKey(), up);
 | 
			
		||||
    }
 | 
			
		||||
    try {
 | 
			
		||||
      up.upload(in, out, err);
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.ImmutableMap;
 | 
			
		||||
import com.google.gerrit.extensions.restapi.AuthException;
 | 
			
		||||
import com.google.gerrit.server.IdentifiedUser;
 | 
			
		||||
import com.google.gerrit.server.change.AllowedFormats;
 | 
			
		||||
import com.google.gerrit.server.change.ArchiveFormat;
 | 
			
		||||
import com.google.gerrit.server.permissions.PermissionBackend;
 | 
			
		||||
@@ -122,7 +121,6 @@ public class UploadArchive extends AbstractGitCommand {
 | 
			
		||||
 | 
			
		||||
  @Inject private PermissionBackend permissionBackend;
 | 
			
		||||
  @Inject private CommitsCollection commits;
 | 
			
		||||
  @Inject private IdentifiedUser user;
 | 
			
		||||
  @Inject private AllowedFormats allowedFormats;
 | 
			
		||||
  private Options options = new Options();
 | 
			
		||||
 | 
			
		||||
@@ -250,7 +248,7 @@ public class UploadArchive extends AbstractGitCommand {
 | 
			
		||||
      // Check reachability of the specific revision.
 | 
			
		||||
      try (RevWalk rw = new RevWalk(repo)) {
 | 
			
		||||
        RevCommit commit = rw.parseCommit(revId);
 | 
			
		||||
        return commits.canRead(state, repo, commit);
 | 
			
		||||
        return commits.canRead(projectState, repo, commit);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,6 @@ import com.google.gerrit.server.config.GerritServerConfig;
 | 
			
		||||
import com.google.gerrit.sshd.CommandModule;
 | 
			
		||||
import com.google.gerrit.sshd.SshCommand;
 | 
			
		||||
import com.google.inject.Inject;
 | 
			
		||||
import com.google.inject.Provider;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import org.eclipse.jgit.lib.Config;
 | 
			
		||||
@@ -55,15 +54,13 @@ public class LfsPluginAuthCommand extends SshCommand {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private final DynamicItem<LfsSshPluginAuth> auth;
 | 
			
		||||
  private final Provider<CurrentUser> user;
 | 
			
		||||
 | 
			
		||||
  @Argument(index = 0, multiValued = true, metaVar = "PARAMS")
 | 
			
		||||
  private List<String> args = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
  @Inject
 | 
			
		||||
  LfsPluginAuthCommand(DynamicItem<LfsSshPluginAuth> auth, Provider<CurrentUser> user) {
 | 
			
		||||
  LfsPluginAuthCommand(DynamicItem<LfsSshPluginAuth> auth) {
 | 
			
		||||
    this.auth = auth;
 | 
			
		||||
    this.user = user;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
@@ -74,6 +71,6 @@ public class LfsPluginAuthCommand extends SshCommand {
 | 
			
		||||
      throw new UnloggedFailure(1, CONFIGURATION_ERROR);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    stdout.print(pluginAuth.authenticate(user.get(), args));
 | 
			
		||||
    stdout.print(pluginAuth.authenticate(user, args));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user