Move file web_links into the meta_a, meta_b headers

Web links should be part of the metadata for the two halves of a diff.
The protocol uses meta_a and meta_b to represent the halves, with
contained fields for specific values.

Also avoid unnecessary copying of the WebLinkInfo by reusing the
created list from the WebLinks factory.

Change-Id: I2c31cad2a4fed11e513f81cd613742534662a663
This commit is contained in:
Shawn Pearce
2014-10-16 22:48:33 -07:00
parent 2ae832e7ed
commit b62414c0c3
6 changed files with 26 additions and 34 deletions

View File

@@ -3366,6 +3366,8 @@ The `DiffFileMetaInfo` entity contains meta information about a file diff.
|`name` |The name of the file.
|`content_type`|The content type of the file.
|`lines` |The total number of lines in the file.
|'web_links' |Links to the file in external sites as a list of
link:rest-api-changes.html#web-link-info[WebLinkInfo] entries.
|==========================
[[diff-info]]
@@ -3389,12 +3391,6 @@ Intraline status (`OK`, `ERROR`, `TIMEOUT`).
|`diff_header` ||A list of strings representing the patch set diff header.
|`content` ||The content differences in the file as a list of
link:#diff-content[DiffContent] entities.
|'web_links_a' |optional|
Links to the side A file in external sites as a list of
link:rest-api-changes.html#web-link-info[WebLinkInfo] entries.
|'web_links_b' |optional|
Links to the side B file in external sites as a list of
link:rest-api-changes.html#web-link-info[WebLinkInfo] entries.
|==========================
[[diff-intraline-info]]

View File

@@ -28,8 +28,6 @@ public class DiffInfo extends JavaScriptObject {
public final native FileMeta meta_b() /*-{ return this.meta_b; }-*/;
public final native JsArrayString diff_header() /*-{ return this.diff_header; }-*/;
public final native JsArray<Region> content() /*-{ return this.content; }-*/;
public final native JsArray<WebLinkInfo> web_links_a() /*-{ return this.web_links_a; }-*/;
public final native JsArray<WebLinkInfo> web_links_b() /*-{ return this.web_links_b; }-*/;
public final ChangeType change_type() {
return ChangeType.valueOf(change_typeRaw());
@@ -103,6 +101,7 @@ public class DiffInfo extends JavaScriptObject {
public final native String name() /*-{ return this.name; }-*/;
public final native String content_type() /*-{ return this.content_type; }-*/;
public final native int lines() /*-{ return this.lines || 0 }-*/;
public final native JsArray<WebLinkInfo> web_links() /*-{ return this.web_links; }-*/;
protected FileMeta() {
}

View File

@@ -16,7 +16,6 @@ package com.google.gerrit.client.diff;
import com.google.gerrit.client.account.DiffPreferences;
import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.reviewdb.client.Patch.ChangeType;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwt.core.client.GWT;
@@ -173,10 +172,8 @@ class DiffTable extends Composite {
boolean editExists, int currentPatchSet) {
this.changeType = info.change_type();
this.autoHideHeader = prefs.autoHideDiffTableHeader();
patchSetSelectBoxA.setUpPatchSetNav(list, info.meta_a(),
Natives.asList(info.web_links_a()), editExists, currentPatchSet);
patchSetSelectBoxB.setUpPatchSetNav(list, info.meta_b(),
Natives.asList(info.web_links_b()), editExists, currentPatchSet);
patchSetSelectBoxA.setUpPatchSetNav(list, info.meta_a(), editExists, currentPatchSet);
patchSetSelectBoxB.setUpPatchSetNav(list, info.meta_b(), editExists, currentPatchSet);
JsArrayString hdr = info.diff_header();
if (hdr != null) {

View File

@@ -22,6 +22,7 @@ import com.google.gerrit.client.changes.ChangeFileApi;
import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
import com.google.gerrit.client.patches.PatchUtil;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.client.ui.InlineHyperlink;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Patch;
@@ -86,7 +87,7 @@ class PatchSetSelectBox2 extends Composite {
}
void setUpPatchSetNav(JsArray<RevisionInfo> list, DiffInfo.FileMeta meta,
List<WebLinkInfo> webLinks, boolean editExists, int currentPatchSet) {
boolean editExists, int currentPatchSet) {
InlineHyperlink baseLink = null;
InlineHyperlink selectedLink = null;
if (sideA) {
@@ -117,6 +118,7 @@ class PatchSetSelectBox2 extends Composite {
linkPanel.add(createEditIcon());
}
}
List<WebLinkInfo> webLinks = Natives.asList(meta.web_links());
if (webLinks != null) {
for (WebLinkInfo weblink : webLinks) {
Anchor a = new Anchor();

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.server;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.gerrit.extensions.common.WebLinkInfo;
import com.google.gerrit.extensions.registration.DynamicSet;
@@ -57,14 +58,18 @@ public class WebLinks {
return links;
}
public Iterable<WebLinkInfo> getFileLinks(String project, String revision,
public List<WebLinkInfo> getFileLinks(String project, String revision,
String file) {
List<WebLinkInfo> links = Lists.newArrayList();
List<WebLinkInfo> links = new ArrayList<>(4);
for (FileWebLink webLink : fileLinks) {
links.add(new WebLinkInfo(webLink.getLinkName(),
webLink.getImageUrl(),
webLink.getFileUrl(project, revision, file),
webLink.getTarget()));
String name = webLink.getLinkName();
String url = webLink.getFileUrl(project, revision, file);
if (!Strings.isNullOrEmpty(name) && !Strings.isNullOrEmpty(url)) {
links.add(new WebLinkInfo(name,
webLink.getImageUrl(),
url,
webLink.getTarget()));
}
}
return links;
}

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.server.change;
import static com.google.common.base.Preconditions.checkState;
import com.google.common.base.MoreObjects;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.gerrit.common.data.PatchScript;
@@ -47,6 +46,7 @@ import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import org.eclipse.jgit.diff.Edit;
import org.eclipse.jgit.diff.ReplaceEdit;
import org.kohsuke.args4j.CmdLineException;
@@ -59,7 +59,6 @@ import org.kohsuke.args4j.spi.Parameters;
import org.kohsuke.args4j.spi.Setter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -160,7 +159,7 @@ public class GetDiff implements RestReadView<FileResource> {
String rev = basePatchSet != null
? basePatchSet.getRefName()
: resource.getRevision().getPatchSet().getRefName() + "^1";
result.webLinksA =
result.metaA.webLinks =
getFileWebLinks(state.getProject(), rev, result.metaA.name);
}
@@ -169,7 +168,7 @@ public class GetDiff implements RestReadView<FileResource> {
result.metaB.name = ps.getNewName();
setContentType(result.metaB, state, ps.getFileModeB(), ps.getMimeTypeB());
result.metaB.lines = ps.getB().size();
result.webLinksB = getFileWebLinks(state.getProject(),
result.metaB.webLinks = getFileWebLinks(state.getProject(),
resource.getRevision().getPatchSet().getRefName(),
result.metaB.name);
}
@@ -203,14 +202,9 @@ public class GetDiff implements RestReadView<FileResource> {
private List<WebLinkInfo> getFileWebLinks(Project project, String rev,
String file) {
List<WebLinkInfo> fileWebLinks = new ArrayList<>();
for (WebLinkInfo link : webLinks.getFileLinks(project.getName(),
rev, file)) {
if (!Strings.isNullOrEmpty(link.name) && !Strings.isNullOrEmpty(link.url)) {
fileWebLinks.add(link);
}
}
return fileWebLinks;
List<WebLinkInfo> links =
webLinks.getFileLinks(project.getName(), rev, file);
return !links.isEmpty() ? links : null;
}
static class Result {
@@ -220,14 +214,13 @@ public class GetDiff implements RestReadView<FileResource> {
ChangeType changeType;
List<String> diffHeader;
List<ContentEntry> content;
List<WebLinkInfo> webLinksA;
List<WebLinkInfo> webLinksB;
}
static class FileMeta {
String name;
String contentType;
Integer lines;
List<WebLinkInfo> webLinks;
}
private void setContentType(FileMeta meta, ProjectState project,