Merge branch 'stable-3.4' into stable-3.5

* stable-3.4:
  Update getFileWebLink signature to match Gerrit

Change-Id: I7b8b02b8ccc230abc07d70722c600a811d838896
Depends-on: https://gerrit-review.googlesource.com/c/gerrit/+/331440
diff --git a/BUILD b/BUILD
index 057d3d2..8966d6b 100644
--- a/BUILD
+++ b/BUILD
@@ -7,7 +7,7 @@
     srcs = glob(["src/main/java/**/*.java"]),
     manifest_entries = [
         "Gerrit-PluginName: gitiles",
-        "Gerrit-Module: com.googlesource.gerrit.plugins.gitiles.Module",
+        "Gerrit-Module: com.googlesource.gerrit.plugins.gitiles.PluginModule",
         "Gerrit-HttpModule: com.googlesource.gerrit.plugins.gitiles.HttpModule",
         # Gitiles uses /repo to access a repo, so the default plugin layout would
         # disallow repos named "static" or "Documentation". Paths starting with +
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
index 29258f0..f2f842c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
@@ -17,7 +17,6 @@
 import static java.util.stream.Collectors.toMap;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Maps;
 import com.google.gerrit.entities.Project;
 import com.google.gerrit.extensions.restapi.AuthException;
 import com.google.gerrit.server.CurrentUser;
@@ -243,12 +242,7 @@
 
     @Override
     public List<Ref> getAdditionalRefs() throws IOException {
-      List<Ref> refs = git.getRefDatabase().getAdditionalRefs();
-      Map<String, Ref> result = Maps.newHashMapWithExpectedSize(refs.size());
-      for (Ref ref : refs) {
-        result.put(ref.getName(), ref);
-      }
-      return ImmutableList.copyOf(result.values());
+      return ImmutableList.copyOf(git.getRefDatabase().getAdditionalRefs());
     }
 
     @Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/HttpModule.java
index f1c34c6..a2d5c94 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/HttpModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/HttpModule.java
@@ -17,6 +17,7 @@
 import com.google.common.flogger.FluentLogger;
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.config.SitePaths;
+import com.google.gitiles.BranchRedirectFilter;
 import com.google.gitiles.GitilesAccess;
 import com.google.gitiles.GitilesServlet;
 import com.google.gitiles.GitilesUrls;
@@ -108,7 +109,17 @@
       GitilesUrls urls,
       GitilesAccess.Factory accessFactory,
       RepositoryResolver<HttpServletRequest> resolver) {
-    return new GitilesServlet(cfg, null, urls, accessFactory, resolver, null, null, null, null);
+    return new GitilesServlet(
+        cfg,
+        null,
+        urls,
+        accessFactory,
+        resolver,
+        null,
+        null,
+        null,
+        null,
+        new BranchRedirectFilter());
   }
 
   @Provides
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/MenuFilter.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/MenuFilter.java
index 1fd26e2..263fd70 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/MenuFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/MenuFilter.java
@@ -68,7 +68,7 @@
   private String getLoginRedirectUrl(HttpServletRequest req) {
     String baseUrl = urls.getBaseGerritUrl(req);
     String loginUrl = baseUrl + "login/";
-    String token = req.getRequestURL().toString();
+    String token = getRequestUrl(req);
     if (!baseUrl.isEmpty()) {
       token = token.substring(baseUrl.length());
     }
@@ -79,4 +79,9 @@
     }
     return (loginUrl + Url.encode(token));
   }
+
+  @SuppressWarnings("JdkObsolete")
+  private static String getRequestUrl(HttpServletRequest req) {
+    return req.getRequestURL().toString();
+  }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/Module.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/PluginModule.java
similarity index 97%
rename from src/main/java/com/googlesource/gerrit/plugins/gitiles/Module.java
rename to src/main/java/com/googlesource/gerrit/plugins/gitiles/PluginModule.java
index 02f7eb7..5aab4cd 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/PluginModule.java
@@ -47,11 +47,11 @@
 import org.eclipse.jgit.lib.Config;
 import org.eclipse.jgit.transport.resolver.RepositoryResolver;
 
-class Module extends LifecycleModule {
+class PluginModule extends LifecycleModule {
   private final boolean noWebLinks;
 
   @Inject
-  Module(PluginConfigFactory configFactory) {
+  PluginModule(PluginConfigFactory configFactory) {
     Config config = configFactory.getGlobalPluginConfig("gitiles");
     this.noWebLinks = config.getBoolean("gerrit", null, "noWebLinks", false);
   }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/gitiles/ListProjectsAccessTest.java b/src/test/java/com/googlesource/gerrit/plugins/gitiles/ListProjectsAccessTest.java
index 839bd26..d8dee32 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/gitiles/ListProjectsAccessTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/gitiles/ListProjectsAccessTest.java
@@ -34,7 +34,7 @@
 import org.junit.After;
 import org.junit.Test;
 
-@TestPlugin(name = "gitiles", sysModule = "com.googlesource.gerrit.plugins.gitiles.Module")
+@TestPlugin(name = "gitiles", sysModule = "com.googlesource.gerrit.plugins.gitiles.PluginModule")
 public class ListProjectsAccessTest extends LightweightPluginDaemonTest {
   @ConfigSuite.Default
   public static Config defaultConfig() {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/gitiles/RepositoryResolverAccessTest.java b/src/test/java/com/googlesource/gerrit/plugins/gitiles/RepositoryResolverAccessTest.java
index dc0e89d..110837f 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/gitiles/RepositoryResolverAccessTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/gitiles/RepositoryResolverAccessTest.java
@@ -35,7 +35,7 @@
 import org.junit.After;
 import org.junit.Test;
 
-@TestPlugin(name = "gitiles", sysModule = "com.googlesource.gerrit.plugins.gitiles.Module")
+@TestPlugin(name = "gitiles", sysModule = "com.googlesource.gerrit.plugins.gitiles.PluginModule")
 public class RepositoryResolverAccessTest extends LightweightPluginDaemonTest {
   @ConfigSuite.Default
   public static Config defaultConfig() {