diff options
author | Luca Milanesio <luca.milanesio@gmail.com> | 2013-10-11 11:34:39 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-04-25 20:25:38 +0200 |
commit | a433ed0366eba3e59590cabd97eac77737178a1d (patch) | |
tree | 9a180ff75520dd7a637b97ab0baea7721756724d | |
parent | 264ba8a1d9b8d668f9026769e39bdbb16d8d67fc (diff) |
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
(cherry picked from commit 253120389509e82d3f71da53d596b3fbcd41cd3e)
Reviewed-by: Ismo Haataja <ismo.haataja@digia.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
4 files changed, 31 insertions, 2 deletions
diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt index 93492baf0c..c136aa0e33 100644 --- a/Documentation/config-gerrit.txt +++ b/Documentation/config-gerrit.txt @@ -1342,6 +1342,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. @@ -1350,7 +1363,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 ~~~~~~~~~~~~~~~~~~~~~~~~ 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 8528c0fdbe..31e9c968d3 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 @@ -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; + } } 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 ec97e58524..c2373841b4 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 @@ -86,6 +86,10 @@ public class GitwebLink { } private String encode(String segment) { - return URL.encodeQueryString(type.replacePathSeparator(segment)); + if (type.isUrlEncode()) { + return URL.encodeQueryString(type.replacePathSeparator(segment)); + } else { + return segment; + } } } 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 22d756895f..dfb1cc25a1 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 @@ -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) { |