Don't lose state when there's a pending push to the same ref

Previously if there was already a pending push (not an in-flight push)
to the same endpoint, the start for the push would be dropped when
adding the push to the Destination. This meant that a replication start
--wait command would never complete when one of its pushes was pending
since its state would never receive the completion notification for that
push.

Fix this by always adding the state and the ref in the Destination class
and preventing the duplicate "addRef" log message in the PushOne class.

Bug: Issue 12731
Change-Id: I33e6af2709bc38aac791a2f60fd896492167bbf5
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 966248a..f4c8133 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
@@ -419,7 +419,7 @@
         ScheduledFuture<?> ignored =
             pool.schedule(task, now ? 0 : config.getDelay(), TimeUnit.SECONDS);
         pending.put(uri, task);
-      } else if (!task.getRefs().contains(ref)) {
+      } else {
         addRef(task, ref);
         task.addState(ref, state);
       }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
index 8ccd54a..ee29162 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
@@ -228,8 +228,7 @@
       delta.clear();
       pushAllRefs = true;
       repLog.trace("Added all refs for replication to {}", uri);
-    } else if (!pushAllRefs) {
-      delta.add(ref);
+    } else if (!pushAllRefs && delta.add(ref)) {
       repLog.trace("Added ref {} for replication to {}", ref, uri);
     }
   }