Prevent creating repos on extra servers

If using a group to replicate only certain repositories, it is possible
to be in a state where the authGroup is used on some servers but not
others.  If this happened, Gerrit would create the repository on all
servers, even if the authGroup would prevent replicating code to it.
By ensuring the authGroup can see the project first, we don't create
the repository if it's not needed.

Bug: Issue 543
Change-Id: I2f189bdb6007228d0b25a6ce9c0357b3f97e4ced
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
index 20b0a3f..feff6c0 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
@@ -200,25 +200,29 @@
     return cfg.getInt("remote", rc.getName(), name, defValue);
   }
 
-  void schedule(final Project.NameKey project, final String ref,
-      final URIish uri, ReplicationState state) {
+  private boolean isVisible(final Project.NameKey project,
+      ReplicationState... states) {
     try {
-      boolean visible = threadScoper.scope(new Callable<Boolean>(){
+      return threadScoper.scope(new Callable<Boolean>() {
         @Override
         public Boolean call() throws NoSuchProjectException {
           return controlFor(project).isVisible();
         }
       }).call();
-      if (!visible) {
-        return;
-      }
     } catch (NoSuchProjectException err) {
-      stateLog.error(String.format(
-          "source project %s not available", project), err, state);
-      return;
+      stateLog.error(String.format("source project %s not available", project),
+          err, states);
     } catch (Exception e) {
       throw Throwables.propagate(e);
     }
+    return false;
+  }
+
+  void schedule(final Project.NameKey project, final String ref,
+      final URIish uri, ReplicationState state) {
+    if (!isVisible(project, state)) {
+      return;
+    }
 
     if (!replicatePermissions) {
       PushOne e;
@@ -380,7 +384,11 @@
     }
   }
 
-  boolean wouldPushProject(Project.NameKey project) {
+  boolean wouldPushProject(final Project.NameKey project) {
+    if (!isVisible(project)) {
+      return false;
+    }
+
     // by default push all projects
     if (projects.length < 1) {
       return true;