{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

Represents a commit object.
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.Ggit.Objects.Commit
    (

-- * Exported types
    Commit(..)                              ,
    IsCommit                                ,
    toCommit                                ,
    noCommit                                ,


 -- * Methods
-- ** amend #method:amend#

#if ENABLE_OVERLOADING
    CommitAmendMethodInfo                   ,
#endif
    commitAmend                             ,


-- ** getAuthor #method:getAuthor#

#if ENABLE_OVERLOADING
    CommitGetAuthorMethodInfo               ,
#endif
    commitGetAuthor                         ,


-- ** getCommitter #method:getCommitter#

#if ENABLE_OVERLOADING
    CommitGetCommitterMethodInfo            ,
#endif
    commitGetCommitter                      ,


-- ** getMessage #method:getMessage#

#if ENABLE_OVERLOADING
    CommitGetMessageMethodInfo              ,
#endif
    commitGetMessage                        ,


-- ** getMessageEncoding #method:getMessageEncoding#

#if ENABLE_OVERLOADING
    CommitGetMessageEncodingMethodInfo      ,
#endif
    commitGetMessageEncoding                ,


-- ** getNthAncestor #method:getNthAncestor#

#if ENABLE_OVERLOADING
    CommitGetNthAncestorMethodInfo          ,
#endif
    commitGetNthAncestor                    ,


-- ** getParents #method:getParents#

#if ENABLE_OVERLOADING
    CommitGetParentsMethodInfo              ,
#endif
    commitGetParents                        ,


-- ** getSubject #method:getSubject#

#if ENABLE_OVERLOADING
    CommitGetSubjectMethodInfo              ,
#endif
    commitGetSubject                        ,


-- ** getTree #method:getTree#

#if ENABLE_OVERLOADING
    CommitGetTreeMethodInfo                 ,
#endif
    commitGetTree                           ,


-- ** getTreeId #method:getTreeId#

#if ENABLE_OVERLOADING
    CommitGetTreeIdMethodInfo               ,
#endif
    commitGetTreeId                         ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL

import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Ggit.Objects.CommitParents as Ggit.CommitParents
import {-# SOURCE #-} qualified GI.Ggit.Objects.Native as Ggit.Native
import {-# SOURCE #-} qualified GI.Ggit.Objects.Object as Ggit.Object
import {-# SOURCE #-} qualified GI.Ggit.Objects.ObjectFactoryBase as Ggit.ObjectFactoryBase
import {-# SOURCE #-} qualified GI.Ggit.Objects.Signature as Ggit.Signature
import {-# SOURCE #-} qualified GI.Ggit.Objects.Tree as Ggit.Tree
import {-# SOURCE #-} qualified GI.Ggit.Structs.OId as Ggit.OId

-- | Memory-managed wrapper type.
newtype Commit = Commit (ManagedPtr Commit)
foreign import ccall "ggit_commit_get_type"
    c_ggit_commit_get_type :: IO GType

instance GObject Commit where
    gobjectType = c_ggit_commit_get_type


-- | Type class for types which can be safely cast to `Commit`, for instance with `toCommit`.
class (GObject o, O.IsDescendantOf Commit o) => IsCommit o
instance (GObject o, O.IsDescendantOf Commit o) => IsCommit o

instance O.HasParentTypes Commit
type instance O.ParentTypes Commit = '[Ggit.Object.Object, Ggit.Native.Native, Ggit.ObjectFactoryBase.ObjectFactoryBase, GObject.Object.Object]

-- | Cast to `Commit`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toCommit :: (MonadIO m, IsCommit o) => o -> m Commit
toCommit = liftIO . unsafeCastTo Commit

-- | A convenience alias for `Nothing` :: `Maybe` `Commit`.
noCommit :: Maybe Commit
noCommit = Nothing

#if ENABLE_OVERLOADING
type family ResolveCommitMethod (t :: Symbol) (o :: *) :: * where
    ResolveCommitMethod "amend" o = CommitAmendMethodInfo
    ResolveCommitMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveCommitMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveCommitMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveCommitMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveCommitMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveCommitMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveCommitMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveCommitMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveCommitMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveCommitMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveCommitMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveCommitMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveCommitMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveCommitMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveCommitMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveCommitMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveCommitMethod "getAuthor" o = CommitGetAuthorMethodInfo
    ResolveCommitMethod "getCommitter" o = CommitGetCommitterMethodInfo
    ResolveCommitMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveCommitMethod "getId" o = Ggit.Object.ObjectGetIdMethodInfo
    ResolveCommitMethod "getMessage" o = CommitGetMessageMethodInfo
    ResolveCommitMethod "getMessageEncoding" o = CommitGetMessageEncodingMethodInfo
    ResolveCommitMethod "getNthAncestor" o = CommitGetNthAncestorMethodInfo
    ResolveCommitMethod "getOwner" o = Ggit.Object.ObjectGetOwnerMethodInfo
    ResolveCommitMethod "getParents" o = CommitGetParentsMethodInfo
    ResolveCommitMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveCommitMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveCommitMethod "getSubject" o = CommitGetSubjectMethodInfo
    ResolveCommitMethod "getTree" o = CommitGetTreeMethodInfo
    ResolveCommitMethod "getTreeId" o = CommitGetTreeIdMethodInfo
    ResolveCommitMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveCommitMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveCommitMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveCommitMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveCommitMethod t Commit, O.MethodInfo info Commit p) => OL.IsLabel t (Commit -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

#endif

#if ENABLE_OVERLOADING
instance O.HasAttributeList Commit
type instance O.AttributeList Commit = CommitAttributeList
type CommitAttributeList = ('[ '("native", Ggit.Native.NativeNativePropertyInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
type instance O.SignalList Commit = CommitSignalList
type CommitSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method Commit::amend
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "commit", argType = TInterface (Name {namespace = "Ggit", name = "Commit"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitCommit.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "update_ref", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "name of the reference to update.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "author", argType = TInterface (Name {namespace = "Ggit", name = "Signature"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "author signature.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "committer", argType = TInterface (Name {namespace = "Ggit", name = "Signature"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "committer signature (and time of commit).", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "message_encoding", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "message encoding.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "message", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "commit message.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "tree", argType = TInterface (Name {namespace = "Ggit", name = "Tree"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the tree of objects to commit.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "OId"}))
-- throws : True
-- Skip return : False

foreign import ccall "ggit_commit_amend" ggit_commit_amend ::
    Ptr Commit ->                           -- commit : TInterface (Name {namespace = "Ggit", name = "Commit"})
    CString ->                              -- update_ref : TBasicType TUTF8
    Ptr Ggit.Signature.Signature ->         -- author : TInterface (Name {namespace = "Ggit", name = "Signature"})
    Ptr Ggit.Signature.Signature ->         -- committer : TInterface (Name {namespace = "Ggit", name = "Signature"})
    CString ->                              -- message_encoding : TBasicType TUTF8
    CString ->                              -- message : TBasicType TUTF8
    Ptr Ggit.Tree.Tree ->                   -- tree : TInterface (Name {namespace = "Ggit", name = "Tree"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Ggit.OId.OId)

{- |
Amend an existing commit. If /@updateRef@/ is not 'Nothing', the given reference will
be updated to point to the newly created commit. Use \"HEAD\" to update the
HEAD of the current branch and make it point to this commit.

If /@messageEncoding@/ is set to 'Nothing', \"UTF-8\" encoding is assumed for the
provided /@message@/. Note that /@message@/ will not be cleaned up automatically.
You can use @/ggit_message_prettify/@ to do this yourself if needed.
-}
commitAmend ::
    (B.CallStack.HasCallStack, MonadIO m, IsCommit a, Ggit.Signature.IsSignature b, Ggit.Signature.IsSignature c, Ggit.Tree.IsTree d) =>
    a
    {- ^ /@commit@/: a 'GI.Ggit.Objects.Commit.Commit'. -}
    -> Maybe (T.Text)
    {- ^ /@updateRef@/: name of the reference to update. -}
    -> b
    {- ^ /@author@/: author signature. -}
    -> c
    {- ^ /@committer@/: committer signature (and time of commit). -}
    -> Maybe (T.Text)
    {- ^ /@messageEncoding@/: message encoding. -}
    -> T.Text
    {- ^ /@message@/: commit message. -}
    -> d
    {- ^ /@tree@/: the tree of objects to commit. -}
    -> m (Maybe Ggit.OId.OId)
    {- ^ __Returns:__ the 'GI.Ggit.Structs.OId.OId' of the created commit object,
or 'Nothing' in case of an error. /(Can throw 'Data.GI.Base.GError.GError')/ -}
commitAmend commit updateRef author committer messageEncoding message tree = liftIO $ do
    commit' <- unsafeManagedPtrCastPtr commit
    maybeUpdateRef <- case updateRef of
        Nothing -> return nullPtr
        Just jUpdateRef -> do
            jUpdateRef' <- textToCString jUpdateRef
            return jUpdateRef'
    author' <- unsafeManagedPtrCastPtr author
    committer' <- unsafeManagedPtrCastPtr committer
    maybeMessageEncoding <- case messageEncoding of
        Nothing -> return nullPtr
        Just jMessageEncoding -> do
            jMessageEncoding' <- textToCString jMessageEncoding
            return jMessageEncoding'
    message' <- textToCString message
    tree' <- unsafeManagedPtrCastPtr tree
    onException (do
        result <- propagateGError $ ggit_commit_amend commit' maybeUpdateRef author' committer' maybeMessageEncoding message' tree'
        maybeResult <- convertIfNonNull result $ \result' -> do
            result'' <- (wrapBoxed Ggit.OId.OId) result'
            return result''
        touchManagedPtr commit
        touchManagedPtr author
        touchManagedPtr committer
        touchManagedPtr tree
        freeMem maybeUpdateRef
        freeMem maybeMessageEncoding
        freeMem message'
        return maybeResult
     ) (do
        freeMem maybeUpdateRef
        freeMem maybeMessageEncoding
        freeMem message'
     )

#if ENABLE_OVERLOADING
data CommitAmendMethodInfo
instance (signature ~ (Maybe (T.Text) -> b -> c -> Maybe (T.Text) -> T.Text -> d -> m (Maybe Ggit.OId.OId)), MonadIO m, IsCommit a, Ggit.Signature.IsSignature b, Ggit.Signature.IsSignature c, Ggit.Tree.IsTree d) => O.MethodInfo CommitAmendMethodInfo a signature where
    overloadedMethod _ = commitAmend

#endif

-- method Commit::get_author
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "commit", argType = TInterface (Name {namespace = "Ggit", name = "Commit"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitCommit.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Signature"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_commit_get_author" ggit_commit_get_author ::
    Ptr Commit ->                           -- commit : TInterface (Name {namespace = "Ggit", name = "Commit"})
    IO (Ptr Ggit.Signature.Signature)

{- |
Gets the author of /@commit@/. The returned value must be free\'d with
'GI.GObject.Objects.Object.objectUnref'.
-}
commitGetAuthor ::
    (B.CallStack.HasCallStack, MonadIO m, IsCommit a) =>
    a
    {- ^ /@commit@/: a 'GI.Ggit.Objects.Commit.Commit'. -}
    -> m (Maybe Ggit.Signature.Signature)
    {- ^ __Returns:__ the author of the commit. -}
commitGetAuthor commit = liftIO $ do
    commit' <- unsafeManagedPtrCastPtr commit
    result <- ggit_commit_get_author commit'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapObject Ggit.Signature.Signature) result'
        return result''
    touchManagedPtr commit
    return maybeResult

#if ENABLE_OVERLOADING
data CommitGetAuthorMethodInfo
instance (signature ~ (m (Maybe Ggit.Signature.Signature)), MonadIO m, IsCommit a) => O.MethodInfo CommitGetAuthorMethodInfo a signature where
    overloadedMethod _ = commitGetAuthor

#endif

-- method Commit::get_committer
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "commit", argType = TInterface (Name {namespace = "Ggit", name = "Commit"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitCommit.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Signature"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_commit_get_committer" ggit_commit_get_committer ::
    Ptr Commit ->                           -- commit : TInterface (Name {namespace = "Ggit", name = "Commit"})
    IO (Ptr Ggit.Signature.Signature)

{- |
Gets the committer of /@commit@/. The returned value must be free\'d with
'GI.GObject.Objects.Object.objectUnref'.
-}
commitGetCommitter ::
    (B.CallStack.HasCallStack, MonadIO m, IsCommit a) =>
    a
    {- ^ /@commit@/: a 'GI.Ggit.Objects.Commit.Commit'. -}
    -> m (Maybe Ggit.Signature.Signature)
    {- ^ __Returns:__ the committer of the commit. -}
commitGetCommitter commit = liftIO $ do
    commit' <- unsafeManagedPtrCastPtr commit
    result <- ggit_commit_get_committer commit'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapObject Ggit.Signature.Signature) result'
        return result''
    touchManagedPtr commit
    return maybeResult

#if ENABLE_OVERLOADING
data CommitGetCommitterMethodInfo
instance (signature ~ (m (Maybe Ggit.Signature.Signature)), MonadIO m, IsCommit a) => O.MethodInfo CommitGetCommitterMethodInfo a signature where
    overloadedMethod _ = commitGetCommitter

#endif

-- method Commit::get_message
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "commit", argType = TInterface (Name {namespace = "Ggit", name = "Commit"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitCommit.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "ggit_commit_get_message" ggit_commit_get_message ::
    Ptr Commit ->                           -- commit : TInterface (Name {namespace = "Ggit", name = "Commit"})
    IO CString

{- |
Gets the full message of /@commit@/. The resulting message is always encoded
in UTF-8.
-}
commitGetMessage ::
    (B.CallStack.HasCallStack, MonadIO m, IsCommit a) =>
    a
    {- ^ /@commit@/: a 'GI.Ggit.Objects.Commit.Commit'. -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ the message of the commit. -}
commitGetMessage commit = liftIO $ do
    commit' <- unsafeManagedPtrCastPtr commit
    result <- ggit_commit_get_message commit'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr commit
    return maybeResult

#if ENABLE_OVERLOADING
data CommitGetMessageMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m, IsCommit a) => O.MethodInfo CommitGetMessageMethodInfo a signature where
    overloadedMethod _ = commitGetMessage

#endif

-- method Commit::get_message_encoding
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "commit", argType = TInterface (Name {namespace = "Ggit", name = "Commit"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitCommit.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "ggit_commit_get_message_encoding" ggit_commit_get_message_encoding ::
    Ptr Commit ->                           -- commit : TInterface (Name {namespace = "Ggit", name = "Commit"})
    IO CString

{- |
Get the encoding for the message of a commit,
as a string representing a standard encoding name.

The encoding may be 'Nothing' if the \'encoding\' header
in the commit is missing; in that case UTF-8 is assumed.
-}
commitGetMessageEncoding ::
    (B.CallStack.HasCallStack, MonadIO m, IsCommit a) =>
    a
    {- ^ /@commit@/: a 'GI.Ggit.Objects.Commit.Commit'. -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ the encoding of the commit message or 'Nothing'. -}
commitGetMessageEncoding commit = liftIO $ do
    commit' <- unsafeManagedPtrCastPtr commit
    result <- ggit_commit_get_message_encoding commit'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr commit
    return maybeResult

#if ENABLE_OVERLOADING
data CommitGetMessageEncodingMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m, IsCommit a) => O.MethodInfo CommitGetMessageEncodingMethodInfo a signature where
    overloadedMethod _ = commitGetMessageEncoding

#endif

-- method Commit::get_nth_ancestor
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "commit", argType = TInterface (Name {namespace = "Ggit", name = "Commit"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitCommit.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "n", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the requested ancestor.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Commit"}))
-- throws : True
-- Skip return : False

foreign import ccall "ggit_commit_get_nth_ancestor" ggit_commit_get_nth_ancestor ::
    Ptr Commit ->                           -- commit : TInterface (Name {namespace = "Ggit", name = "Commit"})
    Word32 ->                               -- n : TBasicType TUInt
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Commit)

{- |
Gets the commit object that is the n-th generation ancestor
of the named commit object, following only the first parents.
Passing @/0/@ to the /@n@/ parameter returns another instance of /@commit@/.
-}
commitGetNthAncestor ::
    (B.CallStack.HasCallStack, MonadIO m, IsCommit a) =>
    a
    {- ^ /@commit@/: a 'GI.Ggit.Objects.Commit.Commit'. -}
    -> Word32
    {- ^ /@n@/: the requested ancestor. -}
    -> m (Maybe Commit)
    {- ^ __Returns:__ the /@n@/ ancestor commit. /(Can throw 'Data.GI.Base.GError.GError')/ -}
commitGetNthAncestor commit n = liftIO $ do
    commit' <- unsafeManagedPtrCastPtr commit
    onException (do
        result <- propagateGError $ ggit_commit_get_nth_ancestor commit' n
        maybeResult <- convertIfNonNull result $ \result' -> do
            result'' <- (wrapObject Commit) result'
            return result''
        touchManagedPtr commit
        return maybeResult
     ) (do
        return ()
     )

#if ENABLE_OVERLOADING
data CommitGetNthAncestorMethodInfo
instance (signature ~ (Word32 -> m (Maybe Commit)), MonadIO m, IsCommit a) => O.MethodInfo CommitGetNthAncestorMethodInfo a signature where
    overloadedMethod _ = commitGetNthAncestor

#endif

-- method Commit::get_parents
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "commit", argType = TInterface (Name {namespace = "Ggit", name = "Commit"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitCommit.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "CommitParents"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_commit_get_parents" ggit_commit_get_parents ::
    Ptr Commit ->                           -- commit : TInterface (Name {namespace = "Ggit", name = "Commit"})
    IO (Ptr Ggit.CommitParents.CommitParents)

{- |
Gets the parents collection for /@commit@/.
-}
commitGetParents ::
    (B.CallStack.HasCallStack, MonadIO m, IsCommit a) =>
    a
    {- ^ /@commit@/: a 'GI.Ggit.Objects.Commit.Commit'. -}
    -> m (Maybe Ggit.CommitParents.CommitParents)
    {- ^ __Returns:__ the parents collection of the commit. -}
commitGetParents commit = liftIO $ do
    commit' <- unsafeManagedPtrCastPtr commit
    result <- ggit_commit_get_parents commit'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapObject Ggit.CommitParents.CommitParents) result'
        return result''
    touchManagedPtr commit
    return maybeResult

#if ENABLE_OVERLOADING
data CommitGetParentsMethodInfo
instance (signature ~ (m (Maybe Ggit.CommitParents.CommitParents)), MonadIO m, IsCommit a) => O.MethodInfo CommitGetParentsMethodInfo a signature where
    overloadedMethod _ = commitGetParents

#endif

-- method Commit::get_subject
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "commit", argType = TInterface (Name {namespace = "Ggit", name = "Commit"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitCommit.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "ggit_commit_get_subject" ggit_commit_get_subject ::
    Ptr Commit ->                           -- commit : TInterface (Name {namespace = "Ggit", name = "Commit"})
    IO CString

{- |
Gets the subject of /@commit@/. The subject of a commit is the first line of
the commit message (as per convention). The resulting subject is always
encoded in UTF-8.
-}
commitGetSubject ::
    (B.CallStack.HasCallStack, MonadIO m, IsCommit a) =>
    a
    {- ^ /@commit@/: a 'GI.Ggit.Objects.Commit.Commit'. -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ the subject of the commit. -}
commitGetSubject commit = liftIO $ do
    commit' <- unsafeManagedPtrCastPtr commit
    result <- ggit_commit_get_subject commit'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr commit
    return maybeResult

#if ENABLE_OVERLOADING
data CommitGetSubjectMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m, IsCommit a) => O.MethodInfo CommitGetSubjectMethodInfo a signature where
    overloadedMethod _ = commitGetSubject

#endif

-- method Commit::get_tree
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "commit", argType = TInterface (Name {namespace = "Ggit", name = "Commit"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitCommit.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "Tree"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_commit_get_tree" ggit_commit_get_tree ::
    Ptr Commit ->                           -- commit : TInterface (Name {namespace = "Ggit", name = "Commit"})
    IO (Ptr Ggit.Tree.Tree)

{- |
Get the tree object for /@commit@/.
-}
commitGetTree ::
    (B.CallStack.HasCallStack, MonadIO m, IsCommit a) =>
    a
    {- ^ /@commit@/: a 'GI.Ggit.Objects.Commit.Commit'. -}
    -> m (Maybe Ggit.Tree.Tree)
    {- ^ __Returns:__ a 'GI.Ggit.Objects.Tree.Tree'. -}
commitGetTree commit = liftIO $ do
    commit' <- unsafeManagedPtrCastPtr commit
    result <- ggit_commit_get_tree commit'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapObject Ggit.Tree.Tree) result'
        return result''
    touchManagedPtr commit
    return maybeResult

#if ENABLE_OVERLOADING
data CommitGetTreeMethodInfo
instance (signature ~ (m (Maybe Ggit.Tree.Tree)), MonadIO m, IsCommit a) => O.MethodInfo CommitGetTreeMethodInfo a signature where
    overloadedMethod _ = commitGetTree

#endif

-- method Commit::get_tree_id
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "commit", argType = TInterface (Name {namespace = "Ggit", name = "Commit"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GgitCommit.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Ggit", name = "OId"}))
-- throws : False
-- Skip return : False

foreign import ccall "ggit_commit_get_tree_id" ggit_commit_get_tree_id ::
    Ptr Commit ->                           -- commit : TInterface (Name {namespace = "Ggit", name = "Commit"})
    IO (Ptr Ggit.OId.OId)

{- |
Get the 'GI.Ggit.Structs.OId.OId' of the tree of /@commit@/. Note that this is more efficient
than getting the tree object with 'GI.Ggit.Objects.Commit.commitGetTree' because no additional
files need to be read from disk.
-}
commitGetTreeId ::
    (B.CallStack.HasCallStack, MonadIO m, IsCommit a) =>
    a
    {- ^ /@commit@/: a 'GI.Ggit.Objects.Commit.Commit'. -}
    -> m (Maybe Ggit.OId.OId)
    {- ^ __Returns:__ a 'GI.Ggit.Structs.OId.OId'. -}
commitGetTreeId commit = liftIO $ do
    commit' <- unsafeManagedPtrCastPtr commit
    result <- ggit_commit_get_tree_id commit'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Ggit.OId.OId) result'
        return result''
    touchManagedPtr commit
    return maybeResult

#if ENABLE_OVERLOADING
data CommitGetTreeIdMethodInfo
instance (signature ~ (m (Maybe Ggit.OId.OId)), MonadIO m, IsCommit a) => O.MethodInfo CommitGetTreeIdMethodInfo a signature where
    overloadedMethod _ = commitGetTreeId

#endif