From 3f6518ce99de8d8fa330ae551b2dc49b2094c712 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Thu, 2 Jul 2020 23:28:39 +0100 Subject: fix(gerrit): return HTML titles in more cases At present, we don't return HTML titles if there's a trailing slash, or a patchset. Instead, just consume the / and anything after it. This also fixes /123, because this is HTTP redirected to the full path *with a trailing slash* which otherwise wouldn't get the title injected. Change-Id: Idfd0e67752880a37dce0b400a3c1cfc53fac2912 Reviewed-on: https://cl.tvl.fyi/c/depot/+/859 Reviewed-by: BuildkiteCI Reviewed-by: tazjin Tested-by: BuildkiteCI --- .../0001-Use-detzip-in-download_bower.py.patch | 25 +++ third_party/gerrit/0002-Syntax-highlight-nix.patch | 24 +++ .../gerrit/0003-Syntax-highlight-rules.pl.patch | 44 +++++ .../gerrit/0004-Add-titles-to-CLs-over-HTTP.patch | 217 +++++++++++++++++++++ third_party/gerrit/add_titles_to_cls.patch | 200 ------------------- third_party/gerrit/default.nix | 8 +- third_party/gerrit/syntax_highlight_nix.patch | 12 -- third_party/gerrit/syntax_highlight_rules_pl.patch | 32 --- third_party/gerrit/use_detzip.patch | 13 -- 9 files changed, 314 insertions(+), 261 deletions(-) create mode 100644 third_party/gerrit/0001-Use-detzip-in-download_bower.py.patch create mode 100644 third_party/gerrit/0002-Syntax-highlight-nix.patch create mode 100644 third_party/gerrit/0003-Syntax-highlight-rules.pl.patch create mode 100644 third_party/gerrit/0004-Add-titles-to-CLs-over-HTTP.patch delete mode 100644 third_party/gerrit/add_titles_to_cls.patch delete mode 100644 third_party/gerrit/syntax_highlight_nix.patch delete mode 100644 third_party/gerrit/syntax_highlight_rules_pl.patch delete mode 100644 third_party/gerrit/use_detzip.patch diff --git a/third_party/gerrit/0001-Use-detzip-in-download_bower.py.patch b/third_party/gerrit/0001-Use-detzip-in-download_bower.py.patch new file mode 100644 index 0000000000..c24505d3bf --- /dev/null +++ b/third_party/gerrit/0001-Use-detzip-in-download_bower.py.patch @@ -0,0 +1,25 @@ +From aa4cda172a61eb4f09759cba98f4645fe74753a9 Mon Sep 17 00:00:00 2001 +From: Luke Granger-Brown +Date: Thu, 2 Jul 2020 23:02:09 +0100 +Subject: [PATCH 1/4] Use detzip in download_bower.py + +--- + tools/js/download_bower.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/tools/js/download_bower.py b/tools/js/download_bower.py +index 1df4b826bc..65bda74082 100755 +--- a/tools/js/download_bower.py ++++ b/tools/js/download_bower.py +@@ -106,7 +106,7 @@ def main(): + args.b, '--quiet', 'install', '%s#%s' % (args.p, args.v))) + bc = os.path.join(cwd, 'bower_components') + subprocess.check_call( +- ['zip', '-q', '--exclude', '.bower.json', '-r', cached, args.n], ++ ['detzip', '--exclude', '.bower.json', cached, args.n], + cwd=bc) + + if args.s: +-- +2.25.1 + diff --git a/third_party/gerrit/0002-Syntax-highlight-nix.patch b/third_party/gerrit/0002-Syntax-highlight-nix.patch new file mode 100644 index 0000000000..82b5bde13b --- /dev/null +++ b/third_party/gerrit/0002-Syntax-highlight-nix.patch @@ -0,0 +1,24 @@ +From f14cba31f2a9a75d06e58fd6313cc60d0cf5e690 Mon Sep 17 00:00:00 2001 +From: Luke Granger-Brown +Date: Thu, 2 Jul 2020 23:02:32 +0100 +Subject: [PATCH 2/4] Syntax highlight nix + +--- + .../app/elements/diff/gr-syntax-layer/gr-syntax-layer.js | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js +index f1e930f177..cc937cff67 100644 +--- a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js ++++ b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js +@@ -101,6 +101,7 @@ const LANGUAGE_MAP = { + 'text/x-vhdl': 'vhdl', + 'text/x-yaml': 'yaml', + 'text/vbscript': 'vbscript', ++ 'application/x-mix-transfer': 'nix', + }; + const ASYNC_DELAY = 10; + +-- +2.25.1 + diff --git a/third_party/gerrit/0003-Syntax-highlight-rules.pl.patch b/third_party/gerrit/0003-Syntax-highlight-rules.pl.patch new file mode 100644 index 0000000000..e85cbb9db2 --- /dev/null +++ b/third_party/gerrit/0003-Syntax-highlight-rules.pl.patch @@ -0,0 +1,44 @@ +From c3603950e5ae377514febbebf9aa26c31e07cd5d Mon Sep 17 00:00:00 2001 +From: Luke Granger-Brown +Date: Thu, 2 Jul 2020 23:02:43 +0100 +Subject: [PATCH 3/4] Syntax highlight rules.pl + +--- + .../elements/diff/gr-syntax-layer/gr-syntax-layer.js | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js +index cc937cff67..2145bc169b 100644 +--- a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js ++++ b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js +@@ -105,6 +105,10 @@ const LANGUAGE_MAP = { + }; + const ASYNC_DELAY = 10; + ++const FILENAME_OVERRIDES = { ++ 'rules.pl': 'prolog', ++}; ++ + const CLASS_WHITELIST = { + 'gr-diff gr-syntax gr-syntax-attr': true, + 'gr-diff gr-syntax gr-syntax-attribute': true, +@@ -236,10 +240,16 @@ class GrSyntaxLayer extends GestureEventListeners( + } + } + ++ _basename(filename) { ++ const pieces = filename.split(/\//); ++ return pieces[pieces.length-1]; ++ } ++ + _getLanguage(diffFileMetaInfo) { + // The Gerrit API provides only content-type, but for other users of + // gr-diff it may be more convenient to specify the language directly. + return diffFileMetaInfo.language || ++ FILENAME_OVERRIDES[this._basename(diffFileMetaInfo.name)] || + LANGUAGE_MAP[diffFileMetaInfo.content_type]; + } + +-- +2.25.1 + diff --git a/third_party/gerrit/0004-Add-titles-to-CLs-over-HTTP.patch b/third_party/gerrit/0004-Add-titles-to-CLs-over-HTTP.patch new file mode 100644 index 0000000000..bf372add84 --- /dev/null +++ b/third_party/gerrit/0004-Add-titles-to-CLs-over-HTTP.patch @@ -0,0 +1,217 @@ +From ead56bd63491ba4fd3c24fb1e9af36a3fa2141bf Mon Sep 17 00:00:00 2001 +From: Luke Granger-Brown +Date: Thu, 2 Jul 2020 23:03:02 +0100 +Subject: [PATCH 4/4] Add titles to CLs over HTTP + +--- + .../gerrit/httpd/raw/IndexHtmlUtil.java | 14 +++- + .../google/gerrit/httpd/raw/IndexServlet.java | 7 +- + .../google/gerrit/httpd/raw/StaticModule.java | 5 +- + .../gerrit/httpd/raw/TitleComputer.java | 67 +++++++++++++++++++ + .../gerrit/httpd/raw/PolyGerritIndexHtml.soy | 4 +- + 5 files changed, 89 insertions(+), 8 deletions(-) + create mode 100644 java/com/google/gerrit/httpd/raw/TitleComputer.java + +diff --git a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java b/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java +index 41d2f83975..323567b4a4 100644 +--- a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java ++++ b/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java +@@ -42,6 +42,7 @@ import java.util.Arrays; + import java.util.Collections; + import java.util.HashMap; + import java.util.Map; ++import java.util.Optional; + import java.util.Set; + import java.util.function.Function; + import java.util.regex.Matcher; +@@ -110,7 +111,8 @@ public class IndexHtmlUtil { + String faviconPath, + Map urlParameterMap, + Function urlInScriptTagOrdainer, +- String requestedURL) ++ String requestedURL, ++ TitleComputer titleComputer) + throws URISyntaxException, RestApiException { + ImmutableMap.Builder data = ImmutableMap.builder(); + data.putAll( +@@ -121,7 +123,7 @@ public class IndexHtmlUtil { + urlParameterMap, + urlInScriptTagOrdainer, + requestedURL)) +- .putAll(dynamicTemplateData(gerritApi)); ++ .putAll(dynamicTemplateData(gerritApi, requestedURL, titleComputer)); + + Set enabledExperiments = experimentData(urlParameterMap); + if (!enabledExperiments.isEmpty()) { +@@ -131,7 +133,9 @@ public class IndexHtmlUtil { + } + + /** Returns dynamic parameters of {@code index.html}. */ +- public static ImmutableMap dynamicTemplateData(GerritApi gerritApi) ++ public static ImmutableMap dynamicTemplateData(GerritApi gerritApi, ++ String requestedURL, ++ TitleComputer titleComputer) + throws RestApiException { + ImmutableMap.Builder data = ImmutableMap.builder(); + Map initialData = new HashMap<>(); +@@ -159,6 +163,10 @@ public class IndexHtmlUtil { + } + + data.put("gerritInitialData", initialData); ++ ++ Optional title = titleComputer.computeTitle(requestedURL); ++ title.ifPresent(s -> data.put("title", s)); ++ + return data.build(); + } + +diff --git a/java/com/google/gerrit/httpd/raw/IndexServlet.java b/java/com/google/gerrit/httpd/raw/IndexServlet.java +index 97d22701de..089ef4725f 100644 +--- a/java/com/google/gerrit/httpd/raw/IndexServlet.java ++++ b/java/com/google/gerrit/httpd/raw/IndexServlet.java +@@ -44,12 +44,14 @@ public class IndexServlet extends HttpServlet { + private final GerritApi gerritApi; + private final SoySauce soySauce; + private final Function urlOrdainer; ++ private TitleComputer titleComputer; + + IndexServlet( + @Nullable String canonicalUrl, + @Nullable String cdnPath, + @Nullable String faviconPath, +- GerritApi gerritApi) { ++ GerritApi gerritApi, ++ TitleComputer titleComputer) { + this.canonicalUrl = canonicalUrl; + this.cdnPath = cdnPath; + this.faviconPath = faviconPath; +@@ -63,6 +65,7 @@ public class IndexServlet extends HttpServlet { + (s) -> + UnsafeSanitizedContentOrdainer.ordainAsSafe( + s, SanitizedContent.ContentKind.TRUSTED_RESOURCE_URI); ++ this.titleComputer = titleComputer; + } + + @Override +@@ -74,7 +77,7 @@ public class IndexServlet extends HttpServlet { + // TODO(hiesel): Remove URL ordainer as parameter once Soy is consistent + ImmutableMap templateData = + IndexHtmlUtil.templateData( +- gerritApi, canonicalUrl, cdnPath, faviconPath, parameterMap, urlOrdainer, requestUrl); ++ gerritApi, canonicalUrl, cdnPath, faviconPath, parameterMap, urlOrdainer, requestUrl, titleComputer); + renderer = soySauce.renderTemplate("com.google.gerrit.httpd.raw.Index").setData(templateData); + } catch (URISyntaxException | RestApiException e) { + throw new IOException(e); +diff --git a/java/com/google/gerrit/httpd/raw/StaticModule.java b/java/com/google/gerrit/httpd/raw/StaticModule.java +index 414a120194..e1b6fb082d 100644 +--- a/java/com/google/gerrit/httpd/raw/StaticModule.java ++++ b/java/com/google/gerrit/httpd/raw/StaticModule.java +@@ -220,11 +220,12 @@ public class StaticModule extends ServletModule { + HttpServlet getPolyGerritUiIndexServlet( + @CanonicalWebUrl @Nullable String canonicalUrl, + @GerritServerConfig Config cfg, +- GerritApi gerritApi) { ++ GerritApi gerritApi, ++ TitleComputer titleComputer) { + String cdnPath = + options.useDevCdn() ? options.devCdn() : cfg.getString("gerrit", null, "cdnPath"); + String faviconPath = cfg.getString("gerrit", null, "faviconPath"); +- return new IndexServlet(canonicalUrl, cdnPath, faviconPath, gerritApi); ++ return new IndexServlet(canonicalUrl, cdnPath, faviconPath, gerritApi, titleComputer); + } + + @Provides +diff --git a/java/com/google/gerrit/httpd/raw/TitleComputer.java b/java/com/google/gerrit/httpd/raw/TitleComputer.java +new file mode 100644 +index 0000000000..8fd2053ad0 +--- /dev/null ++++ b/java/com/google/gerrit/httpd/raw/TitleComputer.java +@@ -0,0 +1,67 @@ ++package com.google.gerrit.httpd.raw; ++ ++import com.google.common.flogger.FluentLogger; ++import com.google.gerrit.entities.Change; ++import com.google.gerrit.extensions.restapi.ResourceConflictException; ++import com.google.gerrit.extensions.restapi.ResourceNotFoundException; ++import com.google.gerrit.server.change.ChangeResource; ++import com.google.gerrit.server.permissions.PermissionBackendException; ++import com.google.gerrit.server.restapi.change.ChangesCollection; ++import com.google.inject.Inject; ++import com.google.inject.Provider; ++import com.google.inject.Singleton; ++ ++import java.net.MalformedURLException; ++import java.net.URL; ++import java.util.Optional; ++import java.util.regex.Matcher; ++import java.util.regex.Pattern; ++ ++@Singleton ++public class TitleComputer { ++ private static final FluentLogger logger = FluentLogger.forEnclosingClass(); ++ ++ @Inject ++ public TitleComputer(Provider changes) { ++ this.changes = changes; ++ } ++ ++ public Optional computeTitle(String requestedURI) { ++ URL url = null; ++ try { ++ url = new URL(requestedURI); ++ } catch (MalformedURLException e) { ++ logger.atWarning().log("Failed to turn %s into a URL.", requestedURI); ++ return Optional.empty(); ++ } ++ ++ // Try to turn this into a change. ++ Optional changeId = tryExtractChange(url.getPath()); ++ if (changeId.isPresent()) { ++ return titleFromChangeId(changeId.get()); ++ } ++ ++ return Optional.empty(); ++ } ++ ++ private static final Pattern extractChangeIdRegex = Pattern.compile("^/(?:c/.*/\\+/)?(?[0-9]+)(?:/[0-9]+)?(?:/.*)?$"); ++ private final Provider changes; ++ ++ private Optional tryExtractChange(String path) { ++ Matcher m = extractChangeIdRegex.matcher(path); ++ if (!m.matches()) { ++ return Optional.empty(); ++ } ++ return Change.Id.tryParse(m.group("changeId")); ++ } ++ ++ private Optional titleFromChangeId(Change.Id changeId) { ++ ChangesCollection changesCollection = changes.get(); ++ try { ++ ChangeResource changeResource = changesCollection.parse(changeId); ++ return Optional.of(changeResource.getChange().getSubject()); ++ } catch (ResourceConflictException | ResourceNotFoundException | PermissionBackendException e) { ++ return Optional.empty(); ++ } ++ } ++} +diff --git a/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy b/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy +index d162714399..0ba228ad00 100644 +--- a/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy ++++ b/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy +@@ -33,10 +33,12 @@ + {@param? preloadChangePage: ?} + {@param? preloadDiffPage: ?} + {@param? userIsAuthenticated: ?} ++ {@param? title: ?} + {\n} + {\n} + {\n} +- {\n} ++ {if $title}{$title} · Gerrit Code Review{\n}{/if} ++ {\n} + {\n} + {\n} + +-- +2.25.1 + diff --git a/third_party/gerrit/add_titles_to_cls.patch b/third_party/gerrit/add_titles_to_cls.patch deleted file mode 100644 index 1a17e6dbb7..0000000000 --- a/third_party/gerrit/add_titles_to_cls.patch +++ /dev/null @@ -1,200 +0,0 @@ -diff --git a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java b/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java -index 41d2f83975..323567b4a4 100644 ---- a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java -+++ b/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java -@@ -42,6 +42,7 @@ import java.util.Arrays; - import java.util.Collections; - import java.util.HashMap; - import java.util.Map; -+import java.util.Optional; - import java.util.Set; - import java.util.function.Function; - import java.util.regex.Matcher; -@@ -110,7 +111,8 @@ public class IndexHtmlUtil { - String faviconPath, - Map urlParameterMap, - Function urlInScriptTagOrdainer, -- String requestedURL) -+ String requestedURL, -+ TitleComputer titleComputer) - throws URISyntaxException, RestApiException { - ImmutableMap.Builder data = ImmutableMap.builder(); - data.putAll( -@@ -121,7 +123,7 @@ public class IndexHtmlUtil { - urlParameterMap, - urlInScriptTagOrdainer, - requestedURL)) -- .putAll(dynamicTemplateData(gerritApi)); -+ .putAll(dynamicTemplateData(gerritApi, requestedURL, titleComputer)); - - Set enabledExperiments = experimentData(urlParameterMap); - if (!enabledExperiments.isEmpty()) { -@@ -131,7 +133,9 @@ public class IndexHtmlUtil { - } - - /** Returns dynamic parameters of {@code index.html}. */ -- public static ImmutableMap dynamicTemplateData(GerritApi gerritApi) -+ public static ImmutableMap dynamicTemplateData(GerritApi gerritApi, -+ String requestedURL, -+ TitleComputer titleComputer) - throws RestApiException { - ImmutableMap.Builder data = ImmutableMap.builder(); - Map initialData = new HashMap<>(); -@@ -159,6 +163,10 @@ public class IndexHtmlUtil { - } - - data.put("gerritInitialData", initialData); -+ -+ Optional title = titleComputer.computeTitle(requestedURL); -+ title.ifPresent(s -> data.put("title", s)); -+ - return data.build(); - } - -diff --git a/java/com/google/gerrit/httpd/raw/IndexServlet.java b/java/com/google/gerrit/httpd/raw/IndexServlet.java -index 97d22701de..089ef4725f 100644 ---- a/java/com/google/gerrit/httpd/raw/IndexServlet.java -+++ b/java/com/google/gerrit/httpd/raw/IndexServlet.java -@@ -44,12 +44,14 @@ public class IndexServlet extends HttpServlet { - private final GerritApi gerritApi; - private final SoySauce soySauce; - private final Function urlOrdainer; -+ private TitleComputer titleComputer; - - IndexServlet( - @Nullable String canonicalUrl, - @Nullable String cdnPath, - @Nullable String faviconPath, -- GerritApi gerritApi) { -+ GerritApi gerritApi, -+ TitleComputer titleComputer) { - this.canonicalUrl = canonicalUrl; - this.cdnPath = cdnPath; - this.faviconPath = faviconPath; -@@ -63,6 +65,7 @@ public class IndexServlet extends HttpServlet { - (s) -> - UnsafeSanitizedContentOrdainer.ordainAsSafe( - s, SanitizedContent.ContentKind.TRUSTED_RESOURCE_URI); -+ this.titleComputer = titleComputer; - } - - @Override -@@ -74,7 +77,7 @@ public class IndexServlet extends HttpServlet { - // TODO(hiesel): Remove URL ordainer as parameter once Soy is consistent - ImmutableMap templateData = - IndexHtmlUtil.templateData( -- gerritApi, canonicalUrl, cdnPath, faviconPath, parameterMap, urlOrdainer, requestUrl); -+ gerritApi, canonicalUrl, cdnPath, faviconPath, parameterMap, urlOrdainer, requestUrl, titleComputer); - renderer = soySauce.renderTemplate("com.google.gerrit.httpd.raw.Index").setData(templateData); - } catch (URISyntaxException | RestApiException e) { - throw new IOException(e); -diff --git a/java/com/google/gerrit/httpd/raw/StaticModule.java b/java/com/google/gerrit/httpd/raw/StaticModule.java -index 414a120194..e1b6fb082d 100644 ---- a/java/com/google/gerrit/httpd/raw/StaticModule.java -+++ b/java/com/google/gerrit/httpd/raw/StaticModule.java -@@ -220,11 +220,12 @@ public class StaticModule extends ServletModule { - HttpServlet getPolyGerritUiIndexServlet( - @CanonicalWebUrl @Nullable String canonicalUrl, - @GerritServerConfig Config cfg, -- GerritApi gerritApi) { -+ GerritApi gerritApi, -+ TitleComputer titleComputer) { - String cdnPath = - options.useDevCdn() ? options.devCdn() : cfg.getString("gerrit", null, "cdnPath"); - String faviconPath = cfg.getString("gerrit", null, "faviconPath"); -- return new IndexServlet(canonicalUrl, cdnPath, faviconPath, gerritApi); -+ return new IndexServlet(canonicalUrl, cdnPath, faviconPath, gerritApi, titleComputer); - } - - @Provides -diff --git a/java/com/google/gerrit/httpd/raw/TitleComputer.java b/java/com/google/gerrit/httpd/raw/TitleComputer.java -new file mode 100644 -index 0000000000..efee24607c ---- /dev/null -+++ b/java/com/google/gerrit/httpd/raw/TitleComputer.java -@@ -0,0 +1,67 @@ -+package com.google.gerrit.httpd.raw; -+ -+import com.google.common.flogger.FluentLogger; -+import com.google.gerrit.entities.Change; -+import com.google.gerrit.extensions.restapi.ResourceConflictException; -+import com.google.gerrit.extensions.restapi.ResourceNotFoundException; -+import com.google.gerrit.server.change.ChangeResource; -+import com.google.gerrit.server.permissions.PermissionBackendException; -+import com.google.gerrit.server.restapi.change.ChangesCollection; -+import com.google.inject.Inject; -+import com.google.inject.Provider; -+import com.google.inject.Singleton; -+ -+import java.net.MalformedURLException; -+import java.net.URL; -+import java.util.Optional; -+import java.util.regex.Matcher; -+import java.util.regex.Pattern; -+ -+@Singleton -+public class TitleComputer { -+ private static final FluentLogger logger = FluentLogger.forEnclosingClass(); -+ -+ @Inject -+ public TitleComputer(Provider changes) { -+ this.changes = changes; -+ } -+ -+ public Optional computeTitle(String requestedURI) { -+ URL url = null; -+ try { -+ url = new URL(requestedURI); -+ } catch (MalformedURLException e) { -+ logger.atWarning().log("Failed to turn %s into a URL.", requestedURI); -+ return Optional.empty(); -+ } -+ -+ // Try to turn this into a change. -+ Optional changeId = tryExtractChange(url.getPath()); -+ if (changeId.isPresent()) { -+ return titleFromChangeId(changeId.get()); -+ } -+ -+ return Optional.empty(); -+ } -+ -+ private static final Pattern extractChangeIdRegex = Pattern.compile("^/(?:c/.*/\\+/)?(?[0-9]+)(?:/[0-9]+)?$"); -+ private final Provider changes; -+ -+ private Optional tryExtractChange(String path) { -+ Matcher m = extractChangeIdRegex.matcher(path); -+ if (!m.matches()) { -+ return Optional.empty(); -+ } -+ return Change.Id.tryParse(m.group("changeId")); -+ } -+ -+ private Optional titleFromChangeId(Change.Id changeId) { -+ ChangesCollection changesCollection = changes.get(); -+ try { -+ ChangeResource changeResource = changesCollection.parse(changeId); -+ return Optional.of(changeResource.getChange().getSubject()); -+ } catch (ResourceConflictException | ResourceNotFoundException | PermissionBackendException e) { -+ return Optional.empty(); -+ } -+ } -+} -diff --git a/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy b/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy -index d162714399..0ba228ad00 100644 ---- a/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy -+++ b/resources/com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy -@@ -33,10 +33,12 @@ - {@param? preloadChangePage: ?} - {@param? preloadDiffPage: ?} - {@param? userIsAuthenticated: ?} -+ {@param? title: ?} - {\n} - {\n} - {\n} -- {\n} -+ {if $title}{$title} · Gerrit Code Review{\n}{/if} -+ {\n} - {\n} - {\n} - diff --git a/third_party/gerrit/default.nix b/third_party/gerrit/default.nix index d5350d3ed8..8b7e9678e9 100644 --- a/third_party/gerrit/default.nix +++ b/third_party/gerrit/default.nix @@ -40,10 +40,10 @@ pkgs.buildBazelPackage { fetchSubmodules = true; }; patches = [ - ./use_detzip.patch - ./syntax_highlight_nix.patch - ./syntax_highlight_rules_pl.patch - ./add_titles_to_cls.patch + ./0001-Use-detzip-in-download_bower.py.patch + ./0002-Syntax-highlight-nix.patch + ./0003-Syntax-highlight-rules.pl.patch + ./0004-Add-titles-to-CLs-over-HTTP.patch ]; bazelTarget = "release"; diff --git a/third_party/gerrit/syntax_highlight_nix.patch b/third_party/gerrit/syntax_highlight_nix.patch deleted file mode 100644 index 2a7791c756..0000000000 --- a/third_party/gerrit/syntax_highlight_nix.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js -index 1a0bbd9f50..0f2786a911 100644 ---- a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js -+++ b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js -@@ -99,6 +99,7 @@ const LANGUAGE_MAP = { - 'text/x-vhdl': 'vhdl', - 'text/x-yaml': 'yaml', - 'text/vbscript': 'vbscript', -+ 'application/x-mix-transfer': 'nix', - }; - const ASYNC_DELAY = 10; - diff --git a/third_party/gerrit/syntax_highlight_rules_pl.patch b/third_party/gerrit/syntax_highlight_rules_pl.patch deleted file mode 100644 index ccc59b6b46..0000000000 --- a/third_party/gerrit/syntax_highlight_rules_pl.patch +++ /dev/null @@ -1,32 +0,0 @@ -diff --git a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js -index 1a0bbd9f50..d8d2fa643b 100644 ---- a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js -+++ b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js -@@ -102,6 +102,10 @@ const LANGUAGE_MAP = { - }; - const ASYNC_DELAY = 10; - -+const FILENAME_OVERRIDES = { -+ 'rules.pl': 'prolog', -+}; -+ - const CLASS_WHITELIST = { - 'gr-diff gr-syntax gr-syntax-attr': true, - 'gr-diff gr-syntax gr-syntax-attribute': true, -@@ -233,10 +237,16 @@ class GrSyntaxLayer extends GestureEventListeners( - } - } - -+ _basename(filename) { -+ const pieces = filename.split(/\//); -+ return pieces[pieces.length-1]; -+ } -+ - _getLanguage(diffFileMetaInfo) { - // The Gerrit API provides only content-type, but for other users of - // gr-diff it may be more convenient to specify the language directly. - return diffFileMetaInfo.language || -+ FILENAME_OVERRIDES[this._basename(diffFileMetaInfo.name)] || - LANGUAGE_MAP[diffFileMetaInfo.content_type]; - } - diff --git a/third_party/gerrit/use_detzip.patch b/third_party/gerrit/use_detzip.patch deleted file mode 100644 index 068bce7717..0000000000 --- a/third_party/gerrit/use_detzip.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/tools/js/download_bower.py b/tools/js/download_bower.py -index 1df4b826bc..65bda74082 100755 ---- a/tools/js/download_bower.py -+++ b/tools/js/download_bower.py -@@ -106,7 +106,7 @@ def main(): - args.b, '--quiet', 'install', '%s#%s' % (args.p, args.v))) - bc = os.path.join(cwd, 'bower_components') - subprocess.check_call( -- ['zip', '-q', '--exclude', '.bower.json', '-r', cached, args.n], -+ ['detzip', '--exclude', '.bower.json', cached, args.n], - cwd=bc) - - if args.s: -- cgit 1.4.1