more OsPath conversion

About 1/10th done with this I think.
This commit is contained in:
Joey Hess 2025-01-24 13:40:09 -04:00
parent 8021d22955
commit c412c59ecd
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
16 changed files with 152 additions and 142 deletions

View file

@ -12,6 +12,7 @@ module Git.Objects where
import Common
import Git
import Git.Sha
import qualified Utility.OsString as OS
import qualified Data.ByteString as B
import qualified System.FilePath.ByteString as P
@ -31,10 +32,19 @@ listPackFiles r = filter (".pack" `B.isSuffixOf`)
listLooseObjectShas :: Repo -> IO [Sha]
listLooseObjectShas r = catchDefaultIO [] $
mapMaybe (extractSha . encodeBS . concat . reverse . take 2 . reverse . splitDirectories . decodeBS)
<$> emptyWhenDoesNotExist (dirContentsRecursiveSkipping (== "pack") True (objectsDir r))
mapMaybe conv <$> emptyWhenDoesNotExist
(dirContentsRecursiveSkipping (== "pack") True (objectsDir r))
where
conv :: OsPath -> Maybe Sha
conv = extractSha
. fromOsPath
. OS.concat
. reverse
. take 2
. reverse
. splitDirectories
looseObjectFile :: Repo -> Sha -> RawFilePath
looseObjectFile :: Repo -> Sha -> OsPath
looseObjectFile r sha = objectsDir r P.</> prefix P.</> rest
where
(prefix, rest) = B.splitAt 2 (fromRef' sha)