From 1dfe36c9b2d333264e2678e167fa93950da96c4d Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Fri, 12 Apr 2013 14:52:56 -0400 Subject: [PATCH] Add gitweb.linkDrafts to control if gitweb links are shown on drafts If gitweb is hosted on a second server and only public references are replicated, links to draft patch sets in the panel don't go anywhere useful. Default behavior remains the same, to provide links on all patch sets, regardless of draft status. Change-Id: Ia26f08b4fd4e480a89b84ff5602603c3fcc8eee6 --- Documentation/config-gerrit.txt | 10 ++++++++++ .../google/gerrit/common/data/GitWebType.java | 16 ++++++++++++++++ .../com/google/gerrit/client/GitwebLink.java | 10 ++++++++++ .../changes/PatchSetComplexDisclosurePanel.java | 2 +- .../com/google/gerrit/httpd/GitWebConfig.java | 1 + 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt index 6ad9c3fa17..27b48747b4 100644 --- a/Documentation/config-gerrit.txt +++ b/Documentation/config-gerrit.txt @@ -1320,6 +1320,16 @@ using the property 'gitweb.pathSeparator'. + Valid values are the characters '*', '(' and ')'. +[[gitweb.linkDrafts]]gitweb.linkDrafts:: ++ +Whether or not Gerrit should provide links to gitweb on draft patch sets. ++ +By default, Gerrit will show links to gitweb on all patch sets. If gitweb +only allows publicly viewable references, set this to false to remove +the links to draft patch sets from the change review screen. ++ +Valid values are "true" and "false," default is "true." + [[groups]]Section groups ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/GitWebType.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/GitWebType.java index 3580774f2e..8528c0fdbe 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/GitWebType.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/GitWebType.java @@ -75,6 +75,9 @@ public class GitWebType { * project names */ private char pathSeparator = '/'; + /** Whether to include links to draft patch sets */ + private boolean linkDrafts; + /** Private default constructor for gson. */ protected GitWebType() { } @@ -124,6 +127,15 @@ public class GitWebType { return fileHistory; } + /** + * Get whether to link to draft patch sets + * + * @return True to link + */ + public boolean getLinkDrafts() { + return linkDrafts; + } + /** * Set the pattern for branch view. * @@ -201,4 +213,8 @@ public class GitWebType { public void setPathSeparator(char separator) { this.pathSeparator = separator; } + + public void setLinkDrafts(boolean linkDrafts) { + this.linkDrafts = linkDrafts; + } } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/GitwebLink.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/GitwebLink.java index 5f62a5260e..ec97e58524 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/GitwebLink.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/GitwebLink.java @@ -35,6 +35,16 @@ public class GitwebLink { type = link.type; } + /** + * Can we link to a patch set if it's a draft + * + * @param ps Patch set to check draft status + * @return true if it's not a draft, or we can link to drafts + */ + public boolean canLink(final PatchSet ps) { + return !ps.isDraft() || type.getLinkDrafts(); + } + public String getLinkName() { return "(" + type.getLinkName() + ")"; } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java index 76f77a2b07..e14c942109 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java @@ -91,7 +91,7 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel final InlineLabel revtxt = new InlineLabel(ps.getRevision().get() + " "); revtxt.addStyleName(Gerrit.RESOURCES.css().patchSetRevision()); getHeader().add(revtxt); - if (gw != null) { + if (gw != null && gw.canLink(ps)) { final Anchor revlink = new Anchor(gw.getLinkName(), false, gw.toRevision(changeDetail.getChange() .getProject(), ps)); diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GitWebConfig.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GitWebConfig.java index 7de4bc3757..22d756895f 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GitWebConfig.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GitWebConfig.java @@ -55,6 +55,7 @@ public class GitWebConfig { type.setProject(cfg.getString("gitweb", null, "project")); type.setRevision(cfg.getString("gitweb", null, "revision")); type.setFileHistory(cfg.getString("gitweb", null, "filehistory")); + type.setLinkDrafts(cfg.getBoolean("gitweb", null, "linkdrafts", true)); String pathSeparator = cfg.getString("gitweb", null, "pathSeparator"); if (pathSeparator != null) { if (pathSeparator.length() == 1) {