{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- Represents a patch object.

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

module GI.Ggit.Structs.Patch
    ( 

-- * Exported types
    Patch(..)                               ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [ref]("GI.Ggit.Structs.Patch#g:method:ref"), [toStream]("GI.Ggit.Structs.Patch#g:method:toStream"), [toString]("GI.Ggit.Structs.Patch#g:method:toString"), [unref]("GI.Ggit.Structs.Patch#g:method:unref").
-- 
-- ==== Getters
-- [getDelta]("GI.Ggit.Structs.Patch#g:method:getDelta"), [getHunk]("GI.Ggit.Structs.Patch#g:method:getHunk"), [getLineStats]("GI.Ggit.Structs.Patch#g:method:getLineStats"), [getNumHunks]("GI.Ggit.Structs.Patch#g:method:getNumHunks"), [getNumLinesInHunk]("GI.Ggit.Structs.Patch#g:method:getNumLinesInHunk").
-- 
-- ==== Setters
-- /None/.

#if defined(ENABLE_OVERLOADING)
    ResolvePatchMethod                      ,
#endif

-- ** getDelta #method:getDelta#

#if defined(ENABLE_OVERLOADING)
    PatchGetDeltaMethodInfo                 ,
#endif
    patchGetDelta                           ,


-- ** getHunk #method:getHunk#

#if defined(ENABLE_OVERLOADING)
    PatchGetHunkMethodInfo                  ,
#endif
    patchGetHunk                            ,


-- ** getLineStats #method:getLineStats#

#if defined(ENABLE_OVERLOADING)
    PatchGetLineStatsMethodInfo             ,
#endif
    patchGetLineStats                       ,


-- ** getNumHunks #method:getNumHunks#

#if defined(ENABLE_OVERLOADING)
    PatchGetNumHunksMethodInfo              ,
#endif
    patchGetNumHunks                        ,


-- ** getNumLinesInHunk #method:getNumLinesInHunk#

#if defined(ENABLE_OVERLOADING)
    PatchGetNumLinesInHunkMethodInfo        ,
#endif
    patchGetNumLinesInHunk                  ,


-- ** newFromBlobs #method:newFromBlobs#

    patchNewFromBlobs                       ,


-- ** newFromDiff #method:newFromDiff#

    patchNewFromDiff                        ,


-- ** ref #method:ref#

#if defined(ENABLE_OVERLOADING)
    PatchRefMethodInfo                      ,
#endif
    patchRef                                ,


-- ** toStream #method:toStream#

#if defined(ENABLE_OVERLOADING)
    PatchToStreamMethodInfo                 ,
#endif
    patchToStream                           ,


-- ** toString #method:toString#

#if defined(ENABLE_OVERLOADING)
    PatchToStringMethodInfo                 ,
#endif
    patchToString                           ,


-- ** unref #method:unref#

#if defined(ENABLE_OVERLOADING)
    PatchUnrefMethodInfo                    ,
#endif
    patchUnref                              ,




    ) 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.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GArray as B.GArray
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.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Coerce as Coerce
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 GHC.Records as R

import {-# SOURCE #-} qualified GI.Ggit.Objects.Blob as Ggit.Blob
import {-# SOURCE #-} qualified GI.Ggit.Objects.Diff as Ggit.Diff
import {-# SOURCE #-} qualified GI.Ggit.Objects.DiffOptions as Ggit.DiffOptions
import {-# SOURCE #-} qualified GI.Ggit.Structs.DiffDelta as Ggit.DiffDelta
import {-# SOURCE #-} qualified GI.Ggit.Structs.DiffHunk as Ggit.DiffHunk
import qualified GI.Gio.Objects.OutputStream as Gio.OutputStream

-- | Memory-managed wrapper type.
newtype Patch = Patch (SP.ManagedPtr Patch)
    deriving (Patch -> Patch -> Bool
(Patch -> Patch -> Bool) -> (Patch -> Patch -> Bool) -> Eq Patch
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Patch -> Patch -> Bool
$c/= :: Patch -> Patch -> Bool
== :: Patch -> Patch -> Bool
$c== :: Patch -> Patch -> Bool
Eq)

instance SP.ManagedPtrNewtype Patch where
    toManagedPtr :: Patch -> ManagedPtr Patch
toManagedPtr (Patch ManagedPtr Patch
p) = ManagedPtr Patch
p

foreign import ccall "ggit_patch_get_type" c_ggit_patch_get_type :: 
    IO GType

type instance O.ParentTypes Patch = '[]
instance O.HasParentTypes Patch

instance B.Types.TypedObject Patch where
    glibType :: IO GType
glibType = IO GType
c_ggit_patch_get_type

instance B.Types.GBoxed Patch

-- | Convert 'Patch' to and from 'Data.GI.Base.GValue.GValue'. See 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue (Maybe Patch) where
    gvalueGType_ :: IO GType
gvalueGType_ = IO GType
c_ggit_patch_get_type
    gvalueSet_ :: Ptr GValue -> Maybe Patch -> IO ()
gvalueSet_ Ptr GValue
gv Maybe Patch
P.Nothing = Ptr GValue -> Ptr Patch -> IO ()
forall a. Ptr GValue -> Ptr a -> IO ()
B.GValue.set_boxed Ptr GValue
gv (Ptr Patch
forall a. Ptr a
FP.nullPtr :: FP.Ptr Patch)
    gvalueSet_ Ptr GValue
gv (P.Just Patch
obj) = Patch -> (Ptr Patch -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Patch
obj (Ptr GValue -> Ptr Patch -> IO ()
forall a. Ptr GValue -> Ptr a -> IO ()
B.GValue.set_boxed Ptr GValue
gv)
    gvalueGet_ :: Ptr GValue -> IO (Maybe Patch)
gvalueGet_ Ptr GValue
gv = do
        Ptr Patch
ptr <- Ptr GValue -> IO (Ptr Patch)
forall b. Ptr GValue -> IO (Ptr b)
B.GValue.get_boxed Ptr GValue
gv :: IO (Ptr Patch)
        if Ptr Patch
ptr Ptr Patch -> Ptr Patch -> Bool
forall a. Eq a => a -> a -> Bool
/= Ptr Patch
forall a. Ptr a
FP.nullPtr
        then Patch -> Maybe Patch
forall a. a -> Maybe a
P.Just (Patch -> Maybe Patch) -> IO Patch -> IO (Maybe Patch)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ManagedPtr Patch -> Patch) -> Ptr Patch -> IO Patch
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.newBoxed ManagedPtr Patch -> Patch
Patch Ptr Patch
ptr
        else Maybe Patch -> IO (Maybe Patch)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Patch
forall a. Maybe a
P.Nothing
        
    


#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList Patch
type instance O.AttributeList Patch = PatchAttributeList
type PatchAttributeList = ('[ ] :: [(Symbol, *)])
#endif

-- method Patch::new_from_blobs
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "old_blob"
--           , argType = TInterface Name { namespace = "Ggit" , name = "Blob" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitBlob to diff from."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "old_as_path"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "treat @old_blob as if it had this filename, or %NULL,"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "new_blob"
--           , argType = TInterface Name { namespace = "Ggit" , name = "Blob" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitBlob to diff to."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "new_as_path"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "treat @new_blob as if it had this filename, or %NULL,"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "diff_options"
--           , argType =
--               TInterface Name { namespace = "Ggit" , name = "DiffOptions" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitDiffOptions, or %NULL."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Ggit" , name = "Patch" })
-- throws : True
-- Skip return : False

foreign import ccall "ggit_patch_new_from_blobs" ggit_patch_new_from_blobs :: 
    Ptr Ggit.Blob.Blob ->                   -- old_blob : TInterface (Name {namespace = "Ggit", name = "Blob"})
    CString ->                              -- old_as_path : TBasicType TUTF8
    Ptr Ggit.Blob.Blob ->                   -- new_blob : TInterface (Name {namespace = "Ggit", name = "Blob"})
    CString ->                              -- new_as_path : TBasicType TUTF8
    Ptr Ggit.DiffOptions.DiffOptions ->     -- diff_options : TInterface (Name {namespace = "Ggit", name = "DiffOptions"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Patch)

-- | Directly generate a patch from the difference between two blobs.
-- 
-- This is just like 'GI.Ggit.Objects.Diff.diffBlobs' except it generates a patch object
-- for the difference instead of directly making callbacks.  You can use the
-- standard ggit_patch accessor functions to read the patch data, and
-- you must call ggit_patch_unref on the patch when done.
patchNewFromBlobs ::
    (B.CallStack.HasCallStack, MonadIO m, Ggit.Blob.IsBlob a, Ggit.Blob.IsBlob b, Ggit.DiffOptions.IsDiffOptions c) =>
    Maybe (a)
    -- ^ /@oldBlob@/: a t'GI.Ggit.Objects.Blob.Blob' to diff from.
    -> Maybe (T.Text)
    -- ^ /@oldAsPath@/: treat /@oldBlob@/ as if it had this filename, or 'P.Nothing',
    -> Maybe (b)
    -- ^ /@newBlob@/: a t'GI.Ggit.Objects.Blob.Blob' to diff to.
    -> Maybe (T.Text)
    -- ^ /@newAsPath@/: treat /@newBlob@/ as if it had this filename, or 'P.Nothing',
    -> Maybe (c)
    -- ^ /@diffOptions@/: a t'GI.Ggit.Objects.DiffOptions.DiffOptions', or 'P.Nothing'.
    -> m (Maybe Patch)
    -- ^ __Returns:__ a newly created t'GI.Ggit.Structs.Patch.Patch' or 'P.Nothing'. /(Can throw 'Data.GI.Base.GError.GError')/
patchNewFromBlobs :: forall (m :: * -> *) a b c.
(HasCallStack, MonadIO m, IsBlob a, IsBlob b, IsDiffOptions c) =>
Maybe a
-> Maybe Text
-> Maybe b
-> Maybe Text
-> Maybe c
-> m (Maybe Patch)
patchNewFromBlobs Maybe a
oldBlob Maybe Text
oldAsPath Maybe b
newBlob Maybe Text
newAsPath Maybe c
diffOptions = IO (Maybe Patch) -> m (Maybe Patch)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Patch) -> m (Maybe Patch))
-> IO (Maybe Patch) -> m (Maybe Patch)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Blob
maybeOldBlob <- case Maybe a
oldBlob of
        Maybe a
Nothing -> Ptr Blob -> IO (Ptr Blob)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Blob
forall a. Ptr a
nullPtr
        Just a
jOldBlob -> do
            Ptr Blob
jOldBlob' <- a -> IO (Ptr Blob)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
jOldBlob
            Ptr Blob -> IO (Ptr Blob)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Blob
jOldBlob'
    Ptr CChar
maybeOldAsPath <- case Maybe Text
oldAsPath of
        Maybe Text
Nothing -> Ptr CChar -> IO (Ptr CChar)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr CChar
forall a. Ptr a
nullPtr
        Just Text
jOldAsPath -> do
            Ptr CChar
jOldAsPath' <- Text -> IO (Ptr CChar)
textToCString Text
jOldAsPath
            Ptr CChar -> IO (Ptr CChar)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr CChar
jOldAsPath'
    Ptr Blob
maybeNewBlob <- case Maybe b
newBlob of
        Maybe b
Nothing -> Ptr Blob -> IO (Ptr Blob)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Blob
forall a. Ptr a
nullPtr
        Just b
jNewBlob -> do
            Ptr Blob
jNewBlob' <- b -> IO (Ptr Blob)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
jNewBlob
            Ptr Blob -> IO (Ptr Blob)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Blob
jNewBlob'
    Ptr CChar
maybeNewAsPath <- case Maybe Text
newAsPath of
        Maybe Text
Nothing -> Ptr CChar -> IO (Ptr CChar)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr CChar
forall a. Ptr a
nullPtr
        Just Text
jNewAsPath -> do
            Ptr CChar
jNewAsPath' <- Text -> IO (Ptr CChar)
textToCString Text
jNewAsPath
            Ptr CChar -> IO (Ptr CChar)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr CChar
jNewAsPath'
    Ptr DiffOptions
maybeDiffOptions <- case Maybe c
diffOptions of
        Maybe c
Nothing -> Ptr DiffOptions -> IO (Ptr DiffOptions)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr DiffOptions
forall a. Ptr a
nullPtr
        Just c
jDiffOptions -> do
            Ptr DiffOptions
jDiffOptions' <- c -> IO (Ptr DiffOptions)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr c
jDiffOptions
            Ptr DiffOptions -> IO (Ptr DiffOptions)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr DiffOptions
jDiffOptions'
    IO (Maybe Patch) -> IO () -> IO (Maybe Patch)
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr Patch
result <- (Ptr (Ptr GError) -> IO (Ptr Patch)) -> IO (Ptr Patch)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr Patch)) -> IO (Ptr Patch))
-> (Ptr (Ptr GError) -> IO (Ptr Patch)) -> IO (Ptr Patch)
forall a b. (a -> b) -> a -> b
$ Ptr Blob
-> Ptr CChar
-> Ptr Blob
-> Ptr CChar
-> Ptr DiffOptions
-> Ptr (Ptr GError)
-> IO (Ptr Patch)
ggit_patch_new_from_blobs Ptr Blob
maybeOldBlob Ptr CChar
maybeOldAsPath Ptr Blob
maybeNewBlob Ptr CChar
maybeNewAsPath Ptr DiffOptions
maybeDiffOptions
        Maybe Patch
maybeResult <- Ptr Patch -> (Ptr Patch -> IO Patch) -> IO (Maybe Patch)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Patch
result ((Ptr Patch -> IO Patch) -> IO (Maybe Patch))
-> (Ptr Patch -> IO Patch) -> IO (Maybe Patch)
forall a b. (a -> b) -> a -> b
$ \Ptr Patch
result' -> do
            Patch
result'' <- ((ManagedPtr Patch -> Patch) -> Ptr Patch -> IO Patch
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Patch -> Patch
Patch) Ptr Patch
result'
            Patch -> IO Patch
forall (m :: * -> *) a. Monad m => a -> m a
return Patch
result''
        Maybe a -> (a -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe a
oldBlob a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
        Maybe b -> (b -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe b
newBlob b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
        Maybe c -> (c -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe c
diffOptions c -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
        Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
maybeOldAsPath
        Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
maybeNewAsPath
        Maybe Patch -> IO (Maybe Patch)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Patch
maybeResult
     ) (do
        Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
maybeOldAsPath
        Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
maybeNewAsPath
     )

#if defined(ENABLE_OVERLOADING)
#endif

-- method Patch::new_from_diff
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "diff"
--           , argType = TInterface Name { namespace = "Ggit" , name = "Diff" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitDiff." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "idx"
--           , argType = TBasicType TUInt64
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "index into diff list."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Ggit" , name = "Patch" })
-- throws : True
-- Skip return : False

foreign import ccall "ggit_patch_new_from_diff" ggit_patch_new_from_diff :: 
    Ptr Ggit.Diff.Diff ->                   -- diff : TInterface (Name {namespace = "Ggit", name = "Diff"})
    Word64 ->                               -- idx : TBasicType TUInt64
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Patch)

-- | The t'GI.Ggit.Structs.Patch.Patch' is a newly created object contains the text diffs
-- for the delta.  You have to call 'GI.Ggit.Structs.Patch.patchUnref' when you are
-- done with it.  You can use the patch object to loop over all the hunks
-- and lines in the diff of the one delta.
patchNewFromDiff ::
    (B.CallStack.HasCallStack, MonadIO m, Ggit.Diff.IsDiff a) =>
    a
    -- ^ /@diff@/: a t'GI.Ggit.Objects.Diff.Diff'.
    -> Word64
    -- ^ /@idx@/: index into diff list.
    -> m (Maybe Patch)
    -- ^ __Returns:__ a newly created t'GI.Ggit.Structs.Patch.Patch' or 'P.Nothing'. /(Can throw 'Data.GI.Base.GError.GError')/
patchNewFromDiff :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsDiff a) =>
a -> Word64 -> m (Maybe Patch)
patchNewFromDiff a
diff Word64
idx = IO (Maybe Patch) -> m (Maybe Patch)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Patch) -> m (Maybe Patch))
-> IO (Maybe Patch) -> m (Maybe Patch)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Diff
diff' <- a -> IO (Ptr Diff)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
diff
    IO (Maybe Patch) -> IO () -> IO (Maybe Patch)
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr Patch
result <- (Ptr (Ptr GError) -> IO (Ptr Patch)) -> IO (Ptr Patch)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr Patch)) -> IO (Ptr Patch))
-> (Ptr (Ptr GError) -> IO (Ptr Patch)) -> IO (Ptr Patch)
forall a b. (a -> b) -> a -> b
$ Ptr Diff -> Word64 -> Ptr (Ptr GError) -> IO (Ptr Patch)
ggit_patch_new_from_diff Ptr Diff
diff' Word64
idx
        Maybe Patch
