use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class ConsistencyCheckerIT method expectedMergedCommitIsOldPatchSetOfSameChange.
@Test
public void expectedMergedCommitIsOldPatchSetOfSameChange() throws Exception {
ChangeControl ctl = insertChange();
PatchSet ps1 = psUtil.current(db, ctl.getNotes());
String rev1 = ps1.getRevision().get();
ctl = incrementPatchSet(ctl);
PatchSet ps2 = psUtil.current(db, ctl.getNotes());
testRepo.branch(ctl.getChange().getDest().get()).update(testRepo.getRevWalk().parseCommit(ObjectId.fromString(rev1)));
FixInput fix = new FixInput();
fix.expectMergedAs = rev1;
assertProblems(ctl, fix, problem("No patch set found for merged commit " + rev1, FIXED, "Marked change as merged"), problem("Expected merge commit " + rev1 + " corresponds to patch set 1," + " not the current patch set 2", FIXED, "Deleted patch set"), problem("Expected merge commit " + rev1 + " corresponds to patch set 1," + " not the current patch set 2", FIXED, "Inserted as patch set 3"));
ctl = reload(ctl);
PatchSet.Id psId3 = new PatchSet.Id(ctl.getId(), 3);
assertThat(ctl.getChange().currentPatchSetId()).isEqualTo(psId3);
assertThat(ctl.getChange().getStatus()).isEqualTo(Change.Status.MERGED);
assertThat(psUtil.byChangeAsMap(db, ctl.getNotes()).keySet()).containsExactly(ps2.getId(), psId3);
assertThat(psUtil.get(db, ctl.getNotes(), psId3).getRevision().get()).isEqualTo(rev1);
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class ApprovalCopier method getPatchSets.
private static TreeMap<Integer, PatchSet> getPatchSets(ChangeData cd) throws OrmException {
Collection<PatchSet> patchSets = cd.patchSets();
TreeMap<Integer, PatchSet> result = new TreeMap<>();
for (PatchSet ps : patchSets) {
result.put(ps.getId().get(), ps);
}
return result;
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class CommentsUtil method publish.
public void publish(ChangeContext ctx, PatchSet.Id psId, Collection<Comment> drafts, @Nullable String tag) throws OrmException {
ChangeNotes notes = ctx.getNotes();
checkArgument(notes != null);
if (drafts.isEmpty()) {
return;
}
Map<PatchSet.Id, PatchSet> patchSets = psUtil.getAsMap(ctx.getDb(), notes, drafts.stream().map(d -> psId(notes, d)).collect(toSet()));
for (Comment d : drafts) {
PatchSet ps = patchSets.get(psId(notes, d));
if (ps == null) {
throw new OrmException("patch set " + ps + " not found");
}
d.writtenOn = ctx.getWhen();
d.tag = tag;
// Draft may have been created by a different real user; copy the current real user. (Only
// applies to X-Gerrit-RunAs, since modifying drafts via on_behalf_of is not allowed.)
ctx.getUser().updateRealAccountId(d::setRealAuthor);
setCommentRevId(d, patchListCache, notes.getChange(), ps);
}
putComments(ctx.getDb(), ctx.getUpdate(psId), PUBLISHED, drafts);
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class Mergeable method apply.
@Override
public MergeableInfo apply(RevisionResource resource) throws AuthException, ResourceConflictException, BadRequestException, OrmException, IOException {
Change change = resource.getChange();
PatchSet ps = resource.getPatchSet();
MergeableInfo result = new MergeableInfo();
if (!change.getStatus().isOpen()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} else if (!ps.getId().equals(change.currentPatchSetId())) {
// Only the current revision is mergeable. Others always fail.
return result;
}
ChangeData cd = changeDataFactory.create(db.get(), resource.getControl());
result.submitType = getSubmitType(cd, ps);
try (Repository git = gitManager.openRepository(change.getProject())) {
ObjectId commit = toId(ps);
Ref ref = git.getRefDatabase().exactRef(change.getDest().get());
ProjectState projectState = projectCache.get(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<>();
BranchOrderSection branchOrder = projectState.getBranchOrderSection();
if (branchOrder != null) {
int prefixLen = Constants.R_HEADS.length();
String[] names = branchOrder.getMoreStable(ref.getName());
Map<String, Ref> refs = git.getRefDatabase().exactRef(names);
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 result;
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class Rebase method getDescription.
@Override
public UiAction.Description getDescription(RevisionResource resource) {
PatchSet patchSet = resource.getPatchSet();
Change change = resource.getChange();
Branch.NameKey dest = change.getDest();
boolean visible = change.getStatus().isOpen() && resource.isCurrent() && resource.permissions().database(dbProvider).testOrFalse(ChangePermission.REBASE);
boolean enabled = true;
if (visible) {
try (Repository repo = repoManager.openRepository(dest.getParentKey());
RevWalk rw = new RevWalk(repo)) {
visible = hasOneParent(rw, resource.getPatchSet());
enabled = rebaseUtil.canRebase(patchSet, dest, repo, rw);
} catch (IOException e) {
log.error("Failed to check if patch set can be rebased: " + resource.getPatchSet(), e);
visible = false;
}
}
return new UiAction.Description().setLabel("Rebase").setTitle("Rebase onto tip of branch or parent change").setVisible(visible).setEnabled(enabled);
}
Aggregations