more RawFilePath conversion

Converted file mode setting to it, and follow-on changes.

Compiles up through 369/646.

This commit was sponsored by Ethan Aubin.
This commit is contained in:
Joey Hess 2020-11-05 18:45:37 -04:00
parent 9b0dde834e
commit 2c8cf06e75
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
31 changed files with 239 additions and 182 deletions

View file

@ -5,39 +5,45 @@
- Licensed under the GNU AGPL version 3 or higher.
-}
{-# LANGUAGE OverloadedStrings #-}
module Git.Objects where
import Common
import Git
import Git.Sha
objectsDir :: Repo -> FilePath
objectsDir r = fromRawFilePath (localGitDir r) </> "objects"
import qualified Data.ByteString as B
import qualified System.FilePath.ByteString as P
packDir :: Repo -> FilePath
packDir r = objectsDir r </> "pack"
objectsDir :: Repo -> RawFilePath
objectsDir r = localGitDir r P.</> "objects"
packIdxFile :: FilePath -> FilePath
packIdxFile = flip replaceExtension "idx"
packDir :: Repo -> RawFilePath
packDir r = objectsDir r P.</> "pack"
packIdxFile :: RawFilePath -> RawFilePath
packIdxFile = flip P.replaceExtension "idx"
listPackFiles :: Repo -> IO [FilePath]
listPackFiles r = filter (".pack" `isSuffixOf`)
<$> catchDefaultIO [] (dirContents $ packDir r)
<$> catchDefaultIO [] (dirContents $ fromRawFilePath $ packDir r)
listLooseObjectShas :: Repo -> IO [Sha]
listLooseObjectShas r = catchDefaultIO [] $
mapMaybe (extractSha . encodeBS . concat . reverse . take 2 . reverse . splitDirectories)
<$> dirContentsRecursiveSkipping (== "pack") True (objectsDir r)
<$> dirContentsRecursiveSkipping (== "pack") True (fromRawFilePath (objectsDir r))
looseObjectFile :: Repo -> Sha -> FilePath
looseObjectFile r sha = objectsDir r </> prefix </> rest
looseObjectFile :: Repo -> Sha -> RawFilePath
looseObjectFile r sha = objectsDir r P.</> prefix P.</> rest
where
(prefix, rest) = splitAt 2 (fromRef sha)
(prefix, rest) = B.splitAt 2 (fromRef' sha)
listAlternates :: Repo -> IO [FilePath]
listAlternates r = catchDefaultIO [] (lines <$> readFile alternatesfile)
listAlternates r = catchDefaultIO [] $
lines <$> readFile (fromRawFilePath alternatesfile)
where
alternatesfile = objectsDir r </> "info" </> "alternates"
alternatesfile = objectsDir r P.</> "info" P.</> "alternates"
{- A repository recently cloned with --shared will have one or more
- alternates listed, and contain no loose objects or packs. -}