SchemaUtil.getNameParts(...): Use US Locale and split on '/' and '_'

Always use US Locale when converting name parts to lower case. This
makes the behaviour independent of the default Locale.

In addition also split names on '/' and '_'. Splitting on these
characters makes sense for group names, especially since in future
groups are stored as refs/groups/<group-name> refs in NoteDb and
hierarchical group names will be encouraged.

Both these changes to SchemaUtil.getNameParts(...) require new schema
versions for all indexes since values for fields that use
SchemaUtil.getNameParts(...) may change. This is why we do both
modification in the same change, so that we must increase the index
schema versions only once.

Change-Id: I26f6940216058acd27e2f0dd38441a93fe5d7107
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2017-01-17 11:08:14 +01:00
committed by David Pursehouse
parent 8b038714f5
commit d6d67bb740
6 changed files with 23 additions and 4 deletions

View File

@@ -32,6 +32,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -102,19 +103,19 @@ public class SchemaUtil {
public static Set<String> getNameParts(String name,
Iterable<String> emails) {
Splitter at = Splitter.on('@');
Splitter s = Splitter.on(CharMatcher.anyOf("@.- ")).omitEmptyStrings();
Splitter s = Splitter.on(CharMatcher.anyOf("@.- /_")).omitEmptyStrings();
HashSet<String> parts = new HashSet<>();
for (String email : emails) {
if (email == null) {
continue;
}
String lowerEmail = email.toLowerCase();
String lowerEmail = email.toLowerCase(Locale.US);
parts.add(lowerEmail);
Iterables.addAll(parts, at.split(lowerEmail));
Iterables.addAll(parts, s.split(lowerEmail));
}
if (name != null) {
Iterables.addAll(parts, s.split(name.toLowerCase()));
Iterables.addAll(parts, s.split(name.toLowerCase(Locale.US)));
}
return parts;
}

View File

@@ -26,6 +26,7 @@ import com.google.gerrit.server.index.SchemaUtil;
import java.sql.Timestamp;
import java.util.Collections;
import java.util.Locale;
import java.util.Set;
/** Secondary index schemas for accounts. */
@@ -65,7 +66,7 @@ public class AccountField {
// Additional values not currently added by getPersonParts.
// TODO(dborowitz): Move to getPersonParts and remove this hack.
if (fullName != null) {
parts.add(fullName.toLowerCase());
parts.add(fullName.toLowerCase(Locale.US));
}
return parts;
}

View File

@@ -35,9 +35,12 @@ public class AccountSchemaDefinitions extends SchemaDefinitions<AccountState> {
static final Schema<AccountState> V2 =
schema(V1, AccountField.WATCHED_PROJECT);
@Deprecated
static final Schema<AccountState> V3 =
schema(V2, AccountField.FULL_NAME);
static final Schema<AccountState> V4 = schema(V3);
public static final AccountSchemaDefinitions INSTANCE =
new AccountSchemaDefinitions();

View File

@@ -80,11 +80,14 @@ public class ChangeSchemaDefinitions extends SchemaDefinitions<ChangeData> {
ChangeField.STORED_SUBMIT_RECORD_LENIENT,
ChangeField.STORED_SUBMIT_RECORD_STRICT);
@Deprecated
static final Schema<ChangeData> V36 =
schema(V35,
ChangeField.REF_STATE,
ChangeField.REF_STATE_PATTERN);
static final Schema<ChangeData> V37 = schema(V36);
public static final String NAME = "changes";
public static final ChangeSchemaDefinitions INSTANCE =
new ChangeSchemaDefinitions();

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.server.index.Schema;
import com.google.gerrit.server.index.SchemaDefinitions;
public class GroupSchemaDefinitions extends SchemaDefinitions<AccountGroup> {
@Deprecated
static final Schema<AccountGroup> V1 = schema(
GroupField.ID,
GroupField.UUID,
@@ -30,6 +31,8 @@ public class GroupSchemaDefinitions extends SchemaDefinitions<AccountGroup> {
GroupField.DESCRIPTION,
GroupField.IS_VISIBLE_TO_ALL);
static final Schema<AccountGroup> V2 = schema(V1);
public static final GroupSchemaDefinitions INSTANCE =
new GroupSchemaDefinitions();