aboutsummaryrefslogtreecommitdiff
path: root/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Main.hs')
-rw-r--r--Main.hs21
1 files changed, 12 insertions, 9 deletions
diff --git a/Main.hs b/Main.hs
index 7c27afe..4f0d399 100644
--- a/Main.hs
+++ b/Main.hs
@@ -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