From 5e68d300aad04406adcc974a64e7436b7b2f8cea Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Wed, 5 Jun 2024 17:59:04 +0200 Subject: add `withCommit` --- src/Store/Store.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/Store/Store.hs b/src/Store/Store.hs index 511d822..b58a2da 100644 --- a/src/Store/Store.hs +++ b/src/Store/Store.hs @@ -1,6 +1,7 @@ module Store.Store ( StoreM, withStore, + withCommit, listFiles, readFile, writeFile, @@ -72,11 +73,22 @@ withStore repoPath ref action = do Just cid <- fmap Tagged <$> G.resolveReference ref tid <- (.commitTree) <$> G.lookupCommit cid pure (cid, tid) + runReaderT (evalStateT (runStoreT action) (State {cid, tid})) (Env {repo, ref}) `finally` G.runRepository GB.lgFactory repo G.closeRepository +withCommit :: G.CommitOid GB.LgRepo -> StoreM a -> StoreM a +withCommit cid action = do + Env {repo, ref} <- ask + liftIO do + tid <- G.runRepository GB.lgFactory repo do + (.commitTree) <$> G.lookupCommit cid + runReaderT + (evalStateT (runStoreT action) (State {cid, tid})) + (Env {repo, ref}) + listDirectory :: FilePath -> StoreM [FilePath] listDirectory dir' = do State {tid} <- get -- cgit v1.2.3