maybeResult <- Ptr Patch -> (Ptr Patch -> IO Patch) -> IO (Maybe Patch)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Patch
result ((Ptr Patch -> IO Patch) -> IO (Maybe Patch))
-> (Ptr Patch -> IO Patch) -> IO (Maybe Patch)
forall a b. (a -> b) -> a -> b
$ \Ptr Patch
result' -> do
            Patch
result'' <- ((ManagedPtr Patch -> Patch) -> Ptr Patch -> IO Patch
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Patch -> Patch
Patch) Ptr Patch
result'
            Patch -> IO Patch
forall (m :: * -> *) a. Monad m => a -> m a
return Patch
result''
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
diff
        Maybe Patch -> IO (Maybe Patch)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Patch
maybeResult
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if defined(ENABLE_OVERLOADING)
#endif

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

foreign import ccall "ggit_patch_get_delta" ggit_patch_get_delta :: 
    Ptr Patch ->                            -- patch : TInterface (Name {namespace = "Ggit", name = "Patch"})
    IO (Ptr Ggit.DiffDelta.DiffDelta)

-- | Get the diff delta corresponding to the patch.
patchGetDelta ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Patch
    -- ^ /@patch@/: a t'GI.Ggit.Structs.Patch.Patch'.
    -> m (Maybe Ggit.DiffDelta.DiffDelta)
    -- ^ __Returns:__ the t'GI.Ggit.Structs.DiffDelta.DiffDelta' of the patch or 'P.Nothing'.
