diff options
author | Vicent Marti <vicent@github.com> | 2014-02-28 09:40:17 +0100 |
---|---|---|
committer | Vicent Marti <vicent@github.com> | 2014-02-28 09:40:17 +0100 |
commit | 06d41826b6f85d83e68973e0565978b6b3e8976f (patch) | |
tree | 74ca53d8808a16090bb4df867b38c4a07444f8e1 /src/diff_file.c | |
parent | 1574d3884f020c072f68c08785e199732e438e34 (diff) | |
parent | 6789b7a75d1e24a7f4ce34628c6b4561517f0b73 (diff) | |
download | libgit2-06d41826b6f85d83e68973e0565978b6b3e8976f.tar.gz |
Merge pull request #2146 from libgit2/rb/diff-b2b
Add git_diff_buffers and git_patch_from_buffers
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); |