Merge branch 'stable-2.15' into stable-2.16

* stable-2.15:
  Update bazlets to latest revision on stable-2.15
  Update bazlets to latest revision on stable-2.14

Change-Id: I80f334a77e22f0423ad29ace0dd8d966a8318b81
diff --git a/BUILD b/BUILD
index 116cd88..3428c43 100644
--- a/BUILD
+++ b/BUILD
@@ -48,6 +48,7 @@
         "@cm-autolink//jar",
         "@commonmark//jar",
         "@commons-lang3//jar",
+        "@commons-text//jar",
         "@gfm-strikethrough//jar",
         "@gfm-tables//jar",
         "@gitiles-servlet//jar",
diff --git a/WORKSPACE b/WORKSPACE
index 081c73a..19991fe 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
 load("//:bazlets.bzl", "load_bazlets")
 
 load_bazlets(
-    commit = "8386b3fbf80e375f0a10c8386c0a8dfe260c5c1b",
+    commit = "5c1e201c6835e56a69a980c72206431e2a9d7d80",
     #local_path = "/home/<user>/projects/bazlets",
 )
 
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
index 85c3a37..5f4313d 100644
--- a/external_plugin_deps.bzl
+++ b/external_plugin_deps.bzl
@@ -5,8 +5,8 @@
 def external_plugin_deps():
     maven_jar(
         name = "gitiles-servlet",
-        artifact = "com.google.gitiles:gitiles-servlet:0.2-5",
-        sha1 = "18186bd83a8c52a4a965472fcb9b4ea87862eb35",
+        artifact = "com.google.gitiles:gitiles-servlet:0.2-7",
+        sha1 = "f23b22cb27fe5c4a78f761492082159d17873f57",
         repository = GERRIT,
     )
 
@@ -23,6 +23,12 @@
         sha1 = "557edd918fd41f9260963583ebf5a61a43a6b423",
     )
 
+    maven_jar(
+        name = "commons-text",
+        artifact = "org.apache.commons:commons-text:1.2",
+        sha1 = "74acdec7237f576c4803fff0c1008ab8a3808b2b",
+    )
+
     # commonmark must match the version used in Gitiles
     maven_jar(
         name = "commonmark",
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 039f78f..3dee013 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/FilteredRepository.java
@@ -21,8 +21,8 @@
 import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.git.GitRepositoryManager;
-import com.google.gerrit.server.git.VisibleRefFilter;
 import com.google.gerrit.server.permissions.PermissionBackend;
+import com.google.gerrit.server.permissions.PermissionBackend.RefFilterOptions;
 import com.google.gerrit.server.permissions.PermissionBackendException;
 import com.google.gerrit.server.permissions.ProjectPermission;
 import com.google.gerrit.server.project.NoSuchProjectException;
@@ -49,7 +49,6 @@
     private final Provider<CurrentUser> userProvider;
     private final ProjectCache projectCache;
     private final GitRepositoryManager repoManager;
-    private final VisibleRefFilter.Factory visibleRefFilterFactory;
     private final PermissionBackend permissionBackend;
 
     @Inject
@@ -57,12 +56,10 @@
         ProjectCache projectCache,
         Provider<CurrentUser> userProvider,
         GitRepositoryManager repoManager,
-        VisibleRefFilter.Factory visibleRefFilterFactory,
         PermissionBackend permissionBackend) {
       this.userProvider = userProvider;
       this.projectCache = projectCache;
       this.repoManager = repoManager;
-      this.visibleRefFilterFactory = visibleRefFilterFactory;
       this.permissionBackend = permissionBackend;
     }
 
@@ -73,11 +70,7 @@
         throw new NoSuchProjectException(name);
       }
       return new FilteredRepository(
-          projectState,
-          userProvider.get(),
-          repoManager.openRepository(name),
-          visibleRefFilterFactory,
-          permissionBackend);
+          projectState, userProvider.get(), repoManager.openRepository(name), permissionBackend);
     }
   }
 
@@ -88,7 +81,6 @@
       ProjectState projectState,
       CurrentUser user,
       Repository delegate,
-      VisibleRefFilter.Factory refFilterFactory,
       PermissionBackend permissionBackend)
       throws PermissionBackendException {
     super(toBuilder(delegate));
@@ -106,7 +98,7 @@
 
       this.refdb =
           new FilteredRefDatabase(
-              delegate.getRefDatabase(), refFilterFactory.create(projectState, delegate));
+              delegate, permissionBackend.user(user).project(projectState.getNameKey()));
     }
   }
 
@@ -152,7 +144,7 @@
   }
 
   @Override
