diff options
| author | Russell Belfer <rb@github.com> | 2013-06-12 11:55:27 -0700 | 
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-06-12 11:55:27 -0700 | 
| commit | f9c824c592d7a23f7cc385c25c95a5d0c5c8687e (patch) | |
| tree | a9041574778f0bb2341d97c56357d280ed71f06c /include/git2/diff.h | |
| parent | 54faddd299ccb6187a9747c1d3ee18d33e5edf7a (diff) | |
| download | libgit2-f9c824c592d7a23f7cc385c25c95a5d0c5c8687e.tar.gz | |
Add patch from blobs API
This adds two new public APIs: git_diff_patch_from_blobs and
git_diff_patch_from_blob_and_buffer, plus it refactors the code
for git_diff_blobs and git_diff_blob_to_buffer so that they code
is almost entirely shared between these APIs, and adds tests for
the new APIs.
Diffstat (limited to 'include/git2/diff.h')
| -rw-r--r-- | include/git2/diff.h | 47 | 
1 files changed, 45 insertions, 2 deletions
| diff --git a/include/git2/diff.h b/include/git2/diff.h index 40e65b1e4..8113a56be 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -860,7 +860,7 @@ GIT_EXTERN(size_t) git_diff_patch_num_hunks(   * @param total_additions Count of addition lines in output, can be NULL.   * @param total_deletions Count of deletion lines in output, can be NULL.   * @param patch The git_diff_patch object - * @return Number of lines in hunk or -1 if invalid hunk index + * @return 0 on success, <0 on error   */  GIT_EXTERN(int) git_diff_patch_line_stats(  	size_t *total_context, @@ -1001,6 +1001,26 @@ GIT_EXTERN(int) git_diff_blobs(  	void *payload);  /** + * Directly generate a patch from the difference between two blobs. + * + * This is just like `git_diff_blobs()` except it generates a patch object + * for the difference instead of directly making callbacks.  You can use the + * standard `git_diff_patch` accessor functions to read the patch data, and + * you must call `git_diff_patch_free()` on the patch when done. + * + * @param out The generated patch; NULL on error + * @param old_blob Blob for old side of diff, or NULL for empty blob + * @param new_blob Blob for new side of diff, or NULL for empty blob + * @param options Options for diff, or NULL for default options + * @return 0 on success or error code < 0 + */ +GIT_EXTERN(int) git_diff_patch_from_blobs( +	git_diff_patch **out, +	const git_blob *old_blob, +	const git_blob *new_blob, +	const git_diff_options *opts); + +/**   * Directly run a diff between a blob and a buffer.   *   * As with `git_diff_blobs`, comparing a blob and buffer lacks some context, @@ -1013,7 +1033,7 @@ GIT_EXTERN(int) git_diff_blobs(   * the reverse, with GIT_DELTA_REMOVED and blob content removed.   *   * @param old_blob Blob for old side of diff, or NULL for empty blob - * @param buffer Raw data for new side of diff + * @param buffer Raw data for new side of diff, or NULL for empty   * @param buffer_len Length of raw data for new side of diff   * @param options Options for diff, or NULL for default options   * @param file_cb Callback for "file"; made once if there is a diff; can be NULL @@ -1032,6 +1052,29 @@ GIT_EXTERN(int) git_diff_blob_to_buffer(  	git_diff_data_cb data_cb,  	void *payload); +/** + * Directly generate a patch from the difference between a blob and a buffer. + * + * This is just like `git_diff_blob_to_buffer()` except it generates a patch + * object for the difference instead of directly making callbacks.  You can + * use the standard `git_diff_patch` accessor functions to read the patch + * data, and you must call `git_diff_patch_free()` on the patch when done. + * + * @param out The generated patch; NULL on error + * @param old_blob Blob for old side of diff, or NULL for empty blob + * @param buffer Raw data for new side of diff, or NULL for empty + * @param buffer_len Length of raw data for new side of diff + * @param options Options for diff, or NULL for default options + * @return 0 on success or error code < 0 + */ +GIT_EXTERN(int) git_diff_patch_from_blob_and_buffer( +	git_diff_patch **out, +	const git_blob *old_blob, +	const char *buf, +	size_t buflen, +	const git_diff_options *opts); + +  GIT_END_DECL  /** @} */ | 
