GgitPatch: libgit2-glib Reference Manual

## GgitPatch GgitPatch |

## Functions

GgitDiffDelta * | ggit_patch_get_delta ()
GgitDiffHunk * | ggit_patch_get_hunk ()
gboolean | ggit_patch_get_line_stats ()
gsize | ggit_patch_get_num_hunks ()
gint | ggit_patch_get_num_lines_in_hunk ()
GgitPatch * | ggit_patch_new_from_blobs ()
GgitPatch * | ggit_patch_new_from_diff ()
GgitPatch * | ggit_patch_ref ()
gboolean | ggit_patch_to_stream ()
gchar * | ggit_patch_to_string ()
void | ggit_patch_unref ()

## Types and Values

| GgitPatch

## Object Hierarchy

        GBoxed
        ╰── GgitPatch

## Description

## Functions

### ggit_patch_get_delta ()

    GgitDiffDelta *
    ggit_patch_get_delta (GgitPatch *patch);

Get the diff delta corresponding to the patch.

#### Parameters

patch | a GgitPatch. |

#### Returns

the GgitDiffDelta of the patch or `NULL`.

[transfer full][nullable]

### ggit_patch_get_hunk ()

    GgitDiffHunk *
    ggit_patch_get_hunk (GgitPatch *patch,
                         gsize idx,
                         GError **error);

Get the `idx` 'th hunk in the patch.

#### Parameters

patch | a GgitPatch |
idx | the hunk index. |
error | a GError |

#### Returns

a new GgitDiffHunk or `NULL` on error.

[transfer full][nullable]

### ggit_patch_get_line_stats ()

    gboolean
    ggit_patch_get_line_stats (GgitPatch *patch,
                               gsize *total_context,
                               gsize *total_additions,
                               gsize *total_deletions,
                               GError **error);

Get the line statistics of the patch.

#### Parameters

patch | a GgitPatch. |
total_context | return value for the number of context lines. | [allow-none][out]
total_additions | return value for the number of added lines. | [allow-none][out]
total_deletions | return value for the number of deleted lines. | [allow-none][out]
error | a GError. |

#### Returns

`TRUE` if successfull, `FALSE` otherwise.

### ggit_patch_get_num_hunks ()

    gsize
    ggit_patch_get_num_hunks (GgitPatch *patch);

Get the number of hunks in the patch.

#### Parameters

patch | a GgitPatch. |

#### Returns

the number of hunks.

### ggit_patch_get_num_lines_in_hunk ()

    gint
    ggit_patch_get_num_lines_in_hunk (GgitPatch *patch,
                                      gsize hunk);

Get the number of lines in `hunk` .

#### Parameters

patch | a GgitPatch. |
hunk | the hunk index. |

#### Returns

the number of lines.

### ggit_patch_new_from_blobs ()

    GgitPatch *
    ggit_patch_new_from_blobs (GgitBlob *old_blob,
                               const gchar *old_as_path,
                               GgitBlob *new_blob,
                               const gchar *new_as_path,
                               GgitDiffOptions *diff_options,
                               GError **error);

Directly generate a patch from the difference between two blobs.

This is just like `ggit_diff_blobs()` 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.

#### Parameters

old_blob | a GgitBlob to diff from. | [allow-none]
old_as_path | treat `old_blob` as if it had this filename, or `NULL`,. | [allow-none]
new_blob | a GgitBlob to diff to. | [allow-none]
new_as_path | treat `new_blob` as if it had this filename, or `NULL`,. | [allow-none]
diff_options | a GgitDiffOptions, or `NULL`. | [allow-none]
error | a GError for error reporting, or `NULL`. |

#### Returns

a newly created GgitPatch or `NULL`.

[transfer full][nullable]

### ggit_patch_new_from_diff ()

    GgitPatch *
    ggit_patch_new_from_diff (GgitDiff *diff,
                              gsize idx,
                              GError **error);

The GgitPatch is a newly created object contains the text diffs for the delta. You have to call `ggit_patch_unref()` 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.

#### Parameters

diff | a GgitDiff. |
idx | index into diff list. |
error | a GError for error reporting, or `NULL`. |

#### Returns

a newly created GgitPatch or `NULL`.

[transfer full][nullable]

### ggit_patch_ref ()

    GgitPatch *
    ggit_patch_ref (GgitPatch *patch);

Atomically increments the reference count of `patch` by one. This function is MT-safe and may be called from any thread.

#### Parameters

patch | a GgitPatch. |

#### Returns

a GgitPatch or `NULL`.

[transfer none][nullable]

### ggit_patch_to_stream ()

    gboolean
    ggit_patch_to_stream (GgitPatch *patch,
                          GOutputStream *stream,
                          GError **error);

Write the contents of a patch to the provided stream.

#### Parameters

patch | a GgitPatch. |
stream | a GOutputStream. |
error | a GError for error reporting, or `NULL`. |

#### Returns

`TRUE` if the patch was written successfully, `FALSE` otherwise.

### ggit_patch_to_string ()

    gchar *
    ggit_patch_to_string (GgitPatch *patch,
                          GError **error);

Gets the content of a patch as a single diff text.

#### Parameters

patch | a GgitPatch. |
error | a GError for error reporting, or `NULL`. |

#### Returns

the content of a patch as a single diff text or `NULL`.

[transfer full][nullable]

### ggit_patch_unref ()

    void
    ggit_patch_unref (GgitPatch *patch);

Atomically decrements the reference count of `patch` by one. If the reference count drops to 0, `patch` is freed.

#### Parameters

patch | a GgitPatch. |

## Types and Values

### GgitPatch

    typedef struct _GgitPatch GgitPatch;

Represents a patch object.