use of com.google.gerrit.server.project.ProjectControl in project gerrit by GerritCodeReview.
the class ListGroups method getAllGroups.
private List<GroupInfo> getAllGroups() throws OrmException {
List<GroupInfo> groupInfos;
List<AccountGroup> groupList;
if (!projects.isEmpty()) {
Map<AccountGroup.UUID, AccountGroup> groups = new HashMap<>();
for (final ProjectControl projectControl : projects) {
final Set<GroupReference> groupsRefs = projectControl.getAllGroups();
for (final GroupReference groupRef : groupsRefs) {
final AccountGroup group = groupCache.get(groupRef.getUUID());
if (group != null) {
groups.put(group.getGroupUUID(), group);
}
}
}
groupList = filterGroups(groups.values());
} else {
groupList = filterGroups(groupCache.all());
}
groupInfos = Lists.newArrayListWithCapacity(groupList.size());
int found = 0;
int foundIndex = 0;
for (AccountGroup group : groupList) {
if (foundIndex++ < start) {
continue;
}
if (limit > 0 && ++found > limit) {
break;
}
groupInfos.add(json.addOptions(options).format(GroupDescriptions.forAccountGroup(group)));
}
return groupInfos;
}
use of com.google.gerrit.server.project.ProjectControl in project gerrit by GerritCodeReview.
the class ReviewCommand method parseCommandLine.
@Override
protected void parseCommandLine() throws UnloggedFailure {
optionList = new ArrayList<>();
customLabels = new HashMap<>();
ProjectControl allProjectsControl;
try {
allProjectsControl = projectControlFactory.controlFor(allProjects);
} catch (NoSuchProjectException e) {
throw die("missing " + allProjects.get());
}
for (LabelType type : allProjectsControl.getLabelTypes().getLabelTypes()) {
StringBuilder usage = new StringBuilder("score for ").append(type.getName()).append("\n");
for (LabelValue v : type.getValues()) {
usage.append(v.format()).append("\n");
}
final String name = "--" + type.getName().toLowerCase();
optionList.add(new ApproveOption(name, usage.toString(), type));
}
super.parseCommandLine();
}
use of com.google.gerrit.server.project.ProjectControl in project gerrit by GerritCodeReview.
the class LsUserRefs method run.
@Override
protected void run() throws Failure {
Account userAccount;
try {
userAccount = accountResolver.find(db, userName);
} catch (OrmException e) {
throw die(e);
}
if (userAccount == null) {
stdout.print("No single user could be found when searching for: " + userName + '\n');
stdout.flush();
return;
}
IdentifiedUser user = userFactory.create(userAccount.getId());
ProjectControl userProjectControl = projectControl.forUser(user);
try (Repository repo = repoManager.openRepository(userProjectControl.getProject().getNameKey())) {
try {
Map<String, Ref> refsMap = new VisibleRefFilter(tagCache, changeNotesFactory, changeCache, repo, userProjectControl, db, true).filter(repo.getRefDatabase().getRefs(ALL), false);
for (final String ref : refsMap.keySet()) {
if (!onlyRefsHeads || ref.startsWith(RefNames.REFS_HEADS)) {
stdout.println(ref);
}
}
} catch (IOException e) {
throw new Failure(1, "fatal: Error reading refs: '" + projectControl.getProject().getNameKey(), e);
}
} catch (RepositoryNotFoundException e) {
throw die("'" + projectControl.getProject().getNameKey() + "': not a git archive");
} catch (IOException e) {
throw die("Error opening: '" + projectControl.getProject().getNameKey());
}
}
use of com.google.gerrit.server.project.ProjectControl in project gerrit by GerritCodeReview.
the class RelatedChangesSorter method sort.
public List<PatchSetData> sort(List<ChangeData> in, PatchSet startPs) throws OrmException, IOException {
checkArgument(!in.isEmpty(), "Input may not be empty");
// Map of all patch sets, keyed by commit SHA-1.
Map<String, PatchSetData> byId = collectById(in);
PatchSetData start = byId.get(startPs.getRevision().get());
checkArgument(start != null, "%s not found in %s", startPs, in);
ProjectControl ctl = start.data().changeControl().getProjectControl();
// Map of patch set -> immediate parent.
ListMultimap<PatchSetData, PatchSetData> parents = MultimapBuilder.hashKeys(in.size()).arrayListValues(3).build();
// Map of patch set -> immediate children.
ListMultimap<PatchSetData, PatchSetData> children = MultimapBuilder.hashKeys(in.size()).arrayListValues(3).build();
// All other patch sets of the same change as startPs.
List<PatchSetData> otherPatchSetsOfStart = new ArrayList<>();
for (ChangeData cd : in) {
for (PatchSet ps : cd.patchSets()) {
PatchSetData thisPsd = checkNotNull(byId.get(ps.getRevision().get()));
if (cd.getId().equals(start.id()) && !ps.getId().equals(start.psId())) {
otherPatchSetsOfStart.add(thisPsd);
}
for (RevCommit p : thisPsd.commit().getParents()) {
PatchSetData parentPsd = byId.get(p.name());
if (parentPsd != null) {
parents.put(thisPsd, parentPsd);
children.put(parentPsd, thisPsd);
}
}
}
}
Collection<PatchSetData> ancestors = walkAncestors(ctl, parents, start);
List<PatchSetData> descendants = walkDescendants(ctl, children, start, otherPatchSetsOfStart, ancestors);
List<PatchSetData> result = new ArrayList<>(ancestors.size() + descendants.size() - 1);
result.addAll(Lists.reverse(descendants));
result.addAll(ancestors);
return result;
}
use of com.google.gerrit.server.project.ProjectControl in project gerrit by GerritCodeReview.
the class Revert method applyImpl.
@Override
protected ChangeInfo applyImpl(BatchUpdate.Factory updateFactory, ChangeResource req, RevertInput input) throws IOException, OrmException, RestApiException, UpdateException, NoSuchChangeException {
RefControl refControl = req.getControl().getRefControl();
ProjectControl projectControl = req.getControl().getProjectControl();
Capable capable = projectControl.canPushToAtLeastOneRef();
if (capable != Capable.OK) {
throw new AuthException(capable.getMessage());
}
Change change = req.getChange();
if (!refControl.canUpload()) {
throw new AuthException("revert not permitted");
} else if (change.getStatus() != Status.MERGED) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change));
}
Change.Id revertedChangeId = revert(updateFactory, req.getControl(), Strings.emptyToNull(input.message));
return json.noOptions().format(req.getProject(), revertedChangeId);
}
Aggregations