aboutsummaryrefslogtreecommitdiff
path: root/Main.hs
diff options
context:
space:
mode:
authorMirek Kratochvil <miroslav.kratochvil@matfyz.cuni.cz>2026-09-11 13:23:22 +0200
committerMirek Kratochvil <miroslav.kratochvil@matfyz.cuni.cz>2026-09-11 13:23:22 +0200
commit50d75b061256fa0f4147797205496a5f71695727 (patch)
tree0b22ec4d9ac354f3422d7db1ee490c5ce94d38c1 /Main.hs
parent1f90f49af12705c2038c30412f94937f7e6fc9fe (diff)
downloadgit-auto-acp-50d75b061256fa0f4147797205496a5f71695727.tar.gz
git-auto-acp-50d75b061256fa0f4147797205496a5f71695727.tar.bz2
dedent more
Diffstat (limited to 'Main.hs')
-rw-r--r--Main.hs96
1 files changed, 45 insertions, 51 deletions
diff --git a/Main.hs b/Main.hs
index d0479b0..278e92e 100644
--- a/Main.hs
+++ b/Main.hs
@@ -202,57 +202,51 @@ mainLoop ::
String -> ([Char] -> IO ()) -> Chan Event -> MVar () -> Opts -> St -> IO ()
mainLoop git dbg chan done o = loop
where
- loop st@St {..} = do
+ loop st = do
ev <- readChan chan
dbg $ "processing event: " ++ show ev
now <- getTime Monotonic
- case ev of
- Finished -> putMVar done ()
- Change w -> do
- void . forkIO
- $ delaySec (optAddCommitDelay o) >> writeChan chan AddBounce
- let ws' = S.insert w stWatch
- case optPushDelay o of
- Nothing ->
- loop st {stWatch = ws', stAddsPending = succ stAddsPending}
- Just pd -> do
- void . forkIO $ delaySec pd >> writeChan chan PushBounce
- loop
- st
- { stWatch = ws'
- , stAddsPending = succ stAddsPending
- , stPushesPending = succ stPushesPending
- }
- AddBounce
- | not (S.null stWatch)
- , 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
- if addAll
- then runCmd git ["add", p]
- else runCmd git ["add", "--ignore-removal", p]
- dbg "commit!"
- runCmd git ["commit", "--message", mkMsg stCommitSeries $ optMsg o]
- loop
- st
- { stWatch = S.empty
- , stLastAdd = now
- , stAddsPending = 0
- , stCommitSeries = succ stCommitSeries
- }
- | otherwise ->
- 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
- , stPushesPending = 0 `max` pred stPushesPending
- }
+ handle now st ev
+ handle _ _ Finished = putMVar done ()
+ handle _ st@St {..} (Change w) = do
+ void . forkIO $ delaySec (optAddCommitDelay o) >> writeChan chan AddBounce
+ let ws' = S.insert w stWatch
+ case optPushDelay o of
+ Nothing -> loop st {stWatch = ws', stAddsPending = succ stAddsPending}
+ Just pd -> do
+ void . forkIO $ delaySec pd >> writeChan chan PushBounce
+ loop
+ st
+ { stWatch = ws'
+ , stAddsPending = succ stAddsPending
+ , stPushesPending = succ stPushesPending
+ }
+ handle now st@St {..} AddBounce
+ | not (S.null stWatch)
+ , 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
+ if addAll
+ then runCmd git ["add", p]
+ else runCmd git ["add", "--ignore-removal", p]
+ dbg "commit!"
+ runCmd git ["commit", "--message", mkMsg stCommitSeries $ optMsg o]
+ loop
+ st
+ { stWatch = S.empty
+ , stLastAdd = now
+ , stAddsPending = 0
+ , stCommitSeries = succ stCommitSeries
+ }
+ | otherwise =
+ loop st {stWatch = S.empty, stAddsPending = 0 `max` pred stAddsPending}
+ handle now st@St {..} 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, stPushesPending = 0 `max` pred stPushesPending}