use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class ChangeIndexer method indexImpl.
private void indexImpl(ChangeData cd) {
logger.atFine().log("Reindex change %d in index.", cd.getId().get());
for (Index<?, ChangeData> i : getWriteIndexes()) {
try (TraceTimer traceTimer = TraceContext.newTimer("Reindexing change in index", Metadata.builder().changeId(cd.getId().get()).patchSetId(cd.currentPatchSet().number()).indexVersion(i.getSchema().getVersion()).build())) {
if (isFirstInsertForEntry.equals(IsFirstInsertForEntry.YES)) {
i.insert(cd);
} else {
i.replace(cd);
}
} catch (RuntimeException e) {
throw new StorageException(String.format("Failed to reindex change %d in index version %d (current patch set = %d)", cd.getId().get(), i.getSchema().getVersion(), cd.currentPatchSet().number()), e);
}
}
fireChangeIndexedEvent(cd.project().get(), cd.getId().get());
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class IndexedChangeQuery method read.
@Override
public ResultSet<ChangeData> read() {
final DataSource<ChangeData> currSource = source;
final ResultSet<ChangeData> rs = currSource.read();
return new ResultSet<>() {
@Override
public Iterator<ChangeData> iterator() {
return Iterables.transform(rs, cd -> {
fromSource.put(cd, currSource);
return cd;
}).iterator();
}
@Override
public ImmutableList<ChangeData> toList() {
ImmutableList<ChangeData> r = rs.toList();
for (ChangeData cd : r) {
fromSource.put(cd, currSource);
}
return r;
}
@Override
public void close() {
rs.close();
}
};
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class StalenessChecker method check.
/**
* Returns a {@link StalenessCheckResult} with structured information about staleness of the
* provided {@link com.google.gerrit.entities.Change.Id}.
*/
public StalenessCheckResult check(Change.Id id) {
ChangeIndex i = indexes.getSearchIndex();
if (i == null) {
return StalenessCheckResult.notStale();
}
if (!i.getSchema().hasField(ChangeField.REF_STATE) || !i.getSchema().hasField(ChangeField.REF_STATE_PATTERN)) {
// Index version not new enough for this check.
return StalenessCheckResult.notStale();
}
Optional<ChangeData> result = i.get(id, IndexedChangeQuery.createOptions(indexConfig, 0, 1, FIELDS));
if (!result.isPresent()) {
return StalenessCheckResult.stale("Document %s missing from index", id);
}
ChangeData cd = result.get();
return check(repoManager, id, cd.getRefStates(), parsePatterns(cd));
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class Submit method unmergeableChanges.
public Collection<ChangeData> unmergeableChanges(ChangeSet cs) throws IOException {
Set<ChangeData> mergeabilityMap = new HashSet<>();
Set<ObjectId> outDatedPatchsets = new HashSet<>();
for (ChangeData change : cs.changes()) {
mergeabilityMap.add(change);
// Add all the patchsets commit ids except the current patchset.
outDatedPatchsets.addAll(change.notes().getPatchSets().values().stream().map(p -> p.commitId()).collect(Collectors.toSet()));
outDatedPatchsets.remove(change.currentPatchSet().commitId());
}
ListMultimap<BranchNameKey, ChangeData> cbb = cs.changesByBranch();
for (BranchNameKey branch : cbb.keySet()) {
Collection<ChangeData> targetBranch = cbb.get(branch);
HashMap<Change.Id, RevCommit> commits = findCommits(targetBranch, branch.project());
Set<ObjectId> allParents = Sets.newHashSetWithExpectedSize(cs.size());
for (RevCommit commit : commits.values()) {
for (RevCommit parent : commit.getParents()) {
allParents.add(parent.getId());
}
}
for (ChangeData change : targetBranch) {
RevCommit commit = commits.get(change.getId());
boolean isMergeCommit = commit.getParentCount() > 1;
boolean isLastInChain = !allParents.contains(commit.getId());
if (Arrays.stream(commit.getParents()).anyMatch(c -> outDatedPatchsets.contains(c.getId())) && !isCherryPickSubmit(change)) {
// cherry-pick.
continue;
}
// Recheck mergeability rather than using value stored in the index,
// which may be stale.
// TODO(dborowitz): This is ugly; consider providing a way to not read
// stored fields from the index in the first place.
change.setMergeable(null);
Boolean mergeable = change.isMergeable();
if (mergeable == null) {
// Skip whole check, cannot determine if mergeable
return null;
}
if (mergeable) {
mergeabilityMap.remove(change);
}
if (isLastInChain && isMergeCommit && mergeable) {
for (ChangeData c : targetBranch) {
mergeabilityMap.remove(c);
}
break;
}
}
}
return mergeabilityMap;
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class Submit method findCommits.
private HashMap<Change.Id, RevCommit> findCommits(Collection<ChangeData> changes, Project.NameKey project) throws IOException {
HashMap<Change.Id, RevCommit> commits = new HashMap<>();
try (Repository repo = repoManager.openRepository(project);
RevWalk walk = new RevWalk(repo)) {
for (ChangeData change : changes) {
RevCommit commit = walk.parseCommit(psUtil.current(change.notes()).commitId());
commits.put(change.getId(), commit);
}
}
return commits;
}
Aggregations