use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class GetRelated method getRelated.
private List<ChangeAndCommit> getRelated(RevisionResource rsrc) throws OrmException, IOException {
Set<String> groups = getAllGroups(rsrc.getNotes());
if (groups.isEmpty()) {
return Collections.emptyList();
}
List<ChangeData> cds = queryProvider.get().enforceVisibility(true).byProjectGroups(rsrc.getChange().getProject(), groups);
if (cds.isEmpty()) {
return Collections.emptyList();
}
if (cds.size() == 1 && cds.get(0).getId().equals(rsrc.getChange().getId())) {
return Collections.emptyList();
}
List<ChangeAndCommit> result = new ArrayList<>(cds.size());
boolean isEdit = rsrc.getEdit().isPresent();
PatchSet basePs = isEdit ? rsrc.getEdit().get().getBasePatchSet() : rsrc.getPatchSet();
reloadChangeIfStale(cds, basePs);
for (PatchSetData d : sorter.sort(cds, basePs)) {
PatchSet ps = d.patchSet();
RevCommit commit;
if (isEdit && ps.getId().equals(basePs.getId())) {
// Replace base of an edit with the edit itself.
ps = rsrc.getPatchSet();
commit = rsrc.getEdit().get().getEditCommit();
} else {
commit = d.commit();
}
result.add(new ChangeAndCommit(d.data().change(), ps, commit));
}
if (result.size() == 1) {
ChangeAndCommit r = result.get(0);
if (r.commit != null && r.commit.commit.equals(rsrc.getPatchSet().getRevision().get())) {
return Collections.emptyList();
}
}
return result;
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class ListChangeDrafts method apply.
@Override
public Map<String, List<CommentInfo>> apply(ChangeResource rsrc) throws AuthException, OrmException {
if (!rsrc.getControl().getUser().isIdentifiedUser()) {
throw new AuthException("Authentication required");
}
ChangeData cd = changeDataFactory.create(db.get(), rsrc.getControl());
List<Comment> drafts = commentsUtil.draftByChangeAuthor(db.get(), cd.notes(), rsrc.getControl().getUser().getAccountId());
return commentJson.get().setFillAccounts(false).setFillPatchSet(true).newCommentFormatter().format(drafts);
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class StalenessChecker method isStale.
public boolean isStale(Change.Id id) throws IOException, OrmException {
ChangeIndex i = indexes.getSearchIndex();
if (i == null) {
// No index; caller couldn't do anything if it is stale.
return false;
}
if (!i.getSchema().hasField(ChangeField.REF_STATE) || !i.getSchema().hasField(ChangeField.REF_STATE_PATTERN)) {
// Index version not new enough for this check.
return false;
}
Optional<ChangeData> result = i.get(id, IndexedChangeQuery.createOptions(indexConfig, 0, 1, FIELDS));
if (!result.isPresent()) {
// Not in index, but caller wants it to be.
return true;
}
ChangeData cd = result.get();
return isStale(repoManager, id, cd.change(), ChangeNotes.readOneReviewDbChange(db.get(), id), parseStates(cd), parsePatterns(cd));
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class ChangeIndexRewriter method rewriteImpl.
/**
* Rewrite a single predicate subtree.
*
* @param in predicate to rewrite.
* @param index index whose schema determines which fields are indexed.
* @param opts other query options.
* @param leafTerms number of leaf index query terms encountered so far.
* @return {@code null} if no part of this subtree can be queried in the index directly. {@code
* in} if this subtree and all its children can be queried directly in the index. Otherwise, a
* predicate that is semantically equivalent, with some of its subtrees wrapped to query the
* index directly.
* @throws QueryParseException if the underlying index implementation does not support this
* predicate.
*/
private Predicate<ChangeData> rewriteImpl(Predicate<ChangeData> in, ChangeIndex index, QueryOptions opts, MutableInteger leafTerms) throws QueryParseException {
if (isIndexPredicate(in, index)) {
if (++leafTerms.value > config.maxTerms()) {
throw new QueryParseException("too many terms in query");
}
return in;
} else if (in instanceof LimitPredicate) {
// and included that in their limit computation.
return new LimitPredicate<>(ChangeQueryBuilder.FIELD_LIMIT, opts.limit());
} else if (!isRewritePossible(in)) {
if (in instanceof IndexPredicate) {
throw new QueryParseException("Unsupported index predicate: " + in.toString());
}
// magic to indicate "in" cannot be rewritten
return null;
}
int n = in.getChildCount();
BitSet isIndexed = new BitSet(n);
BitSet notIndexed = new BitSet(n);
BitSet rewritten = new BitSet(n);
List<Predicate<ChangeData>> newChildren = Lists.newArrayListWithCapacity(n);
for (int i = 0; i < n; i++) {
Predicate<ChangeData> c = in.getChild(i);
Predicate<ChangeData> nc = rewriteImpl(c, index, opts, leafTerms);
if (nc == c) {
isIndexed.set(i);
newChildren.add(c);
} else if (nc == null) /* cannot rewrite c */
{
notIndexed.set(i);
newChildren.add(c);
} else {
rewritten.set(i);
newChildren.add(nc);
}
}
if (isIndexed.cardinality() == n) {
// All children are indexed, leave as-is for parent.
return in;
} else if (notIndexed.cardinality() == n) {
// Can't rewrite any children, so cannot rewrite in.
return null;
} else if (rewritten.cardinality() == n) {
// All children were rewritten.
return in.copy(newChildren);
}
return partitionChildren(in, newChildren, isIndexed, index, opts);
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class ChangeIndexRewriter method rewriteImpl.
private Predicate<ChangeData> rewriteImpl(Predicate<ChangeData> in, QueryOptions opts) throws QueryParseException {
ChangeIndex index = indexes.getSearchIndex();
MutableInteger leafTerms = new MutableInteger();
Predicate<ChangeData> out = rewriteImpl(in, index, opts, leafTerms);
if (in == out || out instanceof IndexPredicate) {
return new IndexedChangeQuery(index, out, opts);
} else if (out == null) /* cannot rewrite */
{
return in;
} else {
return out;
}
}
Aggregations