Add operators for absolute last-updated-on search

Some users may have been using sortkey to exclude changes older than
a certain date. This is possible but inconvenient to mimic with an
age: query, so provide operators for absolute searches.

The semantics of these operators are similar to those of `git log`,
except for some incompatibilities/quirks of JGit's GitDateParser.

Change-Id: I52fee758052a5644beb3c97bf727f92129245f3f
This commit is contained in:
Dave Borowitz
2014-02-11 16:43:36 -08:00
parent 0f3fa96e7e
commit a0af7febe6
8 changed files with 258 additions and 18 deletions

View File

@@ -0,0 +1,46 @@
// Copyright (C) 2014 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.server.index.ChangeField;
import com.google.gerrit.server.index.TimestampRangePredicate;
import com.google.gerrit.server.query.QueryParseException;
import com.google.gwtorm.server.OrmException;
import java.util.Date;
public class AfterPredicate extends TimestampRangePredicate<ChangeData> {
private final Date cut;
AfterPredicate(String value) throws QueryParseException {
super(ChangeField.UPDATED, ChangeQueryBuilder.FIELD_AFTER, value);
cut = parse(value);
}
@Override
public Date getMinTimestamp() {
return cut;
}
@Override
public Date getMaxTimestamp() {
return new Date(Long.MAX_VALUE);
}
@Override
public boolean match(ChangeData cd) throws OrmException {
return cd.change().getLastUpdatedOn().getTime() >= cut.getTime();
}
}

View File

@@ -37,10 +37,12 @@ public class AgePredicate extends TimestampRangePredicate<ChangeData> {
this.cut = TimeUtil.nowMs() - ms;
}
@Override
public Timestamp getMinTimestamp() {
return new Timestamp(0);
}
@Override
public Timestamp getMaxTimestamp() {
return new Timestamp(cut);
}
@@ -54,9 +56,4 @@ public class AgePredicate extends TimestampRangePredicate<ChangeData> {
Change change = object.change();
return change != null && change.getLastUpdatedOn().getTime() <= cut;
}
@Override
public int getCost() {
return 1;
}
}

View File

@@ -0,0 +1,46 @@
// Copyright (C) 2014 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.server.index.ChangeField;
import com.google.gerrit.server.index.TimestampRangePredicate;
import com.google.gerrit.server.query.QueryParseException;
import com.google.gwtorm.server.OrmException;
import java.util.Date;
public class BeforePredicate extends TimestampRangePredicate<ChangeData> {
private final Date cut;
BeforePredicate(String value) throws QueryParseException {
super(ChangeField.UPDATED, ChangeQueryBuilder.FIELD_BEFORE, value);
cut = parse(value);
}
@Override
public Date getMinTimestamp() {
return new Date(0);
}
@Override
public Date getMaxTimestamp() {
return cut;
}
@Override
public boolean match(ChangeData cd) throws OrmException {
return cd.change().getLastUpdatedOn().getTime() <= cut.getTime();
}
}

View File

@@ -84,7 +84,9 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
// NOTE: As new search operations are added, please keep the
// SearchSuggestOracle up to date.
public static final String FIELD_AFTER = "after";
public static final String FIELD_AGE = "age";
public static final String FIELD_BEFORE = "before";
public static final String FIELD_BRANCH = "branch";
public static final String FIELD_CHANGE = "change";
public static final String FIELD_COMMENT = "comment";
@@ -238,6 +240,26 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
return new AgePredicate(value);
}
@Operator
public Predicate<ChangeData> before(String value) throws QueryParseException {
return new BeforePredicate(value);
}
@Operator
public Predicate<ChangeData> until(String value) throws QueryParseException {
return before(value);
}
@Operator
public Predicate<ChangeData> after(String value) throws QueryParseException {
return new AfterPredicate(value);
}
@Operator
public Predicate<ChangeData> since(String value) throws QueryParseException {
return after(value);
}
@Operator
public Predicate<ChangeData> change(String query) {
if (PAT_LEGACY_ID.matcher(query).matches()) {