Skip to content

Commit

Permalink
Added more helper functions, some of Index function implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
iand675 committed Aug 31, 2011
1 parent 32e4768 commit 14f0d44
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
9 changes: 8 additions & 1 deletion Data/Git/Helpers.hs
Expand Up @@ -18,4 +18,11 @@ ptrFunc f m = alloca $ \ptrptr -> do
result <- f ptrptr
ptr <- peek ptrptr
free ptrptr
result `errorOr` m ptr
result `errorOr` m ptr

stateMod :: Integral a1 => (Ptr a -> IO a1) -> ForeignPtr a -> IO ()
stateMod f p = withForeignPtr p $ \p' -> do
result <- f p'
result `errorOr` return ()

stateMod' = flip withForeignPtr
36 changes: 28 additions & 8 deletions Data/Git/Index.hs
Expand Up @@ -3,7 +3,7 @@ module Data.Git.Index (
IndexEntry,
open,
clear,
free,
-- free,
read,
write,
find,
Expand All @@ -27,24 +27,44 @@ import Data.Git.Types
import Bindings.Libgit2.Index
import Control.Exception
import System.FilePath
import Foreign.Marshal
import Foreign.C.String
import Foreign.Ptr
import Foreign.ForeignPtr
{-| Create a new bare Git index object as a memory representation
of the Git index file in 'index_path', without a repository
to back it.
Since there is no ODB or working directory behind this index,
any Index methods which rely on these (e.g. index_add) will
fail with a BareIndex error.
If you need to access the index of an actual repository,
use the Data.Git.Repository.index wrapper.
-}

open :: FilePath -> IO Index
open = undefined
open fp = withCString fp $ \fp' -> ptrFunc (\pp -> c'git_index_open pp fp') toIndex

clear :: Index -> IO ()
clear = undefined
free :: Index -> IO ()
free = undefined
clear = stateMod' c'git_index_clear . ixPrim
-- free :: Index -> IO ()
-- free = undefined
read :: Index -> IO ()
read = undefined
read = stateMod c'git_index_read . ixPrim

write :: Index -> IO ()
write = undefined
write = stateMod c'git_index_write . ixPrim

find :: Index -> FilePath -> IO Bool
find = undefined

unique :: Index -> IO ()
unique = undefined
unique = stateMod' c'git_index_uniq . ixPrim

add :: Index -> FilePath -> Int -> IO ()
add = undefined

addIndexEntry :: Index -> IndexEntry -> IO ()
addIndexEntry = undefined
append :: Index -> FilePath -> Int -> IO ()
Expand Down

0 comments on commit 14f0d44

Please sign in to comment.