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 module libgit2_d.object;
8 
9 
10 private static import libgit2_d.buffer;
11 private static import libgit2_d.oid;
12 private static import libgit2_d.types;
13 
14 /**
15  * @file git2/object.h
16  * @brief Git revision object management routines
17  * @defgroup git_object Git revision object management routines
18  * @ingroup Git
19  * @{
20  */
21 extern (C):
22 nothrow @nogc:
23 public:
24 
25 enum GIT_OBJECT_SIZE_MAX = ulong.max;
26 
27 /**
28  * Lookup a reference to one of the objects in a repository.
29  *
30  * The generated reference is owned by the repository and
31  * should be closed with the `git_object_free` method
32  * instead of free'd manually.
33  *
34  * The 'type' parameter must match the type of the object
35  * in the odb; the method will fail otherwise.
36  * The special value 'git_object_t.GIT_OBJECT_ANY' may be passed to let
37  * the method guess the object's type.
38  *
39  * Params:
40  *      object = pointer to the looked-up object
41  *      repo = the repository to look up the object
42  *      id = the unique identifier for the object
43  *      type = the type of the object
44  *
45  * Returns: 0 or an error code
46  */
47 //GIT_EXTERN
48 int git_object_lookup(libgit2_d.types.git_object** object, libgit2_d.types.git_repository* repo, const (libgit2_d.oid.git_oid)* id, libgit2_d.types.git_object_t type);
49 
50 /**
51  * Lookup a reference to one of the objects in a repository,
52  * given a prefix of its identifier (short id).
53  *
54  * The object obtained will be so that its identifier
55  * matches the first 'len' hexadecimal characters
56  * (packets of 4 bits) of the given 'id'.
57  * 'len' must be at least GIT_OID_MINPREFIXLEN, and
58  * long enough to identify a unique object matching
59  * the prefix; otherwise the method will fail.
60  *
61  * The generated reference is owned by the repository and
62  * should be closed with the `git_object_free` method
63  * instead of free'd manually.
64  *
65  * The 'type' parameter must match the type of the object
66  * in the odb; the method will fail otherwise.
67  * The special value 'git_object_t.GIT_OBJECT_ANY' may be passed to let
68  * the method guess the object's type.
69  *
70  * Params:
71  *      object_out = pointer where to store the looked-up object
72  *      repo = the repository to look up the object
73  *      id = a short identifier for the object
74  *      len = the length of the short identifier
75  *      type = the type of the object
76  *
77  * Returns: 0 or an error code
78  */
79 //GIT_EXTERN
80 int git_object_lookup_prefix(libgit2_d.types.git_object** object_out, libgit2_d.types.git_repository* repo, const (libgit2_d.oid.git_oid)* id, size_t len, libgit2_d.types.git_object_t type);
81 
82 /**
83  * Lookup an object that represents a tree entry.
84  *
85  * Params:
86  *      out_ = buffer that receives a pointer to the object (which must be freed by the caller)
87  *      treeish = root object that can be peeled to a tree
88  *      path = relative path from the root object to the desired object
89  *      type = type of object desired
90  *
91  * Returns: 0 on success, or an error code
92  */
93 //GIT_EXTERN
94 int git_object_lookup_bypath(libgit2_d.types.git_object** out_, const (libgit2_d.types.git_object)* treeish, const (char)* path, libgit2_d.types.git_object_t type);
95 
96 /**
97  * Get the id (SHA1) of a repository object
98  *
99  * Params:
100  *      obj = the repository object
101  *
102  * Returns: the SHA1 id
103  */
104 //GIT_EXTERN
105 const (libgit2_d.oid.git_oid)* git_object_id(const (libgit2_d.types.git_object)* obj);
106 
107 /**
108  * Get a short abbreviated OID string for the object
109  *
110  * This starts at the "core.abbrev" length (default 7 characters) and
111  * iteratively extends to a longer string if that length is ambiguous.
112  * The result will be unambiguous (at least until new objects are added to
113  * the repository).
114  *
115  * Params:
116  *      out_ = Buffer to write string into
117  *      obj = The object to get an ID for
118  *
119  * Returns: 0 on success, <0 for error
120  */
121 //GIT_EXTERN
122 int git_object_short_id(libgit2_d.buffer.git_buf* out_, const (libgit2_d.types.git_object)* obj);
123 
124 /**
125  * Get the object type of an object
126  *
127  * Params:
128  *      obj = the repository object
129  *
130  * Returns: the object's type
131  */
132 //GIT_EXTERN
133 libgit2_d.types.git_object_t git_object_type(const (libgit2_d.types.git_object)* obj);
134 
135 /**
136  * Get the repository that owns this object
137  *
138  * Freeing or calling `git_repository_close` on the
139  * returned pointer will invalidate the actual object.
140  *
141  * Any other operation may be run on the repository without
142  * affecting the object.
143  *
144  * Params:
145  *      obj = the object
146  *
147  * Returns: the repository who owns this object
148  */
149 //GIT_EXTERN
150 libgit2_d.types.git_repository* git_object_owner(const (libgit2_d.types.git_object)* obj);
151 
152 /**
153  * Close an open object
154  *
155  * This method instructs the library to close an existing
156  * object; note that git_objects are owned and cached by the repository
157  * so the object may or may not be freed after this library call,
158  * depending on how aggressive is the caching mechanism used
159  * by the repository.
160  *
161  * IMPORTANT:
162  * It *is* necessary to call this method when you stop using
163  * an object. Failure to do so will cause a memory leak.
164  *
165  * Params:
166  *      object = the object to close
167  */
168 //GIT_EXTERN
169 void git_object_free(libgit2_d.types.git_object* object);
170 
171 /**
172  * Convert an object type to its string representation.
173  *
174  * The result is a pointer to a string in static memory and
175  * should not be free()'ed.
176  *
177  * Params:
178  *      type = object type to convert.
179  *
180  * Returns: the corresponding string representation.
181  */
182 //GIT_EXTERN
183 const (char)* git_object_type2string(libgit2_d.types.git_object_t type);
184 
185 /**
186  * Convert a string object type representation to it's libgit2_d.types.git_object_t.
187  *
188  * Params:
189  *      str = the string to convert.
190  *
191  * Returns: the corresponding libgit2_d.types.git_object_t.
192  */
193 //GIT_EXTERN
194 libgit2_d.types.git_object_t git_object_string2type(const (char)* str);
195 
196 /**
197  * Determine if the given libgit2_d.types.git_object_t is a valid loose object type.
198  *
199  * Params:
200  *      type = object type to test.
201  *
202  * Returns: true if the type represents a valid loose object type, false otherwise.
203  */
204 //GIT_EXTERN
205 int git_object_typeisloose(libgit2_d.types.git_object_t type);
206 
207 /**
208  * Recursively peel an object until an object of the specified type is met.
209  *
210  * If the query cannot be satisfied due to the object model,
211  * git_error_code.GIT_EINVALIDSPEC will be returned (e.g. trying to peel a blob to a
212  * tree).
213  *
214  * If you pass `git_object_t.GIT_OBJECT_ANY` as the target type, then the object will
215  * be peeled until the type changes. A tag will be peeled until the
216  * referenced object is no longer a tag, and a commit will be peeled
217  * to a tree. Any other object type will return git_error_code.GIT_EINVALIDSPEC.
218  *
219  * If peeling a tag we discover an object which cannot be peeled to
220  * the target type due to the object model, git_error_code.GIT_EPEEL will be
221  * returned.
222  *
223  * You must free the returned object.
224  *
225  * Params:
226  *      peeled = Pointer to the peeled git_object
227  *      object = The object to be processed
228  *      target_type = The type of the requested object (a GIT_OBJECT_ value)
229  *
230  * Returns: 0 on success, git_error_code.GIT_EINVALIDSPEC, git_error_code.GIT_EPEEL, or an error code
231  */
232 //GIT_EXTERN
233 int git_object_peel(libgit2_d.types.git_object** peeled, const (libgit2_d.types.git_object)* object, libgit2_d.types.git_object_t target_type);
234 
235 /**
236  * Create an in-memory copy of a Git object. The copy must be
237  * explicitly free'd or it will leak.
238  *
239  * Params:
240  *      dest = Pointer to store the copy of the object
241  *      source = Original object to copy
242  */
243 //GIT_EXTERN
244 int git_object_dup(libgit2_d.types.git_object** dest, libgit2_d.types.git_object* source);
245 
246 /** @} */