Skip to content

Commit efef677

Browse files
committed
Reflog
1 parent ebdf9e4 commit efef677

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/haskell/Data/HGit2/ODBBackend.chs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ looseBackend = backend {#call git_odb_backend_loose#}
2424

2525
backend :: (Ptr (Ptr ()) -> CString -> IO CInt) -> String
2626
-> IOEitherErr ODBBackend
27-
backend fn str = withCString str $ \str' ->
27+
backend fn str =
28+
withCString str $ \str' ->
2829
callPeek ODBBackend (\out -> fn out str')

src/haskell/Data/HGit2/Reflog.chs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,27 @@ writeReflog (Reference rfp) (OID ofp) (Signature sfp) str =
4646

4747
-- | Get the number of log entries in a reflog
4848
entryCount :: Reflog -> IO Int
49-
entryCount = undefined -- callRetNum {#call git_reflog_entrycount#}
49+
entryCount (Reflog rfp) =
50+
withForeignPtr rfp $ retNum . {#call git_reflog_entrycount#}
5051

5152
-- | Lookup an entry by its index
5253
entryByIndex :: Reflog -> Int -> IO (Maybe ReflogEntry)
5354
entryByIndex (Reflog rfp) n =
54-
withForeignPtr rfp $ \r ->
55-
undefined -- ReflogEntry ({#call git_reflog_entry_byindex#} r (fromIntegral n))
56-
57-
{- unsafeCallStr :: CWrapper a => (CPtr -> IO CString) -> a -> String-}
58-
unsafeCallStr call = undefined -- unsafePerformIO . (peekCString =<<) . call . unwrap
55+
withForeignPtr rfp $ \r -> do
56+
ptr <- mkFPtr =<< {#call git_reflog_entry_byindex#} r (fromIntegral n)
57+
retRes ReflogEntry ptr
5958

6059
-- | Get the old oid
6160
oldOID :: ReflogEntry -> String
62-
oldOID = unsafeCallStr {#call unsafe git_reflog_entry_oidold#}
61+
oldOID (ReflogEntry rfp) = unsafePerformIO $
62+
withForeignPtr rfp $ \r ->
63+
peekCString =<< {#call unsafe git_reflog_entry_oidold#} r
6364

6465
-- | Get the new oid
6566
newOID :: ReflogEntry -> String
66-
newOID = unsafeCallStr {#call unsafe git_reflog_entry_oidnew#}
67+
newOID (ReflogEntry rfp) = unsafePerformIO $
68+
withForeignPtr rfp $ \r ->
69+
peekCString =<< {#call unsafe git_reflog_entry_oidnew#} r
6770

6871
-- | Get the committer of this entry
6972
committer :: ReflogEntry -> Signature
@@ -75,5 +78,7 @@ committer (ReflogEntry rfp) = unsafePerformIO $
7578

7679
-- | Get the log msg
7780
entryMsg :: ReflogEntry -> String
78-
entryMsg = unsafeCallStr {#call unsafe git_reflog_entry_msg#}
81+
entryMsg (ReflogEntry rfp) = unsafePerformIO $
82+
withForeignPtr rfp $ \r ->
83+
peekCString =<< {#call unsafe git_reflog_entry_msg#} r
7984

0 commit comments

Comments
 (0)