Permalink
Browse files

Repository

  • Loading branch information...
1 parent 6f14628 commit 07d7a44b22e3aaf5bd765d69862dc051c8677874 @norm2782 committed Jul 25, 2011
@@ -59,15 +59,15 @@ author = sigCall {#call unsafe git_commit_author#}
tree :: Commit -> IOEitherErr Tree
tree (Commit cfp) =
withForeignPtr cfp $ \c ->
- callPeek' Tree (\out -> {#call git_commit_tree#} out c)
+ callPeek Tree (\out -> {#call git_commit_tree#} out c)
parentCount :: Commit -> IO Int
parentCount = undefined -- wrapToMNum {#call git_commit_parentcount#}
parent :: Commit -> Int -> IOEitherErr Commit
parent (Commit cfp) n =
withForeignPtr cfp $ \c ->
- callPeek' Commit (\out -> {#call git_commit_parent#} out c (fromIntegral n))
+ callPeek Commit (\out -> {#call git_commit_parent#} out c (fromIntegral n))
parentOID :: Commit -> Int -> IO (Maybe OID)
parentOID (Commit cfp) n =
@@ -37,7 +37,7 @@ findGlobalConfig = alloca $ \pth -> do
-- | Open the global configuration file
openGlobalConfig :: IOEitherErr Config
-openGlobalConfig = callPeek' Config {#call git_config_open_global#}
+openGlobalConfig = callPeek Config {#call git_config_open_global#}
-- | Create a configuration file backend for ondisk files
--
@@ -46,14 +46,14 @@ openGlobalConfig = callPeek' Config {#call git_config_open_global#}
-- query it for configuration variables.
createOnDisk :: String -> IOEitherErr ConfigFile
createOnDisk str = withCString str $ \str' ->
- callPeek' ConfigFile (\out -> {#call git_config_file__ondisk#} out str')
+ callPeek ConfigFile (\out -> {#call git_config_file__ondisk#} out str')
-- | Allocate a new configuration object
--
-- This object is empty, so you have to add a file to it before you can do
-- anything with it.
newConfig :: IOEitherErr Config
-newConfig = callPeek' Config {#call git_config_new#}
+newConfig = callPeek Config {#call git_config_new#}
-- | Add a generic config file instance to an existing config
--
@@ -92,23 +92,23 @@ addOnDisk (Config cfp) pth pr =
openOnDisk :: String -> IOEitherErr Config
openOnDisk str =
withCString str $ \str' ->
- callPeek' Config (\out -> {#call git_config_open_ondisk#} out str')
+ callPeek Config (\out -> {#call git_config_open_ondisk#} out str')
-- | Get the value of an integer config variable.
configInt :: Config -> String -> IOEitherErr Int
configInt (Config cfp) str =
withForeignPtr cfp $ \c ->
withCString str $ \str' ->
undefined
- {- callPeek' fromIntegral ({#call git_config_get_int#} c str')-}
+ {- callPeek fromIntegral ({#call git_config_get_int#} c str')-}
-- | Get the value of an integer config variable.
configInteger :: Config -> String -> IOEitherErr Integer
configInteger (Config cfp) str =
withForeignPtr cfp $ \c ->
withCString str $ \str' ->
undefined
- {- callPeek' fromIntegral ({#call git_config_get_long#} c str')-}
+ {- callPeek fromIntegral ({#call git_config_get_long#} c str')-}
-- | Get the value of a boolean config variable.
configBool :: Config -> String -> IO (Either GitError Bool)
@@ -35,7 +35,7 @@ retRes con fp = withForeignPtr fp $ return . ret
where ret res | res == nullPtr = Nothing
| otherwise = Just $ con fp
-{- retRes' :: Monad m => (Ptr a -> b) -> m (Ptr a) -> m (Maybe b)-}
+retRes' :: (Ptr b -> a) -> IO (ForeignPtr b) -> IO (Maybe a)
retRes' con ptr = do
fp <- ptr
withForeignPtr fp $ return . retRes''
@@ -76,12 +76,9 @@ retEnum a = return . toEnum . fromIntegral =<< a
{- callRetMaybe :: CWrapper a => (CPtr -> IO CInt) -> a -> IOCanFail-}
{- callRetMaybe call = (retMaybe =<<) . call . unwrap-}
-{- callPeek :: Storable b => (b -> a) -> (Ptr b -> IO CInt) -> IOEitherErr a-}
-{- callPeek con call = alloca $ \out -> eitherPeek out con =<< call out-}
-
-callPeek' :: (ForeignPtr a1 -> a) -> (Ptr (Ptr a1) -> IO CInt)
- -> IO (Either GitError a)
-callPeek' con call = alloca $ \out -> eitherPeek' out con =<< call out
+callPeek :: (ForeignPtr a1 -> a) -> (Ptr (Ptr a1) -> IO CInt)
+ -> IO (Either GitError a)
+callPeek con call = alloca $ \out -> eitherPeek' out con =<< call out
eitherPeek' :: Ptr (Ptr a1) -> (ForeignPtr a1 -> a) -> CInt -> IOEitherErr a
eitherPeek' ptr = eitherCon (newForeignPtr finalizerFree =<< peek ptr)
@@ -91,3 +88,6 @@ eitherPeek' ptr = eitherCon (newForeignPtr finalizerFree =<< peek ptr)
mkFPtr :: Ptr a -> IO (ForeignPtr a)
mkFPtr = newForeignPtr finalizerFree
+
+unEnum :: (Enum a, Integral i) => a -> i
+unEnum = fromIntegral . fromEnum
@@ -54,7 +54,7 @@ idxExtFlags = fromEnum IntentToAdd .|. fromEnum SkipWorkTree
-- index file in the provided path, without a repository to back it.
openIndex :: String -> IOEitherErr Index
openIndex path = withCString path $ \pth ->
- callPeek' Index (\out -> {#call git_index_open#} out pth)
+ callPeek Index (\out -> {#call git_index_open#} out pth)
-- | Clear the contents (all the entries) of an index object. This clears the
-- index object in memory; changes must be manually written to disk for them to
@@ -27,7 +27,7 @@ instance CWrapper ODBObj where
-- Before the ODB can be used for read/writing, a custom database backend must
-- be manually added using `git_odb_add_backend()`
newODB :: IOEitherErr ODB
-newODB = callPeek' ODB {#call git_odb_new#}
+newODB = callPeek ODB {#call git_odb_new#}
-- Create a new object database and automatically add the two default backends:
--
@@ -40,7 +40,7 @@ newODB = callPeek' ODB {#call git_odb_new#}
openODB :: String -> IOEitherErr ODB
openODB str =
withCString str $ \str' ->
- callPeek' ODB (\out -> {#call git_odb_open#} out str')
+ callPeek ODB (\out -> {#call git_odb_open#} out str')
-- | Add a custom backend to an existing Object DB
--
@@ -84,7 +84,7 @@ readODB :: ODB -> OID -> IOEitherErr ODBObj
readODB (ODB ofp) (OID ifp) =
withForeignPtr ofp $ \o ->
withForeignPtr ifp $ \i ->
- callPeek' ODBObj (\out -> {#call git_odb_read#} out o i)
+ callPeek ODBObj (\out -> {#call git_odb_read#} out o i)
-- | Read an object from the database, given a prefix of its identifier.
--
@@ -100,7 +100,7 @@ readPrefix :: ODB -> OID -> Int -> IOEitherErr ODBObj
readPrefix (ODB ofp) (OID ifp) n =
withForeignPtr ofp $ \o ->
withForeignPtr ifp $ \i ->
- callPeek' ODBObj (\out -> {#call git_odb_read_prefix#} out o i (fromIntegral n))
+ callPeek ODBObj (\out -> {#call git_odb_read_prefix#} out o i (fromIntegral n))
{-
/**
@@ -193,7 +193,7 @@ TODO: Finish this
openWStream :: ODB -> OType -> IOEitherErr ODBStream
openWStream (ODB ofp) oty =
withForeignPtr ofp $ \o ->
- callPeek' ODBStream (\out -> {#call git_odb_open_wstream#} out o undefined
+ callPeek ODBStream (\out -> {#call git_odb_open_wstream#} out o undefined
(fromIntegral $ fromEnum oty))
-- | Open a stream to read an object from the ODB
@@ -215,7 +215,7 @@ openRStream :: ODB -> OID -> IOEitherErr ODBStream
openRStream (ODB ofp) (OID ifp) =
withForeignPtr ofp $ \o ->
withForeignPtr ifp $ \i ->
- callPeek' ODBStream (\out -> {#call git_odb_open_rstream#} out o i)
+ callPeek ODBStream (\out -> {#call git_odb_open_rstream#} out o i)
{-
/**
@@ -25,4 +25,4 @@ looseBackend = backend {#call git_odb_backend_loose#}
backend :: (Ptr (Ptr ()) -> CString -> IO CInt) -> String
-> IOEitherErr ODBBackend
backend fn str = withCString str $ \str' ->
- callPeek' ODBBackend (\out -> fn out str')
+ callPeek ODBBackend (\out -> fn out str')
@@ -23,7 +23,7 @@ lookupObj :: Repository -> OID -> OType -> IOEitherErr GitObj
lookupObj (Repository fp) (OID ofp) oty =
withForeignPtr fp $ \r ->
withForeignPtr ofp $ \o ->
- callPeek' GitObj (\out -> {#call git_object_lookup#} out r o
+ callPeek GitObj (\out -> {#call git_object_lookup#} out r o
(fromIntegral $ fromEnum oty))
-- | Lookup a reference to one of the objects in a repostory, given a prefix of
@@ -33,7 +33,7 @@ lookupObjPref :: Repository -> OID -> Int -> OType -> IOEitherErr GitObj
lookupObjPref (Repository fp) (OID ofp) n oty =
withForeignPtr fp $ \r ->
withForeignPtr ofp $ \o ->
- callPeek' GitObj (\out -> {#call git_object_lookup_prefix#} out r o
+ callPeek GitObj (\out -> {#call git_object_lookup_prefix#} out r o
(fromIntegral n) (fromIntegral $ fromEnum oty))
-- | Get the id (SHA1) of a repository object
@@ -31,7 +31,7 @@ instance CWrapper ReflogEntry where
readReflog :: Reference -> IOEitherErr Reflog
readReflog (Reference rfp) =
withForeignPtr rfp $ \r ->
- callPeek' Reflog (\out -> {#call git_reflog_read#} out r)
+ callPeek Reflog (\out -> {#call git_reflog_read#} out r)
-- | Write a new reflog for the given reference
--
@@ -26,7 +26,7 @@ lookupRef :: Repository -> String -> IOEitherErr Reference
lookupRef (Repository fp) str =
withForeignPtr fp $ \r ->
withCString str $ \str' ->
- callPeek' Reference (\out -> {#call git_reference_lookup#} out r str')
+ callPeek Reference (\out -> {#call git_reference_lookup#} out r str')
-- | Create a new symbolic reference.
--
@@ -42,7 +42,7 @@ createSymRef (Repository fp) n t f =
withForeignPtr fp $ \r ->
withCString n $ \nm ->
withCString t $ \tg ->
- callPeek' Reference (\out -> {#call git_reference_create_symbolic#} out r nm
+ callPeek Reference (\out -> {#call git_reference_create_symbolic#} out r nm
tg (fromBool f))
-- | Create a new object id reference.
@@ -58,7 +58,7 @@ createOID :: Repository -> String -> OID -> Bool -> IOEitherErr Reference
createOID (Repository rfp) n (OID ifp) f =
withForeignPtr rfp $ \r ->
withForeignPtr ifp $ \i ->
- withCString n $ \ns -> callPeek' Reference
+ withCString n $ \ns -> callPeek Reference
(\out -> {#call git_reference_create_oid#} out r ns i (fromBool f))
-- | Get the OID pointed to by a reference.
@@ -102,7 +102,7 @@ refName (Reference rfp) =
resolveRef :: Reference -> IOEitherErr Reference
resolveRef (Reference rfp) =
withForeignPtr rfp $ \r ->
- callPeek' Reference (\out -> {#call git_reference_resolve#} out r)
+ callPeek Reference (\out -> {#call git_reference_resolve#} out r)
-- | Get the repository where a reference resides
refOwner :: Reference -> IO Repository
@@ -25,7 +25,7 @@ remote :: Config -> String -> IOEitherErr Remote
remote (Config cfp) str =
withForeignPtr cfp $ \c ->
withCString str $ \str' ->
- callPeek' Remote (\out -> {#call git_remote_get#} out c str')
+ callPeek Remote (\out -> {#call git_remote_get#} out c str')
-- | Get the remote's name
remoteName :: Remote -> String
@@ -45,7 +45,7 @@ repoIs ffi (Repository fp) =
openRepo :: String -> IOEitherErr Repository
openRepo pth =
withCString pth $ \pstr ->
- callPeek' Repository (\out -> {#call git_repository_open#} out pstr)
+ callPeek Repository (\out -> {#call git_repository_open#} out pstr)
-- | Open a git repository by manually specifying all its paths
openRepoObjDir :: String -> String -> String -> String
@@ -55,7 +55,7 @@ openRepoObjDir dir objDir idxFile workTree =
withCString objDir $ \objDStr ->
withCString idxFile $ \idxFStr ->
withCString workTree $ \wtrStr ->
- callPeek' Repository (\out -> {#call git_repository_open2#} out dirStr objDStr
+ callPeek Repository (\out -> {#call git_repository_open2#} out dirStr objDStr
idxFStr wtrStr)
-- | Open a git repository by manually specifying its paths and the object
@@ -66,7 +66,7 @@ openRepoODB dir (ODB dfp) idxFile workTree =
withCString dir $ \dirStr ->
withCString idxFile $ \idxFStr ->
withCString workTree $ \wtrStr ->
- callPeek' Repository (\out -> {#call git_repository_open3#} out dirStr db
+ callPeek Repository (\out -> {#call git_repository_open3#} out dirStr db
idxFStr wtrStr)
-- | Look for a git repository and copy its path in the given buffer.
@@ -86,12 +86,10 @@ discover sz startPath acrossFs ceilingDirs = alloca $ \out ->
eitherPeekStr out id res
-- | Get the object database behind a Git repository
--- TODO: Refactor
database :: Repository -> IO ODB
database (Repository fp) =
- withForeignPtr fp $ \r -> do
- p <- mkFPtr =<< {#call git_repository_database#} r
- return $ ODB p
+ withForeignPtr fp $ \r ->
+ fmap ODB $ mkFPtr =<< {#call git_repository_database#} r
-- | Open the Index file of a Git repository
--
@@ -108,13 +106,13 @@ database (Repository fp) =
index :: Repository -> IOEitherErr Index
index (Repository fp) =
withForeignPtr fp $ \r ->
- callPeek' Index (\out -> {#call git_repository_index#} out r)
+ callPeek Index (\out -> {#call git_repository_index#} out r)
-- | Creates a new Git repository in the given folder.
init :: String -> Bool -> IOEitherErr Repository
init pth bare =
withCString pth $ \pstr ->
- callPeek' Repository
+ callPeek Repository
(\out -> {#call git_repository_init#} out pstr (fromBool bare))
-- | Check if a repository's HEAD is detached
@@ -148,7 +146,7 @@ isEmpty = repoIs {#call git_repository_is_empty#}
path :: Repository -> RepositoryPathID -> IO String
path (Repository fp) pid =
withForeignPtr fp $ \r ->
- peekCString =<< {#call git_repository_path#} r (fromIntegral $ fromEnum pid)
+ peekCString =<< {#call git_repository_path#} r (unEnum pid)
-- | Check if a repository is bare
isBare :: Repository -> IO Bool
@@ -186,5 +184,5 @@ config (Repository rfp) up sp =
withForeignPtr rfp $ \r ->
withCString up $ \upt ->
withCString sp $ \spt ->
- callPeek' Config (\out -> {#call git_repository_config#} out r upt spt)
+ callPeek Config (\out -> {#call git_repository_config#} out r upt spt)
@@ -35,7 +35,7 @@ instance CWrapper RevWalk where
newWalk :: Repository -> IOEitherErr RevWalk
newWalk (Repository rfp) =
withForeignPtr rfp $ \r ->
- callPeek' RevWalk (\out -> {#call git_revwalk_new#} out r)
+ callPeek RevWalk (\out -> {#call git_revwalk_new#} out r)
-- | Reset the revision walker for reuse.
--
@@ -34,7 +34,7 @@ tagID = undefined -- callRetCons {#call git_tag_id#} OID
target :: Tag -> IOEitherErr Target
target (Tag tfp) =
withForeignPtr tfp $ \t ->
- callPeek' Target (\out -> {#call git_tag_target#} out t)
+ callPeek Target (\out -> {#call git_tag_target#} out t)
-- | Get the OID of the tagged object of a tag
targetOID :: Tag -> IO OID
@@ -19,7 +19,7 @@ instance CWrapper Transport where
new :: String -> IOEitherErr Transport
new u =
withCString u $ \url ->
- callPeek' Transport (\out -> {#call git_transport_new#} out url)
+ callPeek Transport (\out -> {#call git_transport_new#} out url)
connect :: Transport -> Int -> IOCanFail
connect (Transport tfp) n =
@@ -80,7 +80,7 @@ entryToObj :: Repository -> TreeEntry -> IOEitherErr GitObj
entryToObj (Repository rfp) (TreeEntry tfp) =
withForeignPtr rfp $ \r ->
withForeignPtr tfp $ \t ->
- callPeek' GitObj (\out -> {#call git_tree_entry_2object#} out r t)
+ callPeek GitObj (\out -> {#call git_tree_entry_2object#} out r t)
-- Write a tree to the ODB from the index file
createFromIndex :: OID -> Index -> IO (Maybe GitError)

0 comments on commit 07d7a44

Please sign in to comment.