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