diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2025-01-13 20:04:51 +0100 | 
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-01-14 20:34:19 +0100 | 
| commit | 03b5f52091a6a25218911255eb00439384bd24c4 (patch) | |
| tree | baad06a0915af569d11f5e38c249de80e0cc5ce8 | |
| parent | 30e48ddd5d7b6c94b5cb22e645b1fcc4b994cabd (diff) | |
Cache git tree id of a commit after first load
| -rw-r--r-- | src/Repo.hs | 14 | 
1 files changed, 11 insertions, 3 deletions
| diff --git a/src/Repo.hs b/src/Repo.hs index 1148972..45fdb04 100644 --- a/src/Repo.hs +++ b/src/Repo.hs @@ -36,6 +36,7 @@ data Commit = Commit      { commitRepo :: Repo      , commitId :: CommitId      , commitDescription :: Text +    , commitTreeId :: MVar (Maybe TreeId)      } @@ -79,6 +80,7 @@ listCommits commitRepo range = liftIO $ do          let ( cid, desc ) = fmap (drop 1) $ (span (/=' ')) line              commitId = CommitId (BC.pack cid)              commitDescription = T.pack desc +        commitTreeId <- newMVar Nothing          return Commit {..} @@ -94,9 +96,15 @@ checkoutAt Commit {..} dest = do  readTreeId :: (MonadIO m, MonadFail m) => Commit -> m TreeId  readTreeId Commit {..} = do      let GitRepo {..} = commitRepo -    liftIO $ withMVar gitLock $ \_ -> do -        [ "tree", tid ] : _ <- map words . lines <$> readProcess "git" [ "--git-dir=" <> gitDir, "cat-file", "commit", showCommitId commitId ] "" -        return $ TreeId $ BC.pack tid +    liftIO $ do +        modifyMVar commitTreeId $ \case +            Just tid -> do +                return ( Just tid, tid ) +            Nothing -> do +                withMVar gitLock $ \_ -> do +                    [ "tree", stid ] : _ <- map words . lines <$> readProcess "git" [ "--git-dir=" <> gitDir, "cat-file", "commit", showCommitId commitId ] "" +                    let tid = TreeId $ BC.pack stid +                    return ( Just tid, tid )  readCommittedFile :: Commit -> FilePath -> IO (Maybe BL.ByteString) |