patchGetDelta :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Patch -> m (Maybe DiffDelta)
patchGetDelta Patch
patch = IO (Maybe DiffDelta) -> m (Maybe DiffDelta)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe DiffDelta) -> m (Maybe DiffDelta))
-> IO (Maybe DiffDelta) -> m (Maybe DiffDelta)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Patch
patch' <- Patch -> IO (Ptr Patch)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Patch
patch
    Ptr DiffDelta
result <- Ptr Patch -> IO (Ptr DiffDelta)
ggit_patch_get_delta Ptr Patch
patch'
    Maybe DiffDelta
maybeResult <- Ptr DiffDelta
-> (Ptr DiffDelta -> IO DiffDelta) -> IO (Maybe DiffDelta)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr DiffDelta
result ((Ptr DiffDelta -> IO DiffDelta) -> IO (Maybe DiffDelta))
-> (Ptr DiffDelta -> IO DiffDelta) -> IO (Maybe DiffDelta)
forall a b. (a -> b) -> a -> b
$ \Ptr DiffDelta
result' -> do
        DiffDelta
result'' <- ((ManagedPtr DiffDelta -> DiffDelta)
-> Ptr DiffDelta -> IO DiffDelta
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr DiffDelta -> DiffDelta
Ggit.DiffDelta.DiffDelta) Ptr DiffDelta
result'
        DiffDelta -> IO DiffDelta
