Fix cases where replication is waiting indefinitely

In change [1], we started to avoid starting replication tasks which are
not present in ../waiting dir. But the replication commands were waiting
due to state not being updated for the work which is avoided. This
change marks the refs which are neglected as not attempted and in turn
notifies that update to ReplicationState object.

This fix only affects correctness of an internal state.

[1] Ifbb7018ec1d960015626c089a4dadf6b0247d278

Change-Id: Iff31d62ebbbfb88754b43b60344e05dd4b0a1f6d
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 12f0273..0b0b58a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
@@ -583,7 +583,7 @@
       if (inFlightOp != null) {
         return RunwayStatus.denied(inFlightOp.getId());
       }
-      op.setRefs(replicationTasksStorage.get().start(op));
+      op.notifyNotAttempted(op.setStartedRefs(replicationTasksStorage.get().start(op)));
       inFlight.put(op.getURI(), op);
     }
     return RunwayStatus.allowed();
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 565790c..eaed4cf 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
@@ -52,6 +52,7 @@
 import com.jcraft.jsch.JSchException;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -270,10 +271,26 @@
     }
   }
 
-  void setRefs(Set<String> refs) {
+  Set<String> setStartedRefs(Set<String> startedRefs) {
+    Set<String> notAttemptedRefs = Sets.difference(delta, startedRefs);
     pushAllRefs = false;
     delta.clear();
-    addRefs(refs);
+    addRefs(startedRefs);
+    return notAttemptedRefs;
+  }
+
+  void notifyNotAttempted(Set<String> notAttemptedRefs) {
+    notAttemptedRefs.forEach(
+        ref ->
+            Arrays.asList(getStatesByRef(ref))
+                .forEach(
+                    state ->
+                        state.notifyRefReplicated(
+                            projectName.get(),
+                            ref,
+                            uri,
+                            RefPushResult.NOT_ATTEMPTED,
+                            RemoteRefUpdate.Status.UP_TO_DATE)));
   }
 
   void addState(String ref, ReplicationState state) {