use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class ChangeJson method ensureLoaded.
private void ensureLoaded(Iterable<ChangeData> all) throws OrmException {
if (lazyLoad) {
ChangeData.ensureChangeLoaded(all);
if (has(ALL_REVISIONS)) {
ChangeData.ensureAllPatchSetsLoaded(all);
} else if (has(CURRENT_REVISION) || has(MESSAGES)) {
ChangeData.ensureCurrentPatchSetLoaded(all);
}
if (has(REVIEWED) && userProvider.get().isIdentifiedUser()) {
ChangeData.ensureReviewedByLoadedForOpenChanges(all);
}
ChangeData.ensureCurrentApprovalsLoaded(all);
} else {
for (ChangeData cd : all) {
cd.setLazyLoad(false);
}
}
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class AbandonUtil method getValidChanges.
private Collection<ChangeControl> getValidChanges(Collection<ChangeControl> changeControls, String query) throws OrmException, QueryParseException {
Collection<ChangeControl> validChanges = new ArrayList<>();
for (ChangeControl cc : changeControls) {
String newQuery = query + " change:" + cc.getId();
List<ChangeData> changesToAbandon = queryProcessor.enforceVisibility(false).query(queryBuilder.parse(newQuery)).entities();
if (!changesToAbandon.isEmpty()) {
validChanges.add(cc);
} else {
log.debug("Change data with id \"{}\" does not satisfy the query \"{}\"" + " any more, hence skipping it in clean up", cc.getId(), query);
}
}
return validChanges;
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class AbandonUtil method abandonInactiveOpenChanges.
public void abandonInactiveOpenChanges(BatchUpdate.Factory updateFactory) {
if (cfg.getAbandonAfter() <= 0) {
return;
}
try {
String query = "status:new age:" + TimeUnit.MILLISECONDS.toMinutes(cfg.getAbandonAfter()) + "m";
if (!cfg.getAbandonIfMergeable()) {
query += " -is:mergeable";
}
List<ChangeData> changesToAbandon = queryProcessor.enforceVisibility(false).query(queryBuilder.parse(query)).entities();
ImmutableListMultimap.Builder<Project.NameKey, ChangeControl> builder = ImmutableListMultimap.builder();
for (ChangeData cd : changesToAbandon) {
ChangeControl control = cd.changeControl(internalUser);
builder.put(control.getProject().getNameKey(), control);
}
int count = 0;
ListMultimap<Project.NameKey, ChangeControl> abandons = builder.build();
String message = cfg.getAbandonMessage();
for (Project.NameKey project : abandons.keySet()) {
Collection<ChangeControl> changes = getValidChanges(abandons.get(project), query);
try {
abandon.batchAbandon(updateFactory, project, internalUser, changes, message);
count += changes.size();
} catch (Throwable e) {
StringBuilder msg = new StringBuilder("Failed to auto-abandon inactive change(s):");
for (ChangeControl change : changes) {
msg.append(" ").append(change.getId().get());
}
msg.append(".");
log.error(msg.toString(), e);
}
}
log.info(String.format("Auto-Abandoned %d of %d changes.", count, changesToAbandon.size()));
} catch (QueryParseException | OrmException e) {
log.error("Failed to query inactive open changes for auto-abandoning.", e);
}
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class ChangeIdHandler method parseArguments.
@Override
public final int parseArguments(final Parameters params) throws CmdLineException {
final String token = params.getParameter(0);
final String[] tokens = token.split(",");
if (tokens.length != 3) {
throw new CmdLineException(owner, "change should be specified as <project>,<branch>,<change-id>");
}
try {
final Change.Key key = Change.Key.parse(tokens[2]);
final Project.NameKey project = new Project.NameKey(tokens[0]);
final Branch.NameKey branch = new Branch.NameKey(project, tokens[1]);
for (final ChangeData cd : queryProvider.get().byBranchKey(branch, key)) {
setter.addValue(cd.getId());
return 1;
}
} catch (IllegalArgumentException e) {
throw new CmdLineException(owner, "Change-Id is not valid");
} catch (OrmException e) {
throw new CmdLineException(owner, "Database error: " + e.getMessage());
}
throw new CmdLineException(owner, "\"" + token + "\": change not found");
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class WalkSorterTest method subsetOfSeriesOfChangesWithReverseTimestamps.
@Test
public void subsetOfSeriesOfChangesWithReverseTimestamps() throws Exception {
TestRepository<Repo> p = newRepo("p");
RevCommit c0 = p.commit().tick(-1).create();
RevCommit c1 = p.commit().tick(-1).parent(c0).create();
RevCommit c2 = p.commit().tick(-1).parent(c1).create();
RevCommit c3 = p.commit().tick(-1).parent(c2).create();
RevCommit c4 = p.commit().tick(-1).parent(c3).create();
RevWalk rw = p.getRevWalk();
rw.parseCommit(c1);
assertThat(rw.parseCommit(c2).getCommitTime()).isLessThan(c1.getCommitTime());
assertThat(rw.parseCommit(c3).getCommitTime()).isLessThan(c2.getCommitTime());
assertThat(rw.parseCommit(c4).getCommitTime()).isLessThan(c3.getCommitTime());
ChangeData cd1 = newChange(p, c1);
ChangeData cd2 = newChange(p, c2);
ChangeData cd4 = newChange(p, c4);
List<ChangeData> changes = ImmutableList.of(cd1, cd2, cd4);
WalkSorter sorter = new WalkSorter(repoManager);
List<PatchSetData> expected = ImmutableList.of(patchSetData(cd4, c4), patchSetData(cd2, c2), patchSetData(cd1, c1));
for (List<ChangeData> list : permutations(changes)) {
// Not inOrder(); since child of c2 is missing, partial topo sort isn't
// guaranteed to work.
assertThat(sorter.sort(list)).containsExactlyElementsIn(expected);
}
}
Aggregations