git-annex/Git/Objects.hs

36 lines
931 B
Haskell
Raw Normal View History

2013-10-20 21:50:51 +00:00
{- .git/objects
-
- Copyright 2013 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Git.Objects where
import Common
import Git
2013-11-20 22:31:00 +00:00
import Git.Sha
2013-10-20 21:50:51 +00:00
objectsDir :: Repo -> FilePath
objectsDir r = localGitDir r </> "objects"
packDir :: Repo -> FilePath
packDir r = objectsDir r </> "pack"
2013-11-20 22:31:00 +00:00
packIdxFile :: FilePath -> FilePath
packIdxFile = flip replaceExtension "idx"
2013-10-20 21:50:51 +00:00
listPackFiles :: Repo -> IO [FilePath]
listPackFiles r = filter (".pack" `isSuffixOf`)
<$> catchDefaultIO [] (dirContents $ packDir r)
2013-11-20 22:31:00 +00:00
listLooseObjectShas :: Repo -> IO [Sha]
listLooseObjectShas r = catchDefaultIO [] $
mapMaybe (extractSha . concat . reverse . take 2 . reverse . splitDirectories)
<$> dirContentsRecursiveSkipping (== "pack") True (objectsDir r)
2013-10-20 21:50:51 +00:00
looseObjectFile :: Repo -> Sha -> FilePath
looseObjectFile r sha = objectsDir r </> prefix </> rest
where
(prefix, rest) = splitAt 2 (fromRef sha)