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
This commit is contained in:
Chad Horohoe
2013-04-12 14:52:56 -04:00
parent eeed4976d0
commit 1dfe36c9b2
5 changed files with 38 additions and 1 deletions

View File

@@ -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
~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -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;
}
}

View File

@@ -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() + ")";
}

View File

@@ -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));

View File

@@ -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) {