diff options
author | Russell Belfer <rb@github.com> | 2014-02-27 14:13:22 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-02-27 14:13:22 -0800 |
commit | 6789b7a75d1e24a7f4ce34628c6b4561517f0b73 (patch) | |
tree | 74ca53d8808a16090bb4df867b38c4a07444f8e1 /src/diff_file.c | |
parent | d88399922f622baef91c6f4e4e67b2091653cb65 (diff) | |
download | libgit2-6789b7a75d1e24a7f4ce34628c6b4561517f0b73.tar.gz |
Add buffer to buffer diff and patch APIs
This adds `git_diff_buffers` and `git_patch_from_buffers`. This
also includes a bunch of internal refactoring to increase the
shared code between these functions and the blob-to-blob and
blob-to-buffer APIs, as well as some higher level assert helpers
in the tests to also remove redundancy.
Diffstat (limited to 'src/diff_file.c')
-rw-r--r-- | src/diff_file.c | 49 |
1 files changed, 15 insertions, 34 deletions
diff --git a/src/diff_file.c b/src/diff_file.c index fb5d674f7..7dabf8d6f 100644 --- a/src/diff_file.c +++ b/src/diff_file.c @@ -127,57 +127,38 @@ int git_diff_file_content__init_from_diff( return diff_file_content_init_common(fc, &diff->opts); } -int git_diff_file_content__init_from_blob( +int git_diff_file_content__init_from_src( git_diff_file_content *fc, git_repository *repo, const git_diff_options *opts, - const git_blob *blob, + const git_diff_file_content_src *src, git_diff_file *as_file) { memset(fc, 0, sizeof(*fc)); fc->repo = repo; fc->file = as_file; - fc->blob = blob; + fc->blob = src->blob; - if (!blob) { + if (!src->blob && !src->buf) { fc->flags |= GIT_DIFF_FLAG__NO_DATA; } else { fc->flags |= GIT_DIFF_FLAG__LOADED; fc->file->flags |= GIT_DIFF_FLAG_VALID_ID; - fc->file->size = git_blob_rawsize(blob); fc->file->mode = GIT_FILEMODE_BLOB; - git_oid_cpy(&fc->file->id, git_blob_id(blob)); - fc->map.len = (size_t)fc->file->size; - fc->map.data = (char *)git_blob_rawcontent(blob); - } + if (src->blob) { + fc->file->size = git_blob_rawsize(src->blob); + git_oid_cpy(&fc->file->id, git_blob_id(src->blob)); - return diff_file_content_init_common(fc, opts); -} + fc->map.len = (size_t)fc->file->size; + fc->map.data = (char *)git_blob_rawcontent(src->blob); + } else { + fc->file->size = src->buflen; + git_odb_hash(&fc->file->id, src->buf, src->buflen, GIT_OBJ_BLOB); -int git_diff_file_content__init_from_raw( - git_diff_file_content *fc, - git_repository *repo, - const git_diff_options *opts, - const char *buf, - size_t buflen, - git_diff_file *as_file) -{ - memset(fc, 0, sizeof(*fc)); - fc->repo = repo; - fc->file = as_file; - - if (!buf) { - fc->flags |= GIT_DIFF_FLAG__NO_DATA; - } else { - fc->flags |= GIT_DIFF_FLAG__LOADED; - fc->file->flags |= GIT_DIFF_FLAG_VALID_ID; - fc->file->size = buflen; - fc->file->mode = GIT_FILEMODE_BLOB; - git_odb_hash(&fc->file->id, buf, buflen, GIT_OBJ_BLOB); - - fc->map.len = buflen; - fc->map.data = (char *)buf; + fc->map.len = src->buflen; + fc->map.data = (char *)src->buf; + } } return diff_file_content_init_common(fc, opts); |