1 /* 2 * Copyright (C) the libgit2 contributors. All rights reserved. 3 * 4 * This file is part of libgit2, distributed under the GNU GPL v2 with 5 * a Linking Exception. For full terms see the included COPYING file. 6 */ 7 #ifndef INCLUDE_blob_h__ 8 #define INCLUDE_blob_h__ 9 10 #include "common.h" 11 12 #include "git2/blob.h" 13 #include "repository.h" 14 #include "odb.h" 15 #include "futils.h" 16 17 struct git_blob { 18 git_object object; 19 20 union { 21 git_odb_object *odb; 22 struct { 23 const char *data; 24 git_object_size_t size; 25 } raw; 26 } data; 27 unsigned int raw:1; 28 }; 29 30 #define GIT_ERROR_CHECK_BLOBSIZE(n) \ 31 do { \ 32 if (!git__is_sizet(n)) { \ 33 git_error_set(GIT_ERROR_NOMEMORY, "blob contents too large to fit in memory"); \ 34 return -1; \ 35 } \ 36 } while(0) 37 38 void git_blob__free(void *blob); 39 int git_blob__parse(void *blob, git_odb_object *obj); 40 int git_blob__parse_raw(void *blob, const char *data, size_t size); 41 int git_blob__getbuf(git_buf *buffer, git_blob *blob); 42 43 extern int git_blob__create_from_paths( 44 git_oid *out_oid, 45 struct stat *out_st, 46 git_repository *repo, 47 const char *full_path, 48 const char *hint_path, 49 mode_t hint_mode, 50 bool apply_filters); 51 52 #endif 53