use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.
the class Restore method getDescription.
@Override
public UiAction.Description getDescription(ChangeResource rsrc) throws IOException {
UiAction.Description description = new UiAction.Description().setLabel("Restore").setTitle("Restore the change").setVisible(false);
Change change = rsrc.getChange();
if (!change.isAbandoned()) {
return description;
}
if (!projectCache.get(rsrc.getProject()).map(ProjectState::statePermitsRead).orElse(false)) {
return description;
}
if (psUtil.isPatchSetLocked(rsrc.getNotes())) {
return description;
}
boolean visible = rsrc.permissions().testOrFalse(ChangePermission.RESTORE);
return description.setVisible(visible);
}
use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.
the class GetFixPreview method apply.
@Override
public Response<Map<String, DiffInfo>> apply(FixResource resource) throws PermissionBackendException, ResourceNotFoundException, ResourceConflictException, AuthException, IOException, InvalidChangeOperationException {
Map<String, DiffInfo> result = new HashMap<>();
PatchSet patchSet = resource.getRevisionResource().getPatchSet();
ChangeNotes notes = resource.getRevisionResource().getNotes();
Change change = notes.getChange();
ProjectState state = projectCache.get(change.getProject()).orElseThrow(illegalState(change.getProject()));
Map<String, List<FixReplacement>> fixReplacementsPerFilePath = resource.getFixReplacements().stream().collect(groupingBy(fixReplacement -> fixReplacement.path));
try {
try (Repository git = repoManager.openRepository(notes.getProjectName())) {
for (Map.Entry<String, List<FixReplacement>> entry : fixReplacementsPerFilePath.entrySet()) {
String fileName = entry.getKey();
DiffInfo diffInfo = getFixPreviewForSingleFile(git, patchSet, state, notes, fileName, ImmutableList.copyOf(entry.getValue()));
result.put(fileName, diffInfo);
}
}
} catch (NoSuchChangeException e) {
throw new ResourceNotFoundException(e.getMessage(), e);
} catch (LargeObjectException e) {
throw new ResourceConflictException(e.getMessage(), e);
}
return Response.ok(result);
}
use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.
the class Mergeable method apply.
@Override
public Response<MergeableInfo> apply(RevisionResource resource) throws AuthException, ResourceConflictException, BadRequestException, IOException {
Change change = resource.getChange();
PatchSet ps = resource.getPatchSet();
MergeableInfo result = new MergeableInfo();
if (!change.isNew()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} else if (!ps.id().equals(change.currentPatchSetId())) {
// Only the current revision is mergeable. Others always fail.
return Response.ok(result);
}
ChangeData cd = changeDataFactory.create(resource.getNotes());
result.submitType = getSubmitType(cd);
try (Repository git = gitManager.openRepository(change.getProject())) {
ObjectId commit = ps.commitId();
Ref ref = git.getRefDatabase().exactRef(change.getDest().branch());
ProjectState projectState = projectCache.get(change.getProject()).orElseThrow(illegalState(change.getProject()));
String strategy = mergeUtilFactory.create(projectState).mergeStrategyName();
result.strategy = strategy;
result.mergeable = isMergable(git, change, commit, ref, result.submitType, strategy);
if (otherBranches) {
result.mergeableInto = new ArrayList<>();
Optional<BranchOrderSection> branchOrder = projectState.getBranchOrderSection();
if (branchOrder.isPresent()) {
int prefixLen = Constants.R_HEADS.length();
List<String> names = branchOrder.get().getMoreStable(ref.getName());
Map<String, Ref> refs = git.getRefDatabase().exactRef(names.toArray(new String[names.size()]));
for (String n : names) {
Ref other = refs.get(n);
if (other == null) {
continue;
}
if (cache.get(commit, other, SubmitType.CHERRY_PICK, strategy, change.getDest(), git)) {
result.mergeableInto.add(other.getName().substring(prefixLen));
}
}
}
}
}
return Response.ok(result);
}
use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.
the class SubmitStrategyOp method postUpdate.
@Override
public final void postUpdate(PostUpdateContext ctx) throws Exception {
if (changeAlreadyMerged) {
// TODO(dborowitz): This is suboptimal behavior in the presence of retries: postUpdate steps
// will never get run for changes that submitted successfully on any but the final attempt.
// This is primarily a temporary workaround for the fact that the submitter field is not
// populated in the changeAlreadyMerged case.
//
// If we naively execute postUpdate even if the change is already merged when updateChange
// being, then we are subject to a race where postUpdate steps are run twice if two submit
// processes run at the same time.
logger.atFine().log("Skipping post-update steps for change %s; submitter is %s", getId(), submitter);
return;
}
logger.atFine().log("Begin post-update steps for change %s; submitter is %s", getId(), submitter);
postUpdateImpl(ctx);
if (command != null) {
args.tagCache.updateFastForward(getProject(), command.getRefName(), command.getOldId(), command.getNewId());
// per project even if multiple changes to refs/meta/config are submitted.
if (RefNames.REFS_CONFIG.equals(getDest().branch())) {
args.projectCache.evictAndReindex(getProject());
ProjectState p = args.projectCache.get(getProject()).orElseThrow(illegalState(getProject()));
try (Repository git = args.repoManager.openRepository(getProject())) {
git.setGitwebDescription(p.getProject().getDescription());
} catch (IOException e) {
logger.atSevere().withCause(e).log("cannot update description of %s", p.getName());
}
}
}
logger.atFine().log("Begin sending emails for submitting change %s; submitter is %s", getId(), submitter);
// have failed fast in one of the other steps.
try {
args.mergedSenderFactory.create(ctx.getProject(), toMerge.change(), args.caller, ctx.getNotify(getId()), ctx.getRepoView(), stickyApprovalDiff).sendAsync();
} catch (Exception e) {
logger.atSevere().withCause(e).log("Cannot email merged notification for %s", getId());
}
if (mergeResultRev != null && !args.dryrun) {
args.changeMerged.fire(ctx.getChangeData(updatedChange), mergedPatchSet, args.accountCache.get(submitter.accountId()).orElse(null), args.mergeTip.getCurrentTip().name(), ctx.getWhen());
}
}
use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.
the class MergeOpRepoManager method getRepo.
public OpenRepo getRepo(Project.NameKey project) throws NoSuchProjectException, IOException {
if (openRepos.containsKey(project)) {
return openRepos.get(project);
}
ProjectState projectState = projectCache.get(project).orElseThrow(noSuchProject(project));
try {
OpenRepo or = new OpenRepo(repoManager.openRepository(project), projectState);
openRepos.put(project, or);
return or;
} catch (RepositoryNotFoundException e) {
throw new NoSuchProjectException(project, e);
}
}
Aggregations