Branch Operator: Support full branch names

The search operator for branches required the provided value to be the
short branch name that is shown in the web interface (without the
'refs/heads/' prefix). Change the branch operator so that it also
supports full branch names as value.

It is intuive that searching with 'branch:master' and searching with
'branch:refs/for/master' deliver the same result. So far
'branch:refs/for/master' was the same as searching with
'refs:refs/heads/refs/heads/master' which is unexpected for most users.

Change-Id: I573eb4d500160843bc28d142488bb8cbfab5a939
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2012-03-27 16:00:56 +02:00
parent 0ae1044fcb
commit ad921cdbd0
2 changed files with 6 additions and 10 deletions

View File

@@ -109,12 +109,9 @@ library] is used for evaluation of such patterns.
[[branch]]
branch:'BRANCH'::
+
Changes for 'BRANCH'. The branch name is the short name shown
in the web interface, without the traditional 'refs/heads/'
prefix. This operator is a shorthand for 'refs:'. Searching for
'branch:master' really means 'ref:refs/heads/master', and searching
for 'branch:refs/heads/master' is the same as searching for
'ref:refs/heads/refs/heads/master'.
Changes for 'BRANCH'. The branch name is either the short name shown
in the web interface or the full name of the destination branch with
the traditional 'refs/heads/' prefix.
+
If 'BRANCH' starts with `^` it matches branch names by regular
expression patterns. The

View File

@@ -23,12 +23,11 @@ import com.google.inject.Provider;
class BranchPredicate extends OperatorPredicate<ChangeData> {
private final Provider<ReviewDb> dbProvider;
private final String shortName;
BranchPredicate(Provider<ReviewDb> dbProvider, String branch) {
super(ChangeQueryBuilder.FIELD_BRANCH, branch);
super(ChangeQueryBuilder.FIELD_BRANCH, branch.startsWith(Branch.R_HEADS)
? branch : Branch.R_HEADS + branch);
this.dbProvider = dbProvider;
this.shortName = branch;
}
@Override
@@ -38,7 +37,7 @@ class BranchPredicate extends OperatorPredicate<ChangeData> {
return false;
}
return change.getDest().get().startsWith(Branch.R_HEADS)
&& shortName.equals(change.getDest().getShortName());
&& getValue().equals(change.getDest().get());
}
@Override