Skip to content

Commit 580a897

Browse files
committed
Tag
1 parent 58c77b8 commit 580a897

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

src/haskell/Data/HGit2/Tag.chs

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ instance CWrapper Target where
2626

2727
-- | Get the id of a tag.
2828
tagID :: Tag -> IO OID
29-
tagID = undefined -- callRetCons {#call git_tag_id#} OID
29+
tagID (Tag tfp) =
30+
withForeignPtr tfp $ \t -> do
31+
ptr <- mkFPtr =<< {#call git_tag_id#} t
32+
return $ OID ptr
3033

3134
-- | Get the tagged object of a tag
3235
--
@@ -38,7 +41,10 @@ target (Tag tfp) =
3841

3942
-- | Get the OID of the tagged object of a tag
4043
targetOID :: Tag -> IO OID
41-
targetOID = undefined -- callRetCons {#call git_tag_target_oid#} OID
44+
targetOID (Tag tfp) =
45+
withForeignPtr tfp $ \t -> do
46+
ptr <- mkFPtr =<< {#call git_tag_target_oid#} t
47+
return $ OID ptr
4248

4349
-- | Get the type of a tag's tagged object
4450
tagType :: Tag -> OType
@@ -47,15 +53,22 @@ tagType (Tag tfp) = unsafePerformIO $
4753

4854
-- | Get the name of a tag
4955
tagName :: Tag -> String
50-
tagName = undefined -- unsafePeekStr {#call git_tag_name#}
56+
tagName (Tag tfp) = unsafePerformIO $
57+
withForeignPtr tfp $ \t ->
58+
peekCString =<< {#call git_tag_name#} t
5159

5260
-- | Get the tagger (author) of a tag
5361
tagger :: Tag -> Signature
54-
tagger = undefined -- unsafePerformIO . callRetCons {#call git_tag_tagger#} Signature
62+
tagger (Tag tfp) = unsafePerformIO $
63+
withForeignPtr tfp $ \t -> do
64+
ptr <- mkFPtr =<< {#call git_tag_tagger#} t
65+
return $ Signature ptr
5566

5667
-- | Get the message of a tag
5768
tagMessage :: Tag -> String
58-
tagMessage = undefined -- unsafePeekStr {#call git_tag_message#}
69+
tagMessage (Tag tfp) = unsafePerformIO $
70+
withForeignPtr tfp $ \t ->
71+
peekCString =<< {#call git_tag_message#} t
5972

6073
-- | Create a new tag in the repository from an object
6174
--
@@ -71,40 +84,46 @@ createTag (OID ofp) (Repository rfp) tg (GitObj gfp) (Signature sfp) ms fr =
7184
withForeignPtr sfp $ \s ->
7285
withCString tg $ \tag ->
7386
withCString ms $ \msg ->
74-
undefined -- retMaybe =<< {#call git_tag_create#} o r tag g s msg (fromBool fr)
87+
retMaybe =<< {#call git_tag_create#} o r tag g s msg (fromBool fr)
7588

7689
-- | Create a new tag in the repository from a buffer
7790
createFromBuff :: OID -> Repository -> String -> Bool -> IOCanFail
7891
createFromBuff (OID ofp) (Repository rfp) bf fr =
7992
withForeignPtr ofp $ \o ->
8093
withForeignPtr rfp $ \r ->
8194
withCString bf $ \buf ->
82-
undefined -- retMaybe =<< {#call git_tag_create_frombuffer#} o r buf (fromBool fr)
95+
retMaybe =<< {#call git_tag_create_frombuffer#} o r buf (fromBool fr)
8396

8497
-- | Create a new lightweight tag pointing at a target object
8598
--
8699
-- A new direct reference will be created pointing to this target object. If
87100
-- `force` is true and a reference already exists with the given name, it'll be
88101
-- replaced.
89102
createLightWeight :: OID -> Repository -> String -> GitObj -> Bool -> IOCanFail
90-
createLightWeight (OID o) (Repository r) tn (GitObj g) fr =
103+
createLightWeight (OID ofp) (Repository rfp) tn (GitObj gfp) fr =
104+
withForeignPtr ofp $ \o ->
105+
withForeignPtr rfp $ \r ->
106+
withForeignPtr gfp $ \g ->
91107
withCString tn $ \tag ->
92-
undefined -- retMaybe =<< {#call git_tag_create_lightweight#} o r tag g (fromBool fr)
108+
retMaybe =<< {#call git_tag_create_lightweight#} o r tag g (fromBool fr)
93109

94110
-- | Delete an existing tag reference.
95111
deleteTag :: Repository -> String -> IOCanFail
96-
deleteTag (Repository r) tn =
112+
deleteTag (Repository rfp) tn =
113+
withForeignPtr rfp $ \r ->
97114
withCString tn $ \tag ->
98-
undefined --retMaybe =<< {#call git_tag_delete#} r tag
115+
retMaybe =<< {#call git_tag_delete#} r tag
99116

100117
-- | Fill a list with all the tags in the Repository
101118
--
102119
-- The string array will be filled with the names of the matching tags; these
103120
-- values are owned by the user and should be free'd manually when no longer
104121
-- needed, using `git_strarray_free`.
105122
tagList :: StrArray -> Repository -> IOCanFail
106-
tagList (StrArray sa) (Repository r) =
107-
undefined -- retMaybe =<< {#call git_tag_list#} sa r
123+
tagList (StrArray sfp) (Repository rfp) =
124+
withForeignPtr sfp $ \sa ->
125+
withForeignPtr rfp $ \r ->
126+
retMaybe =<< {#call git_tag_list#} sa r
108127

109128
-- | Fill a list with all the tags in the Repository which name match a defined
110129
-- pattern
@@ -115,6 +134,8 @@ tagList (StrArray sa) (Repository r) =
115134
-- values are owned by the user and should be free'd manually when no longer
116135
-- needed, using `git_strarray_free`.
117136
tagListMatch :: StrArray -> String -> Repository -> IOCanFail
118-
tagListMatch (StrArray s) pt (Repository r) =
137+
tagListMatch (StrArray sfp) pt (Repository rfp) =
138+
withForeignPtr sfp $ \s ->
139+
withForeignPtr rfp $ \r ->
119140
withCString pt $ \pat ->
120-
undefined -- retMaybe =<< {#call git_tag_list_match#} s pat r
141+
retMaybe =<< {#call git_tag_list_match#} s pat r

0 commit comments

Comments
 (0)