]> git.proxmox.com Git - libgit2.git/blame - src/object.h
New upstream version 1.4.3+dfsg.1
[libgit2.git] / src / object.h
CommitLineData
c6ac28fd 1/*
359fc2d2 2 * Copyright (C) the libgit2 contributors. All rights reserved.
c6ac28fd
RB
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
eae0bfdc
PP
10#include "common.h"
11
3ef01e77
ET
12#include "repository.h"
13
22a2d3d5
UG
14#define GIT_OBJECT_SIZE_MAX UINT64_MAX
15
22a19f5b
ET
16extern bool git_object__strict_input_validation;
17
c6ac28fd
RB
18/** Base git object for inheritance */
19struct git_object {
20 git_cached_obj cached;
21 git_repository *repo;
c6ac28fd
RB
22};
23
24/* fully free the object; internal method, DO NOT EXPORT */
25void git_object__free(void *object);
26
ac3d33df
JK
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 */
32int git_object__from_raw(
33 git_object **object_out,
34 const char *data,
35 size_t size,
36 git_object_t type);
37
c6ac28fd
RB
38int git_object__from_odb_object(
39 git_object **object_out,
40 git_repository *repo,
41 git_odb_object *odb_obj,
ac3d33df 42 git_object_t type);
c6ac28fd 43
ac3d33df 44int git_object__resolve_to_type(git_object **obj, git_object_t type);
c6ac28fd 45
ac3d33df 46git_object_t git_object_stringn2type(const char *str, size_t len);
eae0bfdc 47
c6ac28fd
RB
48int git_oid__parse(git_oid *oid, const char **buffer_out, const char *buffer_end, const char *header);
49
e579e0f7 50void git_oid__writebuf(git_str *buf, const char *header, const git_oid *oid);
c6ac28fd 51
3ef01e77 52bool git_object__is_valid(
ac3d33df 53 git_repository *repo, const git_oid *id, git_object_t expected_type);
7565dc65 54
ac3d33df 55GIT_INLINE(git_object_t) git_object__type_from_filemode(git_filemode_t mode)
6ddf533a
ET
56{
57 switch (mode) {
58 case GIT_FILEMODE_TREE:
ac3d33df 59 return GIT_OBJECT_TREE;
6ddf533a 60 case GIT_FILEMODE_COMMIT:
ac3d33df 61 return GIT_OBJECT_COMMIT;
6ddf533a
ET
62 case GIT_FILEMODE_BLOB:
63 case GIT_FILEMODE_BLOB_EXECUTABLE:
64 case GIT_FILEMODE_LINK:
ac3d33df 65 return GIT_OBJECT_BLOB;
6ddf533a 66 default:
ac3d33df 67 return GIT_OBJECT_INVALID;
6ddf533a
ET
68 }
69}
70
c6ac28fd 71#endif