forall (m :: * -> *) a. Monad m => a -> m a
return DiffDelta
result''
    Patch -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Patch
patch
    Maybe DiffDelta -> IO (Maybe DiffDelta)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe DiffDelta
maybeResult

#if defined(ENABLE_OVERLOADING)
data PatchGetDeltaMethodInfo
instance (signature ~ (m (Maybe Ggit.DiffDelta.DiffDelta)), MonadIO m) => O.OverloadedMethod PatchGetDeltaMethodInfo Patch signature where
    overloadedMethod = patchGetDelta

instance O.OverloadedMethodInfo PatchGetDeltaMethodInfo Patch where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Ggit.Structs.Patch.patchGetDelta",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-ggit-1.0.11/docs/GI-Ggit-Structs-Patch.html#v:patchGetDelta"
        })


#endif

-- method Patch::get_hunk
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "patch"
--           , argType = TInterface Name { namespace = "Ggit" , name = "Patch" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitPatch" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "idx"
--           , argType = TBasicType TUInt64
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the hunk index." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Ggit" , name = "DiffHunk" })
-- throws : True
-- Skip return : False

foreign import ccall "ggit_patch_get_hunk" ggit_patch_get_hunk :: 
    Ptr Patch ->                            -- patch : TInterface (Name {namespace = "Ggit", name = "Patch"})
    Word64 ->                               -- idx : TBasicType TUInt64
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Ggit.DiffHunk.DiffHunk)

