Add support for set() method to Key, and use fromString() for URLs
This way we have a consistent URL encoding for any entity key. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -25,10 +25,9 @@ import com.google.gerrit.client.patches.PatchUnifiedScreen;
|
||||
import com.google.gerrit.client.reviewdb.Account;
|
||||
import com.google.gerrit.client.reviewdb.Change;
|
||||
import com.google.gerrit.client.reviewdb.Patch;
|
||||
import com.google.gerrit.client.reviewdb.PatchSet;
|
||||
import com.google.gerrit.client.rpc.RpcUtil;
|
||||
import com.google.gerrit.client.ui.Screen;
|
||||
import com.google.gwt.http.client.URL;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.HistoryListener;
|
||||
|
||||
public class Link implements HistoryListener {
|
||||
@@ -51,7 +50,7 @@ public class Link implements HistoryListener {
|
||||
}
|
||||
|
||||
public static String toChange(final Change.Id c) {
|
||||
return "change," + c.get();
|
||||
return "change," + c.toString();
|
||||
}
|
||||
|
||||
public static String toAccountDashboard(final AccountInfo acct) {
|
||||
@@ -59,7 +58,7 @@ public class Link implements HistoryListener {
|
||||
}
|
||||
|
||||
public static String toAccountDashboard(final Account.Id acct) {
|
||||
return "dashboard," + acct.get();
|
||||
return "dashboard," + acct.toString();
|
||||
}
|
||||
|
||||
public static String toPatchSideBySide(final Patch.Id id) {
|
||||
@@ -71,14 +70,18 @@ public class Link implements HistoryListener {
|
||||
}
|
||||
|
||||
public static String toPatch(final String type, final Patch.Id id) {
|
||||
final PatchSet.Id psId = id.getParentKey();
|
||||
final Change.Id chId = psId.getParentKey();
|
||||
final String encp = encodePath(id.get());
|
||||
return "patch," + type + "," + chId.get() + "," + psId.get() + "," + encp;
|
||||
return "patch," + type + "," + id.toString();
|
||||
}
|
||||
|
||||
public void onHistoryChanged(final String token) {
|
||||
final Screen s = select(token);
|
||||
Screen s;
|
||||
try {
|
||||
s = select(token);
|
||||
} catch (RuntimeException err) {
|
||||
GWT.log("Error parsing history token: " + token, err);
|
||||
s = null;
|
||||
}
|
||||
|
||||
if (s != null) {
|
||||
Gerrit.display(s);
|
||||
} else {
|
||||
@@ -87,44 +90,44 @@ public class Link implements HistoryListener {
|
||||
}
|
||||
|
||||
private Screen select(final String token) {
|
||||
if (token == null)
|
||||
return null;
|
||||
String p;
|
||||
|
||||
else if (SETTINGS.equals(token))
|
||||
if (token == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (SETTINGS.equals(token)) {
|
||||
return new AccountSettings();
|
||||
}
|
||||
|
||||
else if (MINE.equals(token))
|
||||
if (MINE.equals(token)) {
|
||||
return new AccountDashboardScreen(RpcUtil.getAccountId());
|
||||
}
|
||||
|
||||
else if (MINE_STARRED.equals(token))
|
||||
if (MINE_STARRED.equals(token)) {
|
||||
return new MineStarredScreen();
|
||||
|
||||
else if (token.startsWith("patch,sidebyside,"))
|
||||
return new PatchSideBySideScreen(patchId(token));
|
||||
|
||||
else if (token.startsWith("patch,unified,"))
|
||||
return new PatchUnifiedScreen(patchId(token));
|
||||
|
||||
else if (token.matches("^change,\\d+$")) {
|
||||
final String id = token.substring("change,".length());
|
||||
return new ChangeScreen(Change.Id.fromString(id));
|
||||
}
|
||||
|
||||
else if (token.matches("^dashboard,\\d+$")) {
|
||||
final String id = token.substring("dashboard,".length());
|
||||
return new AccountDashboardScreen(new Account.Id(Integer.parseInt(id)));
|
||||
p = "patch,sidebyside,";
|
||||
if (token.startsWith(p))
|
||||
return new PatchSideBySideScreen(Patch.Id.parse(skip(p, token)));
|
||||
|
||||
}
|
||||
p = "patch,unified,";
|
||||
if (token.startsWith(p))
|
||||
return new PatchUnifiedScreen(Patch.Id.parse(skip(p, token)));
|
||||
|
||||
p = "change,";
|
||||
if (token.startsWith(p))
|
||||
return new ChangeScreen(Change.Id.parse(skip(p, token)));
|
||||
|
||||
p = "dashboard,";
|
||||
if (token.matches(p))
|
||||
return new AccountDashboardScreen(Account.Id.parse(skip(p, token)));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Patch.Id patchId(final String token) {
|
||||
final String[] p = token.split(",");
|
||||
final Change.Id cId = Change.Id.fromString(p[2]);
|
||||
final PatchSet.Id psId = new PatchSet.Id(cId, Integer.parseInt(p[3]));
|
||||
return new Patch.Id(psId, URL.decodeComponent(p[4]));
|
||||
private static String skip(final String prefix, final String in) {
|
||||
return in.substring(prefix.length());
|
||||
}
|
||||
|
||||
private static native String encodePath(String path) /*-{ return encodeURIComponent(path).replace(/%20/g, "+").replace(/%2F/g, "/"); }-*/;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,18 @@ public final class Account {
|
||||
public int get() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(int newValue) {
|
||||
id = newValue;
|
||||
}
|
||||
|
||||
/** Parse an Account.Id out of a string representation. */
|
||||
public static Id parse(final String str) {
|
||||
final Id r = new Id();
|
||||
r.fromString(str);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
@Column
|
||||
|
||||
@@ -44,6 +44,11 @@ public final class AccountExternalId {
|
||||
public String get() {
|
||||
return externalId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(String newValue) {
|
||||
externalId = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Column(name = Column.NONE)
|
||||
|
||||
@@ -37,6 +37,11 @@ public final class AccountGroup {
|
||||
public String get() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(String newValue) {
|
||||
name = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
/** Synthetic key to link to within the database */
|
||||
@@ -55,6 +60,11 @@ public final class AccountGroup {
|
||||
public int get() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(int newValue) {
|
||||
id = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Column
|
||||
|
||||
@@ -46,6 +46,11 @@ public final class AccountSshKey {
|
||||
public int get() {
|
||||
return seq;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(int newValue) {
|
||||
seq = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Column(name = Column.NONE)
|
||||
|
||||
@@ -35,6 +35,11 @@ public final class ApprovalCategory {
|
||||
public String get() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(String newValue) {
|
||||
id = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Column
|
||||
|
||||
@@ -44,6 +44,11 @@ public final class ApprovalCategoryValue {
|
||||
public short get() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(short newValue) {
|
||||
value = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Column(name = Column.NONE)
|
||||
|
||||
@@ -42,6 +42,11 @@ public final class Branch {
|
||||
return branchName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(String newValue) {
|
||||
branchName = newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project.NameKey getParentKey() {
|
||||
return projectName;
|
||||
@@ -76,6 +81,11 @@ public final class Branch {
|
||||
public int get() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(int newValue) {
|
||||
id = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Column(name = Column.NONE)
|
||||
|
||||
@@ -38,9 +38,16 @@ public final class Change {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(int newValue) {
|
||||
id = newValue;
|
||||
}
|
||||
|
||||
/** Parse a Change.Id out of a string representation. */
|
||||
public static Id fromString(final String str) {
|
||||
return new Id(Integer.parseInt(str));
|
||||
public static Id parse(final String str) {
|
||||
final Id r = new Id();
|
||||
r.fromString(str);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,11 @@ public final class ChangeMessage {
|
||||
public String get() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(String newValue) {
|
||||
uuid = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Column(name = Column.NONE)
|
||||
|
||||
@@ -38,6 +38,11 @@ public final class ContributorAgreement {
|
||||
public int get() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(int newValue) {
|
||||
id = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Column
|
||||
|
||||
@@ -44,6 +44,18 @@ public final class Patch {
|
||||
public String get() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(String newValue) {
|
||||
fileName = newValue;
|
||||
}
|
||||
|
||||
/** Parse a Patch.Id out of a string representation. */
|
||||
public static Id parse(final String str) {
|
||||
final Id r = new Id();
|
||||
r.fromString(str);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum ChangeType {
|
||||
|
||||
@@ -46,6 +46,10 @@ public final class PatchContent {
|
||||
return KeyUtil.encode(sha1);
|
||||
}
|
||||
|
||||
public void fromString(final String in) {
|
||||
sha1 = KeyUtil.decode(in);
|
||||
}
|
||||
|
||||
public com.google.gwtorm.client.Key<?> getParentKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,11 @@ public final class PatchLineComment {
|
||||
public String get() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(String newValue) {
|
||||
uuid = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
protected static final char STATUS_DRAFT = 'd';
|
||||
|
||||
@@ -44,6 +44,18 @@ public final class PatchSet {
|
||||
public int get() {
|
||||
return patchSetId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(int newValue) {
|
||||
patchSetId = newValue;
|
||||
}
|
||||
|
||||
/** Parse a PatchSet.Id out of a string representation. */
|
||||
public static Id parse(final String str) {
|
||||
final Id r = new Id();
|
||||
r.fromString(str);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
@Column(name = Column.NONE)
|
||||
|
||||
@@ -44,6 +44,11 @@ public final class PatchSetAncestor {
|
||||
public int get() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(int newValue) {
|
||||
position = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Column(name = Column.NONE)
|
||||
|
||||
@@ -37,6 +37,11 @@ public final class Project {
|
||||
public String get() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(String newValue) {
|
||||
name = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
/** Synthetic key to link to within the database */
|
||||
@@ -55,6 +60,11 @@ public final class Project {
|
||||
public int get() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(int newValue) {
|
||||
id = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Column
|
||||
|
||||
@@ -34,6 +34,11 @@ public final class SystemConfig {
|
||||
public String get() {
|
||||
return VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void set(final String newValue) {
|
||||
assert get().equals(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public static SystemConfig create() {
|
||||
|
||||
@@ -39,8 +39,9 @@ import java.util.ArrayList;
|
||||
/**
|
||||
* Recreates PatchSet and Patch entities for the changes supplied.
|
||||
* <p>
|
||||
* Takes on input strings of the form <code>change_id|patch_set_id</code>, such
|
||||
* as might be created by the following PostgreSQL database dump:
|
||||
* Takes on input strings of the form <code>change_id|patch_set_id</code> or
|
||||
* <code>change_id,patch_set_id</code>, such as might be created by the
|
||||
* following PostgreSQL database dump:
|
||||
*
|
||||
* <pre>
|
||||
* psql reviewdb -tAc 'select change_id,patch_set_id from patch_sets'
|
||||
@@ -52,17 +53,15 @@ import java.util.ArrayList;
|
||||
public class ReimportPatchSets {
|
||||
public static void main(final String[] argv) throws OrmException,
|
||||
XsrfException, IOException {
|
||||
final GerritServer gs = GerritServer.getInstance();
|
||||
final ArrayList<PatchSet.Id> todo = new ArrayList<PatchSet.Id>();
|
||||
final BufferedReader br =
|
||||
new BufferedReader(new InputStreamReader(System.in));
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
final String[] idstr = line.split("\\|");
|
||||
todo.add(new PatchSet.Id(Change.Id.fromString(idstr[0]), Integer
|
||||
.parseInt(idstr[1])));
|
||||
todo.add(PatchSet.Id.parse(line.replace('|', ',')));
|
||||
}
|
||||
|
||||
final GerritServer gs = GerritServer.getInstance();
|
||||
final ReviewDb db = gs.getDatabase().open();
|
||||
final ProgressMonitor pm = new TextProgressMonitor();
|
||||
try {
|
||||
|
||||
@@ -156,7 +156,7 @@ public class UrlRewriteFilter implements Filter {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Change.Id id = Change.Id.fromString(m.group(1));
|
||||
final Change.Id id = Change.Id.parse(m.group(1));
|
||||
final StringBuffer url = toGerrit(req);
|
||||
url.append('#');
|
||||
url.append(Link.toChange(id));
|
||||
|
||||
@@ -181,7 +181,7 @@ class Receive extends AbstractGitCommand {
|
||||
if (m.matches()) {
|
||||
// The referenced change must exist and must still be open.
|
||||
//
|
||||
final Change.Id changeId = Change.Id.fromString(m.group(1));
|
||||
final Change.Id changeId = Change.Id.parse(m.group(1));
|
||||
parseNewPatchSetCommand(cmd, changeId);
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user