Ggit.Patch

Fields

None

Methods

class

new_from_blobs (old_blob, old_as_path, new_blob, new_as_path, diff_options)

class

new_from_diff (diff, idx)

get_delta ()

get_hunk (idx)

get_line_stats ()

get_num_hunks ()

get_num_lines_in_hunk (hunk)

ref ()

to_stream (stream)

to_string ()

unref ()

Details

class Ggit.Patch

Represents a patch object.

classmethod new_from_blobs(old_blob, old_as_path, new_blob, new_as_path, diff_options)
Parameters:
Raises:

GLib.Error

Returns:

a newly created Ggit.Patch or None.

Return type:

Ggit.Patch or None

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.

classmethod new_from_diff(diff, idx)
Parameters:
Raises:

GLib.Error

Returns:

a newly created Ggit.Patch or None.

Return type:

Ggit.Patch or None

The Ggit.Patch 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.

get_delta()
Returns:

the Ggit.DiffDelta of the patch or None.

Return type:

Ggit.DiffDelta or None

Get the diff delta corresponding to the patch.

get_hunk(idx)
Parameters:

idx (int) – the hunk index.

Raises:

GLib.Error

Returns:

a new Ggit.DiffHunk or None on error.

Return type:

Ggit.DiffHunk or None

Get the idx'th hunk in the patch.

get_line_stats()
Raises:

GLib.Error

Returns:

True if successfull, False otherwise.

total_context:

return value for the number of context lines.

total_additions:

return value for the number of added lines.

total_deletions:

return value for the number of deleted lines.

Return type:

(bool, total_context: int, total_additions: int, total_deletions: int)

Get the line statistics of the patch.

get_num_hunks()
Returns:

the number of hunks.

Return type:

int

Get the number of hunks in the patch.

get_num_lines_in_hunk(hunk)
Parameters:

hunk (int) – the hunk index.

Returns:

the number of lines.

Return type:

int

Get the number of lines in hunk.

ref()
Returns:

a Ggit.Patch or None.

Return type:

Ggit.Patch or None

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

to_stream(stream)
Parameters:

stream (Gio.OutputStream) – a Gio.OutputStream.

Raises:

GLib.Error

Returns:

True if the patch was written successfully, False otherwise.

Return type:

bool

Write the contents of a patch to the provided stream.

to_string()
Raises:

GLib.Error

Returns:

the content of a patch as a single diff text or None.

Return type:

str or None

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

unref()

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