-- | Get the /@idx@/\'th hunk in the patch.
patchGetHunk ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Patch
    -- ^ /@patch@/: a t'GI.Ggit.Structs.Patch.Patch'
    -> Word64
    -- ^ /@idx@/: the hunk index.
    -> m (Maybe Ggit.DiffHunk.DiffHunk)
    -- ^ __Returns:__ a new t'GI.Ggit.Structs.DiffHunk.DiffHunk' or 'P.Nothing' on error. /(Can throw 'Data.GI.Base.GError.GError')/
patchGetHunk :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Patch -> Word64 -> m (Maybe DiffHunk)
patchGetHunk Patch
patch Word64
idx = IO (Maybe DiffHunk) -> m (Maybe DiffHunk)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe DiffHunk) -> m (Maybe DiffHunk))
-> IO (Maybe DiffHunk) -> m (Maybe DiffHunk)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Patch
patch' <- Patch -> IO (Ptr Patch)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Patch
patch
    IO (Maybe DiffHunk) -> IO () -> IO (Maybe DiffHunk)
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr DiffHunk
result <- (Ptr (Ptr GError) -> IO (Ptr DiffHunk)) -> IO (Ptr DiffHunk)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr DiffHunk)) -> IO (Ptr DiffHunk))
-> (Ptr (Ptr GError) -> IO (Ptr DiffHunk)) -> IO (Ptr DiffHunk)
forall a b. (a -> b) -> a -> b
$ Ptr Patch -> Word64 -> Ptr (Ptr GError) -> IO (Ptr DiffHunk)
ggit_patch_get_hunk Ptr Patch
patch' Word64
idx
        Maybe DiffHunk
maybeResult <- Ptr DiffHunk
-> (Ptr DiffHunk -> IO DiffHunk) -> IO (Maybe DiffHunk)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr DiffHunk
result ((Ptr DiffHunk -> IO DiffHunk) -> IO (Maybe DiffHunk))
-> (Ptr DiffHunk -> IO DiffHunk) -> IO (Maybe DiffHunk)
forall a b. (a -> b) -> a -> b
$ \Ptr DiffHunk
result' -> do
            DiffHunk
result'' <- ((ManagedPtr DiffHunk -> DiffHunk) -> Ptr DiffHunk -> IO DiffHunk
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr DiffHunk -> DiffHunk
Ggit.DiffHunk.DiffHunk) Ptr DiffHunk
result'
            DiffHunk -> IO DiffHunk
forall (m :: * -> *) a. Monad m => a -> m a
return DiffHunk
result''
        Patch -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Patch
patch
        Maybe DiffHunk -> IO (Maybe DiffHunk)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe DiffHunk
maybeResult
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if defined(ENABLE_OVERLOADING)
data PatchGetHunkMethodInfo
instance (signature ~ (Word64 -> m (Maybe Ggit.DiffHunk.DiffHunk)), MonadIO m) => O.OverloadedMethod PatchGetHunkMethodInfo Patch signature where
    overloadedMethod = patchGetHunk

instance O.OverloadedMethodInfo PatchGetHunkMethodInfo Patch where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Ggit.Structs.Patch.patchGetHunk",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-ggit-1.0.11/docs/GI-Ggit-Structs-Patch.html#v:patchGetHunk"
        })


#endif

-- method Patch::get_line_stats
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "patch"
--           , argType = TInterface Name { namespace = "Ggit" , name = "Patch" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitPatch." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "total_context"
--           , argType = TBasicType TUInt64
--           , direction = DirectionOut
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "return value for the number of context lines."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       , Arg
--           { argCName = "total_additions"
--           , argType = TBasicType TUInt64
--           , direction = DirectionOut
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "return value for the number of added lines."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       , Arg
--           { argCName = "total_deletions"
--           , argType = TBasicType TUInt64
--           , direction = DirectionOut
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "return value for the number of deleted lines."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "ggit_patch_get_line_stats" ggit_patch_get_line_stats :: 
    Ptr Patch ->                            -- patch : TInterface (Name {namespace = "Ggit", name = "Patch"})
    Ptr Word64 ->                           -- total_context : TBasicType TUInt64
    Ptr Word64 ->                           -- total_additions : TBasicType TUInt64
    Ptr Word64 ->                           -- total_deletions : TBasicType TUInt64
    Ptr (Ptr GError) ->                     -- error
    IO CInt

-- | Get the line statistics of the patch.
patchGetLineStats ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Patch
    -- ^ /@patch@/: a t'GI.Ggit.Structs.Patch.Patch'.
    -> m ((Word64, Word64, Word64))
    -- ^ /(Can throw 'Data.GI.Base.GError.GError')/
patchGetLineStats :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Patch -> m (Word64, Word64, Word64)
patchGetLineStats Patch
patch = IO (Word64, Word64, Word64) -> m (Word64, Word64, Word64)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Word64, Word64, Word64) -> m (Word64, Word64, Word64))
-> IO (Word64, Word64, Word64) -> m (Word64, Word64, Word64)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Patch
patch' <- Patch -> IO (Ptr Patch)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Patch
patch
    Ptr Word64
totalContext <- IO (Ptr Word64)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Word64)
    Ptr Word64
