--- layout: default menu_item: api title: Patch description: Version 0.26.1 menu_item: api return_to: "API Documentation Index": /api/ sections: "convenientFromDiff": "#convenientFromDiff" "fromBlobs": "#fromBlobs" "fromDiff": "#fromDiff" "#getDelta": "#getDelta" "#getHunk": "#getHunk" "#getLineInHunk": "#getLineInHunk" "#lineStats": "#lineStats" "#numHunks": "#numHunks" "#numLinesInHunk": "#numLinesInHunk" "#size": "#size" --- ## Patch.convenientFromDiff ```js Patch.convenientFromDiff(diff).then(function(stdVectorPatchdata) { // Use stdVectorPatchdata }); ``` | Parameters | Type | | | --- | --- | --- | | diff | [Diff](/api/diff/) | | | Returns | | | --- | --- | | StdVectorPatchdata | | ## Patch.fromBlobs ```js Patch.fromBlobs(old_blob, old_as_path, new_blob, new_as_path, opts).then(function(patch) { // Use patch }); ``` | Parameters | Type | | | --- | --- | --- | | old_blob | [Blob](/api/blob/) | Blob for old side of diff, or NULL for empty blob | | old_as_path | String | Treat old blob as if it had this filename; can be NULL | | new_blob | [Blob](/api/blob/) | Blob for new side of diff, or NULL for empty blob | | new_as_path | String | Treat new blob as if it had this filename; can be NULL | | opts | [DiffOptions](/api/diff_options/) | Options for diff, or NULL for default options | | Returns | | | --- | --- | | [Patch](/api/patch/) | The generated patch; NULL on error | ## Patch.fromDiff ```js Patch.fromDiff(diff, idx).then(function(patch) { // Use patch }); ``` | Parameters | Type | | | --- | --- | --- | | diff | [Diff](/api/diff/) | Diff list object | | idx | Number | Index into diff list | | Returns | | | --- | --- | | [Patch](/api/patch/) | Output parameter for the delta patch object | ## Patch#getDelta ```js var diffDelta = patch.getDelta(); ``` | Returns | | | --- | --- | | [DiffDelta](/api/diff_delta/) | | ## Patch#getHunk ```js patch.getHunk(hunk_idx).then(function(result) { // Use result }); ``` | Parameters | Type | | --- | --- | --- | | hunk_idx | Number | Input index of hunk to get information about | | Returns | | | --- | --- | | Number | Output count of total lines in this hunk | ## Patch#getLineInHunk ```js patch.getLineInHunk(hunk_idx, line_of_hunk).then(function(diffLine) { // Use diffLine }); ``` | Parameters | Type | | --- | --- | --- | | hunk_idx | Number | The index of the hunk | | line_of_hunk | Number | The index of the line in the hunk | | Returns | | | --- | --- | | [DiffLine](/api/diff_line/) | The git_diff_line data for this line | ## Patch#lineStats ```js var result = patch.lineStats(); ``` | Returns | | | --- | --- | | Number | Count of deletion lines in output, can be NULL. | ## Patch#numHunks ```js var result = patch.numHunks(); ``` | Returns | | | --- | --- | | Number | | ## Patch#numLinesInHunk ```js var result = patch.numLinesInHunk(hunk_idx); ``` | Parameters | Type | | --- | --- | --- | | hunk_idx | Number | Index of the hunk | | Returns | | | --- | --- | | Number | Number of lines in hunk or GIT_ENOTFOUND if invalid hunk index | ## Patch#size ```js var result = patch.size(include_context, include_hunk_headers, include_file_headers); ``` | Parameters | Type | | --- | --- | --- | | include_context | Number | Include context lines in size if non-zero | | include_hunk_headers | Number | Include hunk header lines if non-zero | | include_file_headers | Number | Include file header lines if non-zero | | Returns | | | --- | --- | | Number | The number of bytes of data |