Merge "Add 'is:merge' operator to find changes which are merge commits" into stable-3.2

This commit is contained in:
Saša Živkov
2020-05-08 18:58:37 +00:00
committed by Gerrit Code Review
6 changed files with 64 additions and 0 deletions

View File

@@ -696,6 +696,19 @@ public class ChangeField {
return m ? "1" : "0";
});
/** Whether the change is a merge commit. */
public static final FieldDef<ChangeData, String> MERGE =
exact(ChangeQueryBuilder.FIELD_MERGE)
.stored()
.build(
cd -> {
Boolean m = cd.isMerge();
if (m == null) {
return null;
}
return m ? "1" : "0";
});
/** The number of inserted lines in this change. */
public static final FieldDef<ChangeData, Integer> ADDED =
intRange(ChangeQueryBuilder.FIELD_ADDED)

View File

@@ -121,6 +121,7 @@ public class ChangeSchemaDefinitions extends SchemaDefinitions<ChangeData> {
* Added new fields {@link ChangeField#ATTENTION_SET_USERS} and {@link
* ChangeField#ATTENTION_SET_FULL}.
*/
@Deprecated
static final Schema<ChangeData> V59 =
new Schema.Builder<ChangeData>()
.add(V58)
@@ -128,6 +129,10 @@ public class ChangeSchemaDefinitions extends SchemaDefinitions<ChangeData> {
.add(ChangeField.ATTENTION_SET_FULL)
.build();
/** Added new fields {@link ChangeField#MERGE} */
static final Schema<ChangeData> V60 =
new Schema.Builder<ChangeData>().add(V59).add(ChangeField.MERGE).build();
/**
* Name of the change index to be used when contacting index backends or loading configurations.
*/

View File

@@ -284,6 +284,7 @@ public class ChangeData {
private Optional<ChangedLines> changedLines;
private SubmitTypeRecord submitTypeRecord;
private Boolean mergeable;
private Boolean merge;
private Set<String> hashtags;
private Map<Account.Id, Ref> editsByUser;
private Set<Account.Id> reviewedBy;
@@ -953,6 +954,16 @@ public class ChangeData {
return mergeable;
}
@Nullable
public Boolean isMerge() {
if (merge == null) {
if (!loadCommitData()) {
return null;
}
}
return parentCount > 1;
}
public Set<Account.Id> editsByUser() {
return editRefs().keySet();
}

View File

@@ -597,6 +597,13 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData, ChangeQueryBuil
return new BooleanPredicate(ChangeField.MERGEABLE);
}
if ("merge".equalsIgnoreCase(value)) {
if (args.getSchema().hasField(ChangeField.MERGE)) {
return new BooleanPredicate(ChangeField.MERGE);
}
throw new QueryParseException("'is:merge' operator is not supported by change index version");
}
if ("private".equalsIgnoreCase(value)) {
if (args.getSchema().hasField(ChangeField.PRIVATE)) {
return new BooleanPredicate(ChangeField.PRIVATE);