totalAdditions <- IO (Ptr Word64)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Word64)
    Ptr Word64
totalDeletions <- IO (Ptr Word64)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Word64)
    IO (Word64, Word64, Word64) -> IO () -> IO (Word64, Word64, Word64)
forall a b. IO a -> IO b -> IO a
onException (do
        CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr Patch
-> Ptr Word64
-> Ptr Word64
-> Ptr Word64
-> Ptr (Ptr GError)
-> IO CInt
ggit_patch_get_line_stats Ptr Patch
patch' Ptr Word64
totalContext Ptr Word64
totalAdditions Ptr Word64
totalDeletions
        Word64
totalContext' <- Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek Ptr Word64
totalContext
        Word64
totalAdditions' <- Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek Ptr Word64
totalAdditions
        Word64
totalDeletions' <- Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek Ptr Word64
totalDeletions
        Patch -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Patch
patch
        Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
totalContext
        Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
totalAdditions
        Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
totalDeletions
        (Word64, Word64, Word64) -> IO (Word64, Word64, Word64)
forall (m :: * -> *) a. Monad m => a -> m a
return (Word64
totalContext', Word64
totalAdditions', Word64
totalDeletions')
     ) (do
        Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
totalContext
        Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
totalAdditions
        Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
totalDeletions
     )

#if defined(ENABLE_OVERLOADING)
data PatchGetLineStatsMethodInfo
instance (signature ~ (m ((Word64, Word64, Word64))), MonadIO m) => O.OverloadedMethod PatchGetLineStatsMethodInfo Patch signature where
    overloadedMethod = patchGetLineStats

instance O.OverloadedMethodInfo PatchGetLineStatsMethodInfo Patch where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Ggit.Structs.Patch.patchGetLineStats",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-ggit-1.0.11/docs/GI-Ggit-Structs-Patch.html#v:patchGetLineStats"
        })


#endif

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

foreign import ccall "ggit_patch_get_num_hunks" ggit_patch_get_num_hunks :: 
    Ptr Patch ->                            -- patch : TInterface (Name {namespace = "Ggit", name = "Patch"})
    IO Word64

-- | Get the number of hunks in the patch.
patchGetNumHunks ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Patch
    -- ^ /@patch@/: a t'GI.Ggit.Structs.Patch.Patch'.
    -> m Word64
    -- ^ __Returns:__ the number of hunks.
patchGetNumHunks :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Patch -> m Word64
patchGetNumHunks Patch
patch = IO Word64 -> m Word64
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Word64 -> m Word64) -> IO Word64 -> m Word64
forall a b. (a -> b) -> a -> b
$ do
    Ptr Patch
patch' <- Patch -> IO (Ptr Patch)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Patch
patch
    Word64
result <- Ptr Patch -> IO Word64
ggit_patch_get_num_hunks Ptr Patch
patch'
    Patch -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Patch
patch
    Word64 -> IO Word64
forall (m :: * -> *) a. Monad m => a -> m a
return Word64
result

#if defined(ENABLE_OVERLOADING)
data PatchGetNumHunksMethodInfo
instance (signature ~ (m Word64), MonadIO m) => O.OverloadedMethod PatchGetNumHunksMethodInfo Patch signature where
    overloadedMethod = patchGetNumHunks

instance O.OverloadedMethodInfo PatchGetNumHunksMethodInfo Patch where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Ggit.Structs.Patch.patchGetNumHunks",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-ggit-1.0.11/docs/GI-Ggit-Structs-Patch.html#v:patchGetNumHunks"
        })


#endif

-- method Patch::get_num_lines_in_hunk
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "patch"
--           , argType = TInterface Name { namespace = "Ggit" , name = "Patch" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitPatch." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "hunk"
--           , argType = TBasicType TUInt64
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the hunk index." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TInt)
-- throws : False
-- Skip return : False

foreign import ccall "ggit_patch_get_num_lines_in_hunk" ggit_patch_get_num_lines_in_hunk :: 
    Ptr Patch ->                            -- patch : TInterface (Name {namespace = "Ggit", name = "Patch"})
    Word64 ->                               -- hunk : TBasicType TUInt64
    IO Int32

-- | Get the number of lines in /@hunk@/.
patchGetNumLinesInHunk ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Patch
    -- ^ /@patch@/: a t'GI.Ggit.Structs.Patch.Patch'.
    -> Word64
    -- ^ /@hunk@/: the hunk index.
    -> m Int32
    -- ^ __Returns:__ the number of lines.
patchGetNumLinesInHunk :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Patch -> Word64 -> m Int32
patchGetNumLinesInHunk Patch
patch Word64
hunk = IO Int32 -> m Int32
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Int32 -> m Int32) -> IO Int32 -> m Int32
forall a b. (a -> b) -> a -> b
$ do
    Ptr Patch
patch' <- Patch -> IO (Ptr Patch)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Patch
patch
    Int32
result <- Ptr Patch -> Word64 -> IO Int32
ggit_patch_get_num_lines_in_hunk Ptr Patch
patch' Word64
hunk
    Patch -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Patch
patch
    Int32 -> IO Int32
forall (m :: * -> *) a. Monad m => a -> m a
return Int32
result

#if defined(ENABLE_OVERLOADING)
data PatchGetNumLinesInHunkMethodInfo
instance (signature ~ (Word64 -> m Int32), MonadIO m) => O.OverloadedMethod PatchGetNumLinesInHunkMethodInfo Patch signature where
    overloadedMethod = patchGetNumLinesInHunk

instance O.OverloadedMethodInfo PatchGetNumLinesInHunkMethodInfo Patch where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Ggit.Structs.Patch.patchGetNumLinesInHunk",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-ggit-1.0.11/docs/GI-Ggit-Structs-Patch.html#v:patchGetNumLinesInHunk"
        })


#endif

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

foreign import ccall "ggit_patch_ref" ggit_patch_ref :: 
    Ptr Patch ->                            -- patch : TInterface (Name {namespace = "Ggit", name = "Patch"})
    IO (Ptr Patch)

-- | Atomically increments the reference count of /@patch@/ by one.
-- This function is MT-safe and may be called from any thread.
patchRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Patch
    -- ^ /@patch@/: a t'GI.Ggit.Structs.Patch.Patch'.
    -> m (Maybe Patch)
    -- ^ __Returns:__ a t'GI.Ggit.Structs.Patch.Patch' or 'P.Nothing'.
patchRef :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Patch -> m (Maybe Patch)
patchRef Patch
patch = IO (Maybe Patch) -> m (Maybe Patch)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Patch) -> m (Maybe Patch))
-> IO (Maybe Patch) -> m (Maybe Patch)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Patch
patch' <- Patch -> IO (Ptr Patch)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Patch
patch
    Ptr Patch
result <- Ptr Patch -> IO (Ptr Patch)
ggit_patch_ref Ptr Patch
patch'
    Maybe Patch
maybeResult <- Ptr Patch -> (Ptr Patch -> IO Patch) -> IO (Maybe Patch)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Patch
result ((Ptr Patch -> IO Patch) -> IO (Maybe Patch))
-> (Ptr Patch -> IO Patch) -> IO (Maybe Patch)
forall a b. (a -> b) -> a -> b
$ \Ptr Patch
result' -> do
        Patch
result'' <- ((ManagedPtr Patch -> Patch) -> Ptr Patch -> IO Patch
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newBoxed ManagedPtr Patch -> Patch
Patch) Ptr Patch
result'
        Patch -> IO Patch
forall (m :: * -> *) a. Monad m => a -> m a
return Patch
result''
    Patch -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Patch
patch
    Maybe Patch -> IO (Maybe Patch)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Patch
maybeResult

#if defined(ENABLE_OVERLOADING)
data PatchRefMethodInfo
instance (signature ~ (m (Maybe Patch)), MonadIO m) => O.OverloadedMethod PatchRefMethodInfo Patch signature where
    overloadedMethod = patchRef

instance O.OverloadedMethodInfo PatchRefMethodInfo Patch where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Ggit.Structs.Patch.patchRef",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-ggit-1.0.11/docs/GI-Ggit-Structs-Patch.html#v:patchRef"
        })


#endif

-- method Patch::to_stream
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "patch"
--           , argType = TInterface Name { namespace = "Ggit" , name = "Patch" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GgitPatch." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "stream"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "OutputStream" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GOutputStream." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "ggit_patch_to_stream" ggit_patch_to_stream :: 
    Ptr Patch ->                            -- patch : TInterface (Name {namespace = "Ggit", name = "Patch"})
    Ptr Gio.OutputStream.OutputStream ->    -- stream : TInterface (Name {namespace = "Gio", name = "OutputStream"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

-- | Write the contents of a patch to the provided stream.
patchToStream ::
    (B.CallStack.HasCallStack, MonadIO m, Gio.OutputStream.IsOutputStream a) =>
    Patch
    -- ^ /@patch@/: a t'GI.Ggit.Structs.Patch.Patch'.
    -> a
    -- ^ /@stream@/: a t'GI.Gio.Objects.OutputStream.OutputStream'.
    -> m ()
    -- ^ /(Can throw 'Data.GI.Base.GError.GError')/
patchToStream :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsOutputStream a) =>
Patch -> a -> m ()
patchToStream Patch
patch a
stream = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Patch
patch' <- Patch -> IO (Ptr Patch)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Patch
patch
    Ptr OutputStream
stream' <- a -> IO (Ptr OutputStream)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
stream
    IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
onException (do
        CInt
_ <- (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CInt) -> IO CInt)
-> (Ptr (Ptr GError) -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ Ptr Patch -> Ptr OutputStream -> Ptr (Ptr GError) -> IO CInt
ggit_patch_to_stream Ptr Patch
patch' Ptr OutputStream
stream'
        Patch -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Patch
patch
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
stream
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if defined(ENABLE_OVERLOADING)
data PatchToStreamMethodInfo
instance (signature ~ (a -> m ()), MonadIO m, Gio.OutputStream.IsOutputStream a) => O.OverloadedMethod PatchToStreamMethodInfo Patch signature where
    overloadedMethod = patchToStream

instance O.OverloadedMethodInfo PatchToStreamMethodInfo Patch where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Ggit.Structs.Patch.patchToStream",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-ggit-1.0.11/docs/GI-Ggit-Structs-Patch.html#v:patchToStream"
        })


#endif

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

foreign import ccall "ggit_patch_to_string" ggit_patch_to_string :: 
    Ptr Patch ->                            -- patch : TInterface (Name {namespace = "Ggit", name = "Patch"})
    Ptr (Ptr GError) ->                     -- error
    IO CString

-- | Gets the content of a patch as a single diff text.
patchToString ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Patch
    -- ^ /@patch@/: a t'GI.Ggit.Structs.Patch.Patch'.
    -> m (Maybe T.Text)
    -- ^ __Returns:__ the content of a patch as a single diff text or 'P.Nothing'. /(Can throw 'Data.GI.Base.GError.GError')/
patchToString :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Patch -> m (Maybe Text)
patchToString Patch
patch = IO (Maybe Text) -> m (Maybe Text)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Text) -> m (Maybe Text))
-> IO (Maybe Text) -> m (Maybe Text)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Patch
patch' <- Patch -> IO (Ptr Patch)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Patch
patch
    IO (Maybe Text) -> IO () -> IO (Maybe Text)
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr CChar
result <- (Ptr (Ptr GError) -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr CChar)) -> IO (Ptr CChar))
-> (Ptr (Ptr GError) -> IO (Ptr CChar)) -> IO (Ptr CChar)
forall a b. (a -> b) -> a -> b
$ Ptr Patch -> Ptr (Ptr GError) -> IO (Ptr CChar)
ggit_patch_to_string Ptr Patch
patch'
        Maybe Text
maybeResult <- Ptr CChar -> (Ptr CChar -> IO Text) -> IO (Maybe Text)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr CChar
result ((Ptr CChar -> IO Text) -> IO (Maybe Text))
-> (Ptr CChar -> IO Text) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \Ptr CChar
result' -> do
            Text
result'' <- HasCallStack => Ptr CChar -> IO Text
Ptr CChar -> IO Text
cstringToText Ptr CChar
result'
            Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
result'
            Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result''
        Patch -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Patch
patch
        Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
maybeResult
     ) (do
        () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
     )

#if defined(ENABLE_OVERLOADING)
data PatchToStringMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.OverloadedMethod PatchToStringMethodInfo Patch signature where
    overloadedMethod = patchToString

instance O.OverloadedMethodInfo PatchToStringMethodInfo Patch where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Ggit.Structs.Patch.patchToString",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-ggit-1.0.11/docs/GI-Ggit-Structs-Patch.html#v:patchToString"
        })


#endif

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

foreign import ccall "ggit_patch_unref" ggit_patch_unref :: 
    Ptr Patch ->                            -- patch : TInterface (Name {namespace = "Ggit", name = "Patch"})
    IO ()

-- | Atomically decrements the reference count of /@patch@/ by one.
-- If the reference count drops to 0, /@patch@/ is freed.
patchUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Patch
    -- ^ /@patch@/: a t'GI.Ggit.Structs.Patch.Patch'.
    -> m ()
patchUnref :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Patch -> m ()
patchUnref Patch
patch = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr Patch
patch' <- Patch -> IO (Ptr Patch)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Patch
patch
    Ptr Patch -> IO ()
ggit_patch_unref Ptr Patch
patch'
    Patch -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Patch
patch
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data PatchUnrefMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.OverloadedMethod PatchUnrefMethodInfo Patch signature where
    overloadedMethod = patchUnref

instance O.OverloadedMethodInfo PatchUnrefMethodInfo Patch where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Ggit.Structs.Patch.patchUnref",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-ggit-1.0.11/docs/GI-Ggit-Structs-Patch.html#v:patchUnref"
        })


#endif

#if defined(ENABLE_OVERLOADING)
type family ResolvePatchMethod (t :: Symbol) (o :: *) :: * where
    ResolvePatchMethod "ref" o = PatchRefMethodInfo
    ResolvePatchMethod "toStream" o = PatchToStreamMethodInfo
    ResolvePatchMethod "toString" o = PatchToStringMethodInfo
    ResolvePatchMethod "unref" o = PatchUnrefMethodInfo
    ResolvePatchMethod "getDelta" o = PatchGetDeltaMethodInfo
    ResolvePatchMethod "getHunk" o = PatchGetHunkMethodInfo
    ResolvePatchMethod "getLineStats" o = PatchGetLineStatsMethodInfo
    ResolvePatchMethod "getNumHunks" o = PatchGetNumHunksMethodInfo
    ResolvePatchMethod "getNumLinesInHunk" o = PatchGetNumLinesInHunkMethodInfo
    ResolvePatchMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolvePatchMethod t Patch, O.OverloadedMethod info Patch p) => OL.IsLabel t (Patch -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolvePatchMethod t Patch, O.OverloadedMethod info Patch p, R.HasField t Patch p) => R.HasField t Patch p where
    getField = O.overloadedMethod @info

#endif

instance (info ~ ResolvePatchMethod t Patch, O.OverloadedMethodInfo info Patch) => OL.IsLabel t (O.MethodProxy info Patch) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.MethodProxy
#else
    fromLabel _ = O.MethodProxy
#endif

#endif