Add support for parent revisions weblinks provided by plugins

Support for parent weblinks was removed in change I8508dcaf3. This is a
regression for some users who rely on that information being present.

On the other hand, not all users want to have these links going to the
same external service as the patch set revision links, so we can't just
add it back as it was.

Instead, add a new plugin web link interface for the parent revisions.

If a plugin provides an implementation of ParentWebLink, the links will
be displayed beside the parent revisions on the change screen.

For the built-in gitweb support, provide the parent links using the same
template as the patch set links, so they will always appear when the
gitweb config defines the 'revision' setting.

Bug: Issue 4908
Change-Id: Icdf0f997f939128717ee4edc2c147a26eeaebad6
(cherry picked from commit 58b8d76204)
This commit is contained in:
David Pursehouse
2016-12-09 11:12:27 +09:00
parent 8f83bbbb27
commit 1aedee62ae
8 changed files with 103 additions and 5 deletions

View File

@@ -26,6 +26,7 @@ import com.google.gerrit.extensions.webui.BranchWebLink;
import com.google.gerrit.extensions.webui.DiffWebLink;
import com.google.gerrit.extensions.webui.FileHistoryWebLink;
import com.google.gerrit.extensions.webui.FileWebLink;
import com.google.gerrit.extensions.webui.ParentWebLink;
import com.google.gerrit.extensions.webui.PatchSetWebLink;
import com.google.gerrit.extensions.webui.ProjectWebLink;
import com.google.gerrit.extensions.webui.WebLink;
@@ -73,6 +74,7 @@ public class WebLinks {
};
private final DynamicSet<PatchSetWebLink> patchSetLinks;
private final DynamicSet<ParentWebLink> parentLinks;
private final DynamicSet<FileWebLink> fileLinks;
private final DynamicSet<FileHistoryWebLink> fileHistoryLinks;
private final DynamicSet<DiffWebLink> diffLinks;
@@ -81,6 +83,7 @@ public class WebLinks {
@Inject
public WebLinks(DynamicSet<PatchSetWebLink> patchSetLinks,
DynamicSet<ParentWebLink> parentLinks,
DynamicSet<FileWebLink> fileLinks,
DynamicSet<FileHistoryWebLink> fileLogLinks,
DynamicSet<DiffWebLink> diffLinks,
@@ -88,6 +91,7 @@ public class WebLinks {
DynamicSet<BranchWebLink> branchLinks
) {
this.patchSetLinks = patchSetLinks;
this.parentLinks = parentLinks;
this.fileLinks = fileLinks;
this.fileHistoryLinks = fileLogLinks;
this.diffLinks = diffLinks;
@@ -112,6 +116,22 @@ public class WebLinks {
});
}
/**
* @param project Project name.
* @param revision SHA1 of the parent revision.
* @return Links for patch sets.
*/
public FluentIterable<WebLinkInfo> getParentLinks(final Project.NameKey project,
final String revision) {
return filterLinks(parentLinks, new Function<WebLink, WebLinkInfo>() {
@Override
public WebLinkInfo apply(WebLink webLink) {
return ((ParentWebLink)webLink).getParentWebLink(project.get(), revision);
}
});
}
/**
*
* @param project Project name.

View File

@@ -1069,6 +1069,11 @@ public class ChangeJson {
CommitInfo i = new CommitInfo();
i.commit = parent.name();
i.subject = parent.getShortMessage();
if (addLinks) {
FluentIterable<WebLinkInfo> parentLinks =
webLinks.getParentLinks(project, parent.name());
i.webLinks = parentLinks.isEmpty() ? null : parentLinks.toList();
}
info.parents.add(i);
}
return info;

View File

@@ -59,6 +59,7 @@ import com.google.gerrit.extensions.webui.BranchWebLink;
import com.google.gerrit.extensions.webui.DiffWebLink;
import com.google.gerrit.extensions.webui.FileHistoryWebLink;
import com.google.gerrit.extensions.webui.FileWebLink;
import com.google.gerrit.extensions.webui.ParentWebLink;
import com.google.gerrit.extensions.webui.PatchSetWebLink;
import com.google.gerrit.extensions.webui.ProjectWebLink;
import com.google.gerrit.extensions.webui.TopMenu;
@@ -347,6 +348,7 @@ public class GerritGlobalModule extends FactoryModule {
DynamicSet.setOf(binder(), ExternalIncludedIn.class);
DynamicMap.mapOf(binder(), ProjectConfigEntry.class);
DynamicSet.setOf(binder(), PatchSetWebLink.class);
DynamicSet.setOf(binder(), ParentWebLink.class);
DynamicSet.setOf(binder(), FileWebLink.class);
DynamicSet.setOf(binder(), FileHistoryWebLink.class);
DynamicSet.setOf(binder(), DiffWebLink.class);

View File

@@ -27,6 +27,7 @@ import com.google.gerrit.extensions.restapi.Url;
import com.google.gerrit.extensions.webui.BranchWebLink;
import com.google.gerrit.extensions.webui.FileHistoryWebLink;
import com.google.gerrit.extensions.webui.FileWebLink;
import com.google.gerrit.extensions.webui.ParentWebLink;
import com.google.gerrit.extensions.webui.PatchSetWebLink;
import com.google.gerrit.extensions.webui.ProjectWebLink;
import com.google.inject.AbstractModule;
@@ -74,6 +75,7 @@ public class GitwebConfig {
if (!isNullOrEmpty(type.getRevision())) {
DynamicSet.bind(binder(), PatchSetWebLink.class).to(GitwebLinks.class);
DynamicSet.bind(binder(), ParentWebLink.class).to(GitwebLinks.class);
}
if (!isNullOrEmpty(type.getProject())) {
@@ -240,7 +242,7 @@ public class GitwebConfig {
@Singleton
static class GitwebLinks implements BranchWebLink, FileHistoryWebLink,
FileWebLink, PatchSetWebLink, ProjectWebLink {
FileWebLink, PatchSetWebLink, ParentWebLink, ProjectWebLink {
private final String url;
private final GitwebType type;
private final ParameterizedString branch;
@@ -310,6 +312,12 @@ public class GitwebConfig {
return null;
}
@Override
public WebLinkInfo getParentWebLink(String projectName, String commit) {
// For Gitweb treat parent revision links the same as patch set links
return getPatchSetWebLink(projectName, commit);
}
@Override
public WebLinkInfo getProjectWeblink(String projectName) {
if (project != null) {