Merge "Add a --no-limit option to the ssh and rest query commands"
This commit is contained in:
commit
24ee10a75f
@ -17,6 +17,7 @@ _ssh_ -p <port> <host> _gerrit query_
|
||||
[--submit-records]
|
||||
[--all-reviewers]
|
||||
[--start <n> | -S <n>]
|
||||
[--no-limit]
|
||||
[--]
|
||||
<query>
|
||||
[limit:<n>]
|
||||
@ -101,6 +102,9 @@ command line parser in the server).
|
||||
-S::
|
||||
Number of changes to skip.
|
||||
|
||||
--no-limit::
|
||||
Return all results, overriding the default limit.
|
||||
|
||||
limit:<n>::
|
||||
Maximum number of results to return. This is actually a
|
||||
query operator, and not a command line option. If more
|
||||
|
@ -350,6 +350,11 @@ be recomputed often, which is slow for projects with big trees.
|
||||
as link:#tracking-id-info[TrackingIdInfo].
|
||||
--
|
||||
|
||||
[[no-limit]]
|
||||
--
|
||||
* `NO-LIMIT`: Return all results
|
||||
--
|
||||
|
||||
.Request
|
||||
----
|
||||
GET /changes/?q=97&o=CURRENT_REVISION&o=CURRENT_COMMIT&o=CURRENT_FILES&o=DOWNLOAD_COMMANDS HTTP/1.0
|
||||
|
@ -48,6 +48,7 @@ import com.google.gerrit.common.data.LabelFunction;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelValue;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.common.data.PermissionRange;
|
||||
import com.google.gerrit.common.data.PermissionRule;
|
||||
import com.google.gerrit.common.data.PermissionRule.Action;
|
||||
import com.google.gerrit.extensions.api.GerritApi;
|
||||
@ -908,6 +909,17 @@ public abstract class AbstractDaemonTest {
|
||||
}
|
||||
}
|
||||
|
||||
protected void allowGlobalCapabilities(
|
||||
AccountGroup.UUID id, int min, int max, String... capabilityNames) throws Exception {
|
||||
try (ProjectConfigUpdate u = updateProject(allProjects)) {
|
||||
for (String capabilityName : capabilityNames) {
|
||||
Util.allow(
|
||||
u.getConfig(), capabilityName, id, new PermissionRange(capabilityName, min, max));
|
||||
}
|
||||
u.save();
|
||||
}
|
||||
}
|
||||
|
||||
protected void allowGlobalCapabilities(AccountGroup.UUID id, String... capabilityNames)
|
||||
throws Exception {
|
||||
allowGlobalCapabilities(id, Arrays.asList(capabilityNames));
|
||||
|
@ -75,6 +75,7 @@ public interface Changes {
|
||||
private String query;
|
||||
private int limit;
|
||||
private int start;
|
||||
private boolean isNoLimit;
|
||||
private EnumSet<ListChangesOption> options = EnumSet.noneOf(ListChangesOption.class);
|
||||
|
||||
public abstract List<ChangeInfo> get() throws RestApiException;
|
||||
@ -89,6 +90,11 @@ public interface Changes {
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryRequest withNoLimit() {
|
||||
this.isNoLimit = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryRequest withStart(int start) {
|
||||
this.start = start;
|
||||
return this;
|
||||
@ -120,6 +126,10 @@ public interface Changes {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public boolean getNoLimit() {
|
||||
return isNoLimit;
|
||||
}
|
||||
|
||||
public int getStart() {
|
||||
return start;
|
||||
}
|
||||
@ -140,7 +150,11 @@ public interface Changes {
|
||||
if (!options.isEmpty()) {
|
||||
sb.append("options=").append(options);
|
||||
}
|
||||
return sb.append('}').toString();
|
||||
sb.append('}');
|
||||
if (isNoLimit == true) {
|
||||
sb.append(" --no-limit");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,7 @@ public abstract class QueryProcessor<T> {
|
||||
|
||||
private boolean enforceVisibility = true;
|
||||
private int userProvidedLimit;
|
||||
private boolean isNoLimit;
|
||||
private Set<String> requestedFields;
|
||||
|
||||
protected QueryProcessor(
|
||||
@ -155,6 +156,11 @@ public abstract class QueryProcessor<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryProcessor<T> setNoLimit(boolean isNoLimit) {
|
||||
this.isNoLimit = isNoLimit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryProcessor<T> setRequestedFields(Set<String> fields) {
|
||||
requestedFields = fields;
|
||||
return this;
|
||||
@ -352,6 +358,9 @@ public abstract class QueryProcessor<T> {
|
||||
}
|
||||
|
||||
private int getEffectiveLimit(Predicate<T> p) {
|
||||
if (isNoLimit == true) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
List<Integer> possibleLimits = new ArrayList<>(4);
|
||||
possibleLimits.add(getBackendSupportedLimit());
|
||||
possibleLimits.add(getPermittedLimit());
|
||||
|
@ -116,6 +116,7 @@ class ChangesImpl implements Changes {
|
||||
}
|
||||
qc.setLimit(q.getLimit());
|
||||
qc.setStart(q.getStart());
|
||||
qc.setNoLimit(q.getNoLimit());
|
||||
for (ListChangesOption option : q.getOptions()) {
|
||||
qc.addOption(option);
|
||||
}
|
||||
|
@ -124,16 +124,28 @@ public class Util {
|
||||
|
||||
public static PermissionRule allow(
|
||||
ProjectConfig project, String capabilityName, AccountGroup.UUID group) {
|
||||
return allow(project, capabilityName, group, (PermissionRange) null);
|
||||
}
|
||||
|
||||
public static PermissionRule allow(
|
||||
ProjectConfig project,
|
||||
String capabilityName,
|
||||
AccountGroup.UUID group,
|
||||
PermissionRange customRange) {
|
||||
PermissionRule rule = newRule(project, group);
|
||||
project
|
||||
.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true)
|
||||
.getPermission(capabilityName, true)
|
||||
.add(rule);
|
||||
if (GlobalCapability.hasRange(capabilityName)) {
|
||||
PermissionRange.WithDefaults range = GlobalCapability.getRange(capabilityName);
|
||||
if (range != null) {
|
||||
rule.setRange(range.getDefaultMin(), range.getDefaultMax());
|
||||
if (customRange == null) {
|
||||
PermissionRange.WithDefaults range = GlobalCapability.getRange(capabilityName);
|
||||
if (range != null) {
|
||||
rule.setRange(range.getDefaultMin(), range.getDefaultMax());
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
rule.setRange(customRange.getMin(), customRange.getMax());
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
@ -116,6 +116,10 @@ public class OutputStreamQuery {
|
||||
queryProcessor.setUserProvidedLimit(n);
|
||||
}
|
||||
|
||||
public void setNoLimit(boolean on) {
|
||||
queryProcessor.setNoLimit(on);
|
||||
}
|
||||
|
||||
public void setStart(int n) {
|
||||
queryProcessor.setStart(n);
|
||||
}
|
||||
|
@ -82,6 +82,11 @@ public class QueryChanges implements RestReadView<TopLevelResource>, DynamicOpti
|
||||
imp.setStart(start);
|
||||
}
|
||||
|
||||
@Option(name = "--no-limit", usage = "Return all results, overriding the default limit")
|
||||
public void setNoLimit(boolean on) {
|
||||
imp.setNoLimit(on);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDynamicBean(String plugin, DynamicOptions.DynamicBean dynamicBean) {
|
||||
imp.setDynamicBean(plugin, dynamicBean);
|
||||
|
@ -91,6 +91,11 @@ public class Query extends SshCommand implements DynamicOptions.BeanReceiver {
|
||||
processor.setStart(start);
|
||||
}
|
||||
|
||||
@Option(name = "--no-limit", usage = "Return all results, overriding the default limit")
|
||||
void setNoLimit(boolean on) {
|
||||
processor.setNoLimit(on);
|
||||
}
|
||||
|
||||
@Argument(
|
||||
index = 0,
|
||||
required = true,
|
||||
|
@ -69,6 +69,7 @@ import com.google.gerrit.acceptance.testsuite.group.GroupOperations;
|
||||
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
|
||||
import com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations;
|
||||
import com.google.gerrit.common.FooterConstants;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.common.data.LabelFunction;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
@ -2488,6 +2489,19 @@ public class ChangeIT extends AbstractDaemonTest {
|
||||
assertThat(Iterables.getOnlyElement(results).changeId).isEqualTo(r2.getChangeId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryChangesNoLimit() throws Exception {
|
||||
allowGlobalCapabilities(
|
||||
SystemGroupBackend.REGISTERED_USERS, 0, 2, GlobalCapability.QUERY_LIMIT);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
createChange();
|
||||
}
|
||||
List<ChangeInfo> resultsWithDefaultLimit = gApi.changes().query().get();
|
||||
List<ChangeInfo> resultsWithNoLimit = gApi.changes().query().withNoLimit().get();
|
||||
assertThat(resultsWithDefaultLimit).hasSize(2);
|
||||
assertThat(resultsWithNoLimit.size()).isAtLeast(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryChangesStart() throws Exception {
|
||||
PushOneCommit.Result r1 = createChange();
|
||||
|
Loading…
Reference in New Issue
Block a user