libgit2

git_diff_get_patch

Version:

Return the diff delta and patch for an entry in the diff list.

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

For an unchanged file or a binary file, no git_diff_patch will be created, the output will be set to NULL, and the binary flag will be set true in the git_diff_delta structure.

The git_diff_delta pointer points to internal data and you do not have to release it when you are done with it. It will go away when the git_diff_list and git_diff_patch go away.

It is okay to pass NULL for either of the output parameters; if you pass NULL for the git_diff_patch, then the text diff will not be calculated.

Signature

int git_diff_get_patch(git_diff_patch **patch_out, const git_diff_delta **delta_out, git_diff_list *diff, size_t idx);

Parameters

In
patch_out

Output parameter for the delta patch object

In
delta_out

Output parameter for the delta object

In
diff

Diff list object

size_t
In
idx

Index into diff list

Returns

int

0 on success, other value < 0 on error

Versions