]> git.proxmox.com Git - libgit2.git/blob - include/git2/object.h
I broke your bindings
[libgit2.git] / include / git2 / object.h
1 /*
2 * This file is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2,
4 * as published by the Free Software Foundation.
5 *
6 * In addition to the permissions in the GNU General Public License,
7 * the authors give you unlimited permission to link the compiled
8 * version of this file into combinations with other programs,
9 * and to distribute those combinations without any restriction
10 * coming from the use of this file. (The General Public License
11 * restrictions do apply in other respects; for example, they cover
12 * modification of the file, and distribution when not linked into
13 * a combined executable.)
14 *
15 * This file is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24 */
25 #ifndef INCLUDE_git_object_h__
26 #define INCLUDE_git_object_h__
27
28 #include "common.h"
29 #include "types.h"
30 #include "oid.h"
31
32 /**
33 * @file git2/object.h
34 * @brief Git revision object management routines
35 * @defgroup git_object Git revision object management routines
36 * @ingroup Git
37 * @{
38 */
39 GIT_BEGIN_DECL
40
41 /**
42 * Lookup a reference to one of the objects in a repostory.
43 *
44 * The generated reference is owned by the repository and
45 * should be closed with the `git_object_close` method
46 * instead of free'd manually.
47 *
48 * The 'type' parameter must match the type of the object
49 * in the odb; the method will fail otherwise.
50 * The special value 'GIT_OBJ_ANY' may be passed to let
51 * the method guess the object's type.
52 *
53 * @param object pointer to the looked-up object
54 * @param repo the repository to look up the object
55 * @param id the unique identifier for the object
56 * @param type the type of the object
57 * @return a reference to the object
58 */
59 GIT_EXTERN(int) git_object_lookup(git_object **object, git_repository *repo, const git_oid *id, git_otype type);
60
61 /**
62 * Get the id (SHA1) of a repository object
63 *
64 * @param obj the repository object
65 * @return the SHA1 id
66 */
67 GIT_EXTERN(const git_oid *) git_object_id(const git_object *obj);
68
69 /**
70 * Get the object type of an object
71 *
72 * @param obj the repository object
73 * @return the object's type
74 */
75 GIT_EXTERN(git_otype) git_object_type(const git_object *obj);
76
77 /**
78 * Get the repository that owns this object
79 *
80 * @param obj the object
81 * @return the repository who owns this object
82 */
83 GIT_EXTERN(git_repository *) git_object_owner(const git_object *obj);
84
85 /**
86 * Close an open object
87 *
88 * This method instructs the library to close an existing
89 * object; note that git_objects are owned and cached by the repository
90 * so the object may or may not be freed after this library call,
91 * depending on how agressive is the caching mechanism used
92 * by the repository.
93 *
94 * IMPORTANT:
95 * It *is* necessary to call this method when you stop using
96 * an object. Failure to do so will cause a memory leak.
97 *
98 * @param object the object to close
99 */
100 GIT_EXTERN(void) git_object_close(git_object *object);
101
102 /**
103 * Convert an object type to it's string representation.
104 *
105 * The result is a pointer to a string in static memory and
106 * should not be free()'ed.
107 *
108 * @param type object type to convert.
109 * @return the corresponding string representation.
110 */
111 GIT_EXTERN(const char *) git_object_type2string(git_otype type);
112
113 /**
114 * Convert a string object type representation to it's git_otype.
115 *
116 * @param str the string to convert.
117 * @return the corresponding git_otype.
118 */
119 GIT_EXTERN(git_otype) git_object_string2type(const char *str);
120
121 /**
122 * Determine if the given git_otype is a valid loose object type.
123 *
124 * @param type object type to test.
125 * @return true if the type represents a valid loose object type,
126 * false otherwise.
127 */
128 GIT_EXTERN(int) git_object_typeisloose(git_otype type);
129
130 /**
131 * Get the size in bytes for the structure which
132 * acts as an in-memory representation of any given
133 * object type.
134 *
135 * For all the core types, this would the equivalent
136 * of calling `sizeof(git_commit)` if the core types
137 * were not opaque on the external API.
138 *
139 * @param type object type to get its size
140 * @return size in bytes of the object
141 */
142 GIT_EXTERN(size_t) git_object__size(git_otype type);
143
144 /** @} */
145 GIT_END_DECL
146
147 #endif