-  public void notifyIndexChanged() {
+  public void notifyIndexChanged(boolean internal) {
     throw new UnsupportedOperationException(); // Gitiles is read-only.
   }
 
@@ -167,12 +159,12 @@
   }
 
   private static class FilteredRefDatabase extends RefDatabase {
-    private final RefDatabase delegate;
-    private final VisibleRefFilter refFilter;
+    private final Repository git;
+    private final PermissionBackend.ForProject perm;
 
-    private FilteredRefDatabase(RefDatabase delegate, VisibleRefFilter refFilter) {
-      this.delegate = delegate;
-      this.refFilter = refFilter;
+    private FilteredRefDatabase(Repository git, PermissionBackend.ForProject perm) {
+      this.git = git;
+      this.perm = perm;
     }
 
     @Override
@@ -187,7 +179,7 @@
 
     @Override
     public boolean isNameConflicting(String name) throws IOException {
-      return delegate.isNameConflicting(name);
+      return git.getRefDatabase().isNameConflicting(name);
     }
 
     @Override
@@ -202,25 +194,50 @@
 
     @Override
     public Ref exactRef(String name) throws IOException {
-      Ref ref = delegate.exactRef(name);
+      Ref ref = git.getRefDatabase().exactRef(name);
       if (ref == null) {
         return null;
       }
-      return refFilter.filter(ImmutableMap.of(name, ref), true).get(name);
+      try {
+        return perm.filter(
+                ImmutableMap.of(name, ref),
+                git,
+                RefFilterOptions.builder().setFilterTagsSeparately(true).build())
+            .get(name);
+      } catch (PermissionBackendException e) {
+        throw new IOException(e);
+      }
     }
 
     @Override
     public Ref getRef(String name) throws IOException {
-      Ref ref = delegate.getRef(name);
+      Ref ref = git.getRefDatabase().getRef(name);
       if (ref == null) {
         return null;
       }
-      return refFilter.filter(ImmutableMap.of(ref.getName(), ref), true).get(ref.getName());
+      try {
+        return perm.filter(
+                ImmutableMap.of(ref.getName(), ref),
+                git,
+                RefFilterOptions.builder().setFilterTagsSeparately(true).build())
+            .get(ref.getName());
+      } catch (PermissionBackendException e) {
+        throw new IOException(e);
+      }
     }
 
     @Override
     public Map<String, Ref> getRefs(String prefix) throws IOException {
-      Map<String, Ref> refs = refFilter.filter(delegate.getRefs(prefix), true);
+      Map<String, Ref> refs;
+      try {
+        refs =
+            perm.filter(
+                git.getRefDatabase().getRefs(prefix),
+                git,
+                RefFilterOptions.builder().setFilterTagsSeparately(true).build());
+      } catch (PermissionBackendException e) {
+        throw new IOException(e);
+      }
       Map<String, Ref> result = Maps.newHashMapWithExpectedSize(refs.size());
       for (Ref ref : refs.values()) {
         // VisibleRefFilter adds the prefix to the keys, re-strip it.
@@ -231,7 +248,7 @@
 
     @Override
     public List<Ref> getAdditionalRefs() throws IOException {
-      List<Ref> refs = delegate.getAdditionalRefs();
+      List<Ref> refs = git.getRefDatabase().getAdditionalRefs();
       Map<String, Ref> result = Maps.newHashMapWithExpectedSize(refs.size());
       for (Ref ref : refs) {
         result.put(ref.getName(), ref);
@@ -241,7 +258,7 @@
 
     @Override
     public Ref peel(Ref ref) throws IOException {
-      return delegate.peel(ref);
+      return git.getRefDatabase().peel(ref);
     }
   }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/gitiles/GerritGitilesAccess.java b/src/main/java/com/googlesource/gerrit/plugins/gitiles/GerritGitilesAccess.java
index 3b5550a..3b833ba 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/GerritGitilesAccess.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/GerritGitilesAccess.java
@@ -24,10 +24,10 @@
 import com.google.gerrit.server.config.AnonymousCowardName;
 import com.google.gerrit.server.config.SitePaths;
 import com.google.gerrit.server.permissions.PermissionBackendException;
-import com.google.gerrit.server.project.ListProjects;
 import com.google.gerrit.server.project.ProjectCache;
 import com.google.gerrit.server.project.ProjectJson;
 import com.google.gerrit.server.project.ProjectState;
+import com.google.gerrit.server.restapi.project.ListProjects;
 import com.google.gitiles.GitilesAccess;
 import com.google.gitiles.GitilesUrls;
 import com.google.gitiles.RepositoryDescription;
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 9402bf4..d91f831 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/gitiles/HttpModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/gitiles/HttpModule.java
@@ -14,6 +14,7 @@
 
 package com.googlesource.gerrit.plugins.gitiles;
 
+import com.google.common.flogger.FluentLogger;
 import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.config.SitePaths;
 import com.google.gitiles.GitilesAccess;
@@ -43,8 +44,6 @@
 import org.eclipse.jgit.storage.file.FileBasedConfig;
 import org.eclipse.jgit.transport.resolver.RepositoryResolver;
 import org.eclipse.jgit.util.FS;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 class HttpModule extends ServletModule {
   private final Provider<CurrentUser> userProvider;
@@ -86,7 +85,7 @@
     };
   }
 
-  private static final Logger log = LoggerFactory.getLogger(HttpModule.class);
+  private static final FluentLogger log = FluentLogger.forEnclosingClass();
 
   @Override
   protected void configureServlets() {
@@ -127,7 +126,7 @@
     if (cfg.getFile().exists()) {
       cfg.load();
     } else {
-      log.info("No " + cfgFile.getAbsolutePath() + "; assuming defaults");
+      log.atInfo().log("No %s; assuming defaults", cfgFile.getAbsolutePath());
     }
     return cfg;
   }