| 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_object_h__ | ||
| 8 | #define INCLUDE_object_h__ | ||
| 9 | |||
| 10 | #include "common.h" | ||
| 11 | |||
| 12 | #include "repository.h" | ||
| 13 | |||
| 14 | #define GIT_OBJECT_SIZE_MAX UINT64_MAX | ||
| 15 | |||
| 16 | extern bool git_object__strict_input_validation; | ||
| 17 | |||
| 18 | /** Base git object for inheritance */ | ||
| 19 | struct git_object { | ||
| 20 | git_cached_obj cached; | ||
| 21 | git_repository *repo; | ||
| 22 | }; | ||
| 23 | |||
| 24 | /* fully free the object; internal method, DO NOT EXPORT */ | ||
| 25 | void git_object__free(void *object); | ||
| 26 | |||
| 27 | /* | ||
| 28 | * Parse object from raw data. Note that the resulting object is | ||
| 29 | * tied to the lifetime of the data, as some objects simply point | ||
| 30 | * into it. | ||
| 31 | */ | ||
| 32 | int git_object__from_raw( | ||
| 33 | git_object **object_out, | ||
| 34 | const char *data, | ||
| 35 | size_t size, | ||
| 36 | git_object_t type); | ||
| 37 | |||
| 38 | int git_object__from_odb_object( | ||
| 39 | git_object **object_out, | ||
| 40 | git_repository *repo, | ||
| 41 | git_odb_object *odb_obj, | ||
| 42 | git_object_t type); | ||
| 43 | |||
| 44 | int git_object__resolve_to_type(git_object **obj, git_object_t type); | ||
| 45 | |||
| 46 | git_object_t git_object_stringn2type(const char *str, size_t len); | ||
| 47 | |||
| 48 | int git_oid__parse(git_oid *oid, const char **buffer_out, const char *buffer_end, const char *header); | ||
| 49 | |||
| 50 | void git_oid__writebuf(git_str *buf, const char *header, const git_oid *oid); | ||
| 51 | |||
| 52 | bool git_object__is_valid( | ||
| 53 | git_repository *repo, const git_oid *id, git_object_t expected_type); | ||
| 54 | |||
| 55 | 43 | GIT_INLINE(git_object_t) git_object__type_from_filemode(git_filemode_t mode) | |
| 56 | { | ||
| 57 | 43 | switch (mode) { | |
| 58 | 0 | case GIT_FILEMODE_TREE: | |
| 59 | 0 | return GIT_OBJECT_TREE; | |
| 60 | 0 | case GIT_FILEMODE_COMMIT: | |
| 61 | 0 | return GIT_OBJECT_COMMIT; | |
| 62 | 43 | case GIT_FILEMODE_BLOB: | |
| 63 | case GIT_FILEMODE_BLOB_EXECUTABLE: | ||
| 64 | case GIT_FILEMODE_LINK: | ||
| 65 | 43 | return GIT_OBJECT_BLOB; | |
| 66 | 0 | default: | |
| 67 | 0 | return GIT_OBJECT_INVALID; | |
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | #endif |