Merge changes Id768b4f1,Iba8447f6

* changes:
  Display only mergeable changes in Conflicts With tab
  Add 'is:mergeable' operator to find changes without merge conflict
This commit is contained in:
Shawn Pearce
2013-11-24 08:00:42 +00:00
committed by Gerrit Code Review
7 changed files with 90 additions and 2 deletions

View File

@@ -349,6 +349,17 @@ public class ChangeField {
}
};
/** Whether the change is mergeable. */
public static final FieldDef<ChangeData, String> MERGEABLE =
new FieldDef.Single<ChangeData, String>(
ChangeQueryBuilder.FIELD_MERGEABLE, FieldType.EXACT, false) {
@Override
public String get(ChangeData input, FillArgs args)
throws OrmException {
return input.change(args.db).isMergeable() ? "1" : null;
}
};
private static <T> List<byte[]> toProtos(ProtobufCodec<T> codec, Collection<T> objs)
throws OrmException {
List<byte[]> result = Lists.newArrayListWithCapacity(objs.size());

View File

@@ -97,6 +97,29 @@ public class ChangeSchemas {
// For upgrade to Lucene 4.4.0 index format only.
static final Schema<ChangeData> V4 = release(V3.getFields().values());
@SuppressWarnings("unchecked")
static final Schema<ChangeData> V5 = release(
ChangeField.LEGACY_ID,
ChangeField.ID,
ChangeField.STATUS,
ChangeField.PROJECT,
ChangeField.REF,
ChangeField.TOPIC,
ChangeField.UPDATED,
ChangeField.SORTKEY,
ChangeField.FILE,
ChangeField.OWNER,
ChangeField.REVIEWER,
ChangeField.COMMIT,
ChangeField.TR,
ChangeField.LABEL,
ChangeField.REVIEWED,
ChangeField.COMMIT_MESSAGE,
ChangeField.COMMENT,
ChangeField.CHANGE,
ChangeField.APPROVAL,
ChangeField.MERGEABLE);
private static Schema<ChangeData> release(Collection<FieldDef<ChangeData, ?>> fields) {
return new Schema<ChangeData>(true, fields);
}

View File

@@ -93,6 +93,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
public static final String FIELD_HAS = "has";
public static final String FIELD_LABEL = "label";
public static final String FIELD_LIMIT = "limit";
public static final String FIELD_MERGEABLE = "mergeable";
public static final String FIELD_MESSAGE = "message";
public static final String FIELD_OWNER = "owner";
public static final String FIELD_OWNERIN = "ownerin";
@@ -280,7 +281,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
}
@Operator
public Predicate<ChangeData> is(String value) {
public Predicate<ChangeData> is(String value) throws QueryParseException {
if ("starred".equalsIgnoreCase(value)) {
return new IsStarredByPredicate(args.dbProvider, currentUser);
}
@@ -305,6 +306,11 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
return new ReviewerPredicate(args.dbProvider, self());
}
if ("mergeable".equalsIgnoreCase(value)) {
requireIndex(FIELD_IS, "mergeable");
return new IsMergeablePredicate(args.dbProvider);
}
try {
return status(value);
} catch (IllegalArgumentException e) {

View File

@@ -0,0 +1,42 @@
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.index.ChangeField;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Provider;
class IsMergeablePredicate extends IndexPredicate<ChangeData> {
private final Provider<ReviewDb> dbProvider;
IsMergeablePredicate(Provider<ReviewDb> dbProvider) {
super(ChangeField.MERGEABLE, "1");
this.dbProvider = dbProvider;
}
@Override
public boolean match(ChangeData object) throws OrmException {
Change c = object.change(dbProvider);
return c != null && c.isMergeable();
}
@Override
public int getCost() {
return 1;
}
}