use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.
the class ConflictsPredicate method predicates.
public static List<Predicate<ChangeData>> predicates(final Arguments args, String value, List<Change> changes) throws QueryParseException, OrmException {
int indexTerms = 0;
List<Predicate<ChangeData>> changePredicates = Lists.newArrayListWithCapacity(changes.size());
final Provider<ReviewDb> db = args.db;
for (final Change c : changes) {
final ChangeDataCache changeDataCache = new ChangeDataCache(c, db, args.changeDataFactory, args.projectCache);
List<String> files = listFiles(c, args, changeDataCache);
indexTerms += 3 + files.size();
if (indexTerms > args.indexConfig.maxTerms()) {
// later on in the query parsing.
throw new QueryParseException(TOO_MANY_FILES);
}
List<Predicate<ChangeData>> filePredicates = Lists.newArrayListWithCapacity(files.size());
for (String file : files) {
filePredicates.add(new EqualsPathPredicate(ChangeQueryBuilder.FIELD_PATH, file));
}
List<Predicate<ChangeData>> predicatesForOneChange = Lists.newArrayListWithCapacity(5);
predicatesForOneChange.add(not(new LegacyChangeIdPredicate(c.getId())));
predicatesForOneChange.add(new ProjectPredicate(c.getProject().get()));
predicatesForOneChange.add(new RefPredicate(c.getDest().get()));
predicatesForOneChange.add(or(or(filePredicates), new IsMergePredicate(args, value)));
predicatesForOneChange.add(new ChangeOperatorPredicate(ChangeQueryBuilder.FIELD_CONFLICTS, value) {
@Override
public boolean match(ChangeData object) throws OrmException {
Change otherChange = object.change();
if (otherChange == null) {
return false;
}
if (!otherChange.getDest().equals(c.getDest())) {
return false;
}
SubmitTypeRecord str = object.submitTypeRecord();
if (!str.isOk()) {
return false;
}
ObjectId other = ObjectId.fromString(object.currentPatchSet().getRevision().get());
ConflictKey conflictsKey = new ConflictKey(changeDataCache.getTestAgainst(), other, str.type, changeDataCache.getProjectState().isUseContentMerge());
Boolean conflicts = args.conflictsCache.getIfPresent(conflictsKey);
if (conflicts != null) {
return conflicts;
}
try (Repository repo = args.repoManager.openRepository(otherChange.getProject());
CodeReviewRevWalk rw = CodeReviewCommit.newRevWalk(repo)) {
conflicts = !args.submitDryRun.run(str.type, repo, rw, otherChange.getDest(), changeDataCache.getTestAgainst(), other, getAlreadyAccepted(repo, rw));
args.conflictsCache.put(conflictsKey, conflicts);
return conflicts;
} catch (IntegrationException | NoSuchProjectException | IOException e) {
throw new OrmException(e);
}
}
@Override
public int getCost() {
return 5;
}
private Set<RevCommit> getAlreadyAccepted(Repository repo, RevWalk rw) throws IntegrationException {
try {
Set<RevCommit> accepted = new HashSet<>();
SubmitDryRun.addCommits(changeDataCache.getAlreadyAccepted(repo), rw, accepted);
ObjectId tip = changeDataCache.getTestAgainst();
if (tip != null) {
accepted.add(rw.parseCommit(tip));
}
return accepted;
} catch (OrmException | IOException e) {
throw new IntegrationException("Failed to determine already accepted commits.", e);
}
}
});
changePredicates.add(and(predicatesForOneChange));
}
return changePredicates;
}
use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method newPatchSet.
protected Change newPatchSet(TestRepository<Repo> repo, Change c) throws Exception {
// Add a new file so the patch set is not a trivial rebase, to avoid default
// Code-Review label copying.
int n = c.currentPatchSetId().get() + 1;
RevCommit commit = repo.parseBody(repo.commit().message("message").add("file" + n, "contents " + n).create());
ChangeControl ctl = changeControlFactory.controlFor(db, c, user);
PatchSetInserter inserter = patchSetFactory.create(ctl, new PatchSet.Id(c.getId(), n), commit).setNotify(NotifyHandling.NONE).setFireRevisionCreated(false).setValidate(false);
try (BatchUpdate bu = updateFactory.create(db, c.getProject(), user, TimeUtil.nowTs());
ObjectInserter oi = repo.getRepository().newObjectInserter();
ObjectReader reader = oi.newReader();
RevWalk rw = new RevWalk(reader)) {
bu.setRepository(repo.getRepository(), rw, oi);
bu.addOp(c.getId(), inserter);
bu.execute();
}
return inserter.getChange();
}
use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.
the class ProjectControlTest method canReadCommitIfReachableFromVisibleRef.
@Test
public void canReadCommitIfReachableFromVisibleRef() throws Exception {
allow(project, READ, REGISTERED_USERS, "refs/heads/branch1");
deny(project, READ, REGISTERED_USERS, "refs/heads/branch2");
RevCommit parent1 = repo.commit().create();
repo.branch("branch1").commit().parent(parent1).create();
RevCommit parent2 = repo.commit().create();
repo.branch("branch2").commit().parent(parent2).create();
ProjectControl pc = newProjectControl();
RevWalk rw = repo.getRevWalk();
Repository r = repo.getRepository();
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
assertFalse(pc.canReadCommit(db, r, rw.parseCommit(parent2)));
}
use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.
the class ProjectControlTest method canReadAfterRollbackWithAllRefsVisible.
@Test
public void canReadAfterRollbackWithAllRefsVisible() throws Exception {
allow(project, READ, REGISTERED_USERS, "refs/*");
RevCommit parent1 = repo.commit().create();
ObjectId id1 = repo.branch("branch1").commit().parent(parent1).create();
ProjectControl pc = newProjectControl();
RevWalk rw = repo.getRevWalk();
Repository r = repo.getRepository();
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(id1)));
repo.branch("branch1").update(parent1);
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
assertFalse(pc.canReadCommit(db, r, rw.parseCommit(id1)));
}
use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.
the class ProjectControlTest method cannotReadAfterRollbackWithRestrictedRead.
@Test
public void cannotReadAfterRollbackWithRestrictedRead() throws Exception {
allow(project, READ, REGISTERED_USERS, "refs/heads/branch1");
RevCommit parent1 = repo.commit().create();
ObjectId id1 = repo.branch("branch1").commit().parent(parent1).create();
ProjectControl pc = newProjectControl();
RevWalk rw = repo.getRevWalk();
Repository r = repo.getRepository();
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(id1)));
repo.branch("branch1").update(parent1);
assertTrue(pc.canReadCommit(db, r, rw.parseCommit(parent1)));
assertFalse(pc.canReadCommit(db, r, rw.parseCommit(id1)));
}
Aggregations