diff options
| author | Vicent Martà <vicent@github.com> | 2013-01-07 18:33:50 -0800 |
|---|---|---|
| committer | Vicent Martà <vicent@github.com> | 2013-01-07 18:33:50 -0800 |
| commit | 368a2b4e3edc32229793045f4970d33b366722bd (patch) | |
| tree | 0fca2a3ed081c1aa3e98679468f1ca273d1a3280 /include | |
| parent | 7dfc5c3c6c4cebe6e2477186a8e7ed6e7dba2c55 (diff) | |
| parent | f2b7f7a6cb8678763ada70e75d5b38407770e269 (diff) | |
| download | libgit2-368a2b4e3edc32229793045f4970d33b366722bd.tar.gz | |
Merge pull request #1204 from arrbee/diff-blob-to-buffer
Have diff blob to buffer share code (and add tests)
Diffstat (limited to 'include')
| -rw-r--r-- | include/git2/blob.h | 4 | ||||
| -rw-r--r-- | include/git2/diff.h | 40 |
2 files changed, 33 insertions, 11 deletions
diff --git a/include/git2/blob.h b/include/git2/blob.h index 30055b614..93d1c7646 100644 --- a/include/git2/blob.h +++ b/include/git2/blob.h @@ -91,7 +91,7 @@ GIT_INLINE(const git_oid *) git_blob_id(const git_blob *blob) * @param blob pointer to the blob * @return the pointer; NULL if the blob has no contents */ -GIT_EXTERN(const void *) git_blob_rawcontent(git_blob *blob); +GIT_EXTERN(const void *) git_blob_rawcontent(const git_blob *blob); /** * Get the size in bytes of the contents of a blob @@ -99,7 +99,7 @@ GIT_EXTERN(const void *) git_blob_rawcontent(git_blob *blob); * @param blob pointer to the blob * @return size on bytes */ -GIT_EXTERN(git_off_t) git_blob_rawsize(git_blob *blob); +GIT_EXTERN(git_off_t) git_blob_rawsize(const git_blob *blob); /** * Read a file from the working folder of a repository diff --git a/include/git2/diff.h b/include/git2/diff.h index 760de6fd1..70dbd97aa 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -802,28 +802,50 @@ GIT_EXTERN(int) git_diff_patch_to_str( */ /** - * Directly run a text diff on two blobs. + * Directly run a diff on two blobs. * * Compared to a file, a blob lacks some contextual information. As such, - * the `git_diff_file` parameters of the callbacks will be filled - * accordingly to the following: `mode` will be set to 0, `path` will be set - * to NULL. When dealing with a NULL blob, `oid` will be set to 0. + * the `git_diff_file` given to the callback will have some fake data; i.e. + * `mode` will be 0 and `path` will be NULL. * - * When at least one of the blobs being dealt with is binary, the - * `git_diff_delta` binary attribute will be set to 1 and no call to the - * hunk_cb nor line_cb will be made. + * NULL is allowed for either `old_blob` or `new_blob` and will be treated + * as an empty blob, with the `oid` set to NULL in the `git_diff_file` data. + * + * We do run a binary content check on the two blobs and if either of the + * blobs looks like binary data, the `git_diff_delta` binary attribute will + * be set to 1 and no call to the hunk_cb nor line_cb will be made (unless + * you pass `GIT_DIFF_FORCE_TEXT` of course). * * @return 0 on success, GIT_EUSER on non-zero callback, or error code */ GIT_EXTERN(int) git_diff_blobs( - git_blob *old_blob, - git_blob *new_blob, + const git_blob *old_blob, + const git_blob *new_blob, const git_diff_options *options, git_diff_file_cb file_cb, git_diff_hunk_cb hunk_cb, git_diff_data_cb line_cb, void *payload); +/** + * Directly run a diff between a blob and a buffer. + * + * As with `git_diff_blobs`, comparing a blob and buffer lacks some context, + * so the `git_diff_file` parameters to the callbacks will be faked a la the + * rules for `git_diff_blobs()`. + * + * @return 0 on success, GIT_EUSER on non-zero callback, or error code + */ +GIT_EXTERN(int) git_diff_blob_to_buffer( + const git_blob *old_blob, + const char *buffer, + size_t buffer_len, + const git_diff_options *options, + git_diff_file_cb file_cb, + git_diff_hunk_cb hunk_cb, + git_diff_data_cb data_cb, + void *payload); + GIT_END_DECL /** @} */ |
