From f5c67c1cf8ea7726ee61a65d927de03e941812ea Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Mon, 25 Nov 2013 10:31:13 -0800 Subject: [PATCH] Add query shorthands o,r,p,f Bind shorthand operators for popular query expressions: o = owner r = reviewer p = project f = file Change-Id: I57d4592e0fca6f756d3afd01fa2262c2fb17465f --- Documentation/user-search.txt | 18 +++++++-------- .../query/change/ChangeQueryBuilder.java | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Documentation/user-search.txt b/Documentation/user-search.txt index a6c10696bf..527d89b3c7 100644 --- a/Documentation/user-search.txt +++ b/Documentation/user-search.txt @@ -82,7 +82,7 @@ as a legacy numerical 'ID' such as 15183, or a newer style Change-Id that was scraped out of the commit message. [[owner]] -owner:'USER':: +owner:'USER', o:'USER':: + Changes originally submitted by 'USER'. The special case of `owner:self` will find changes owned by the caller. @@ -93,7 +93,7 @@ ownerin:'GROUP':: Changes originally submitted by a user in 'GROUP'. [[reviewer]] -reviewer:'USER':: +reviewer:'USER', r:'USER':: + Changes that have been, or need to be, reviewed by 'USER'. The special case of `reviewer:self` will find changes where the caller @@ -110,7 +110,7 @@ commit:'SHA1':: Changes where 'SHA1' is one of the patch sets of the change. [[project]] -project:'PROJECT':: +project:'PROJECT', p:'PROJECT':: + Changes occurring in 'PROJECT'. If 'PROJECT' starts with `^` it matches project names by regular expression. The @@ -187,13 +187,13 @@ comment:'TEXT':: Changes that match 'TEXT' string in any comment left by a reviewer. [[file]] -file:^'REGEX':: +file:'PATH', f:'PATH':: + -Matches any change where REGEX matches a file that was affected -by the change. The regular expression pattern must start with -`^`. For example, to match all XML files use `file:^.*\.xml$`. -The link:http://www.brics.dk/automaton/[dk.brics.automaton -library] is used for the evaluation of such patterns. +Matches any change touching file at 'PATH'. By default exact path +matching is used, but regular expressions can be enabled by starting +with `^`. For example, to match all XML files use `file:^.*\.xml$`. +The link:http://www.brics.dk/automaton/[dk.brics.automaton library] +is used for the evaluation of such patterns. + The `^` required at the beginning of the regular expression not only denotes a regular expression, but it also has the usual meaning of diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java index f7a1ccd578..e15ba3001d 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java @@ -336,6 +336,11 @@ public class ChangeQueryBuilder extends QueryBuilder { args.conflictsCache, value, parseChange(value)); } + @Operator + public Predicate p(String name) { + return project(name); + } + @Operator public Predicate project(String name) { if (name.startsWith("^")) @@ -376,6 +381,11 @@ public class ChangeQueryBuilder extends QueryBuilder { return new RefPredicate(args.dbProvider, ref); } + @Operator + public Predicate f(String file) throws QueryParseException { + return file(file); + } + @Operator public Predicate file(String file) throws QueryParseException { if (file.startsWith("^")) { @@ -535,6 +545,12 @@ public class ChangeQueryBuilder extends QueryBuilder { return visibleto(currentUser); } + @Operator + public Predicate o(String who) + throws QueryParseException, OrmException { + return owner(who); + } + @Operator public Predicate owner(String who) throws QueryParseException, OrmException { @@ -556,6 +572,12 @@ public class ChangeQueryBuilder extends QueryBuilder { return new OwnerinPredicate(args.dbProvider, args.userFactory, g.getUUID()); } + @Operator + public Predicate r(String who) + throws QueryParseException, OrmException { + return reviewer(who); + } + @Operator public Predicate reviewer(String who) throws QueryParseException, OrmException {