diff options
| author | Mirek Kratochvil <miroslav.kratochvil@matfyz.cuni.cz> | 2026-09-11 11:26:12 +0200 |
|---|---|---|
| committer | Mirek Kratochvil <miroslav.kratochvil@matfyz.cuni.cz> | 2026-09-11 11:26:12 +0200 |
| commit | 643639f01cb94a4e663338aabdd9dd9c35d738b0 (patch) | |
| tree | 7e1a1e19d9c87f1acf98d6df0158617fde0f5501 | |
| parent | 48d42ef2e5f6c615725ee3b6017a5ceef68ca13e (diff) | |
| download | git-auto-acp-643639f01cb94a4e663338aabdd9dd9c35d738b0.tar.gz git-auto-acp-643639f01cb94a4e663338aabdd9dd9c35d738b0.tar.bz2 | |
fix the debouncing logic
| -rw-r--r-- | Main.hs | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -169,9 +169,9 @@ main = do , stAddsPending = succ stAddsPending , stPushesPending = succ stPushesPending } - AddBounce -- TODO the last trigger looks nice but may cause double add, instead track an increasing token or such + AddBounce | not (S.null stWatch) - , stAddsPending == 1 + , stAddsPending == 1 {- protection against triggering too early -} || intervalPassed (optAddCommitDelay o) now stLastAdd -> do for_ stWatch $ \w@(Watch p addAll) -> do dbg $ "will add: " ++ show w @@ -186,25 +186,28 @@ main = do st { stWatch = S.empty , stLastAdd = now - , stAddsPending = pred stAddsPending + , stAddsPending = 0 , stCommitSeries = succ stCommitSeries } | otherwise -> - loop st {stWatch = S.empty, stAddsPending = pred stAddsPending} + loop + st + { stWatch = S.empty + , stAddsPending = 0 `max` pred stAddsPending + } PushBounce | Just pd <- optPushDelay o , stPushesPending == 1 || intervalPassed pd now stLastPush -> do dbg $ "push!" runCmd git ["push"] loop + st {stWatch = S.empty, stLastPush = now, stPushesPending = 0} + | otherwise -> + loop st { stWatch = S.empty - , stLastPush = now - , stPushesPending = pred stPushesPending + , stPushesPending = 0 `max` pred stPushesPending } - | otherwise -> - loop - st {stWatch = S.empty, stPushesPending = pred stPushesPending} void . forkIO $ loop emptyState -- wait for the finish, then terminate takeMVar done |
