@@ -54,43 +54,41 @@ idxExtFlags = fromEnum IntentToAdd .|. fromEnum SkipWorkTree
5454-- index file in the provided path, without a repository to back it.
5555openIndex :: String -> IO (Either GitError Index )
5656openIndex path = alloca $ \ index -> do
57- pth <- newCString path
58- res <- {# call git_index_open# } index pth
57+ res <- {# call git_index_open# } index =<< newCString path
5958 retEither res $ fmap (Right . Index ) $ peek index
6059
6160-- | Clear the contents (all the entries) of an index object. This clears the
6261-- index object in memory; changes must be manually written to disk for them to
6362-- take effect.
6463clearIndex :: Index -> IO ()
65- clearIndex ( Index idx) = {# call git_index_clear# } idx
64+ clearIndex = {# call git_index_clear# } . unwrap
6665
6766-- | Free an existing index object.
6867freeIndex :: Index -> IO ()
69- freeIndex ( Index idx) = {# call git_index_free# } idx
68+ freeIndex = {# call git_index_free# } . unwrap
7069
7170-- | Update the contents of an existing index object in memory by reading from
7271-- the hard disk.
7372readIndex :: Index -> IO (Maybe GitError )
74- readIndex ( Index idx) = retMaybe =<< {# call git_index_read# } idx
73+ readIndex = callRetMaybe {# call git_index_read# }
7574
7675-- | Write an existing index object from memory back to disk using an atomic
7776-- file lock.
7877writeIndex :: Index -> IO (Maybe GitError )
79- writeIndex ( Index idx) = retMaybe =<< {# call git_index_write# } idx
78+ writeIndex = callRetMaybe {# call git_index_write# }
8079
8180-- | Find the first index of any entries which point to given path in the Git
8281-- index.
8382findIndex :: Index -> String -> IO (Maybe Int )
8483findIndex (Index idx) path = do
85- pth <- newCString path
86- res <- {# call git_index_find# } idx pth
84+ res <- {# call git_index_find# } idx =<< newCString path
8785 return $ if res >= 0
8886 then Just $ fromIntegral res
8987 else Nothing
9088
9189-- | Remove all entries with equal path except last added
9290uniqIndex :: Index -> IO ()
93- uniqIndex ( Index idx) = {# call git_index_uniq# } idx
91+ uniqIndex = {# call git_index_uniq# } . unwrap
9492
9593-- | Add or update an index entry from a file in disk
9694addIndex :: Index -> String -> Int -> IO (Maybe GitError )
@@ -126,13 +124,11 @@ getIndex (Index idx) n =
126124
127125-- | Get the count of entries currently in the index
128126entryCount :: Index -> IO Int
129- entryCount (Index idx) =
130- return . fromIntegral =<< {# call git_index_entrycount# } idx
127+ entryCount = callRetNum {# call git_index_entrycount# }
131128
132129-- | Get the count of unmerged entries currently in the index
133130entryCountUnMerged :: Index -> IO Int
134- entryCountUnMerged (Index idx) =
135- return . fromIntegral =<< {# call git_index_entrycount_unmerged# } idx
131+ entryCountUnMerged = callRetNum {# call git_index_entrycount_unmerged# }
136132
137133retIEU :: CPtr -> IO (Maybe IndexEntryUnMerged )
138134retIEU = retRes IndexEntryUnMerged
@@ -149,5 +145,4 @@ unmergedByIndex (Index idx) n =
149145
150146-- | Return the stage number from a git index entry
151147entryStage :: IndexEntry -> IO Int
152- entryStage (IndexEntry ie) =
153- return . fromIntegral =<< {# call git_index_entry_stage# } ie
148+ entryStage = callRetNum {# call git_index_entry_stage# }
0 commit comments