Allow gitweb URLs to be passed unencoded for viewing.
Gerrit composes the viewer URL using information about the project, branch, file or commit of the target object to be displayed. Context: Typically viewers such as CGit and GitWeb do need those parts to be encoded, including the '/' in project names, for being correctly parsed. However other viewers could instead require unencoded URL (e.g. GitHub web based viewer). This patch allows to disable the URL encoding for allowing GitHub to be used as "gitweb custom viewer" on top of Gerrit. Example of GitHub configured as viewer: [gitweb] type = custom url = https://github.com/ project = ${project} revision = ${project}/commit/${commit} branch = ${project}/tree/${branch} fileHistory = ${project}/blog/${branch}/${file} linkName = GitHub urlEncode = false Change-Id: Ief59de7eb19def60c5e765c4a495bcac00384d83
This commit is contained in:
@@ -1460,6 +1460,19 @@ using the property 'gitweb.pathSeparator'.
|
||||
+
|
||||
Valid values are the characters '*', '(' and ')'.
|
||||
|
||||
[[gitweb.linkDrafts]]gitweb.urlEncode::
|
||||
+
|
||||
Whether or not Gerrit should encode the generated viewer URL.
|
||||
+
|
||||
Gerrit composes the viewer URL using information about the project, branch, file
|
||||
or commit of the target object to be displayed. Typically viewers such as CGit
|
||||
and GitWeb do need those parts to be encoded, including the '/' in project's name,
|
||||
for being correctly parsed.
|
||||
However other viewers could instead require an unencoded URL (e.g. GitHub web
|
||||
based viewer)
|
||||
+
|
||||
Valid values are "true" and "false," default is "true."
|
||||
|
||||
[[gitweb.linkDrafts]]gitweb.linkDrafts::
|
||||
+
|
||||
Whether or not Gerrit should provide links to gitweb on draft patch sets.
|
||||
@@ -1468,7 +1481,7 @@ 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."
|
||||
Valid values are "true" and "false," default is "true".
|
||||
|
||||
[[groups]]Section groups
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@@ -78,6 +78,9 @@ public class GitWebType {
|
||||
/** Whether to include links to draft patch sets */
|
||||
private boolean linkDrafts;
|
||||
|
||||
/** Whether to encode URL segments */
|
||||
private boolean urlEncode;
|
||||
|
||||
/** Private default constructor for gson. */
|
||||
protected GitWebType() {
|
||||
}
|
||||
@@ -217,4 +220,12 @@ public class GitWebType {
|
||||
public void setLinkDrafts(boolean linkDrafts) {
|
||||
this.linkDrafts = linkDrafts;
|
||||
}
|
||||
|
||||
public boolean isUrlEncode() {
|
||||
return urlEncode;
|
||||
}
|
||||
|
||||
public void setUrlEncode(boolean urlEncode) {
|
||||
this.urlEncode = urlEncode;
|
||||
}
|
||||
}
|
||||
|
@@ -94,6 +94,10 @@ public class GitwebLink {
|
||||
}
|
||||
|
||||
private String encode(String segment) {
|
||||
if (type.isUrlEncode()) {
|
||||
return URL.encodeQueryString(type.replacePathSeparator(segment));
|
||||
} else {
|
||||
return segment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -56,6 +56,7 @@ public class GitWebConfig {
|
||||
type.setRevision(cfg.getString("gitweb", null, "revision"));
|
||||
type.setFileHistory(cfg.getString("gitweb", null, "filehistory"));
|
||||
type.setLinkDrafts(cfg.getBoolean("gitweb", null, "linkdrafts", true));
|
||||
type.setUrlEncode(cfg.getBoolean("gitweb", null, "urlencode", true));
|
||||
String pathSeparator = cfg.getString("gitweb", null, "pathSeparator");
|
||||
if (pathSeparator != null) {
|
||||
if (pathSeparator.length() == 1) {
|
||||
|
Reference in New Issue
Block a user