]>
Commit | Line | Data |
---|---|---|
c15648cb | 1 | /* |
50298f44 SP |
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. | |
c15648cb | 5 | * |
50298f44 SP |
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.) | |
c15648cb | 14 | * |
50298f44 SP |
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. | |
c15648cb | 19 | * |
50298f44 SP |
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. | |
c15648cb SP |
24 | */ |
25 | ||
26 | #ifndef INCLUDE_git_odb_h__ | |
27 | #define INCLUDE_git_odb_h__ | |
28 | ||
d1ea30c3 SP |
29 | #include "git/common.h" |
30 | #include "git/oid.h" | |
c15648cb SP |
31 | |
32 | /** | |
d1ea30c3 | 33 | * @file git/odb.h |
c15648cb | 34 | * @brief Git object database routines |
8edc2805 | 35 | * @defgroup git_odb Git object database routines |
c15648cb SP |
36 | * @ingroup Git |
37 | * @{ | |
38 | */ | |
39 | GIT_BEGIN_DECL | |
40 | ||
41 | /** An open object database handle. */ | |
6533aadc | 42 | typedef struct git_odb git_odb; |
c15648cb SP |
43 | |
44 | /** | |
45 | * Open an object database for read/write access. | |
46 | * @param out location to store the database pointer, if opened. | |
47 | * Set to NULL if the open failed. | |
48 | * @param objects_dir path of the database's "objects" directory. | |
49 | * @return GIT_SUCCESS if the database opened; otherwise an error | |
50 | * code describing why the open was not possible. | |
51 | */ | |
6533aadc | 52 | GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir); |
c15648cb SP |
53 | |
54 | /** | |
55 | * Close an open object database. | |
56 | * @param db database pointer to close. If NULL no action is taken. | |
57 | * The pointer is set to NULL when the close is completed. | |
58 | */ | |
6533aadc | 59 | GIT_EXTERN(void) git_odb_close(git_odb **db); |
c15648cb SP |
60 | |
61 | /** Basic type (loose or packed) of any Git object. */ | |
62 | typedef enum { | |
bce499af SP |
63 | GIT_OBJ_BAD = -1, /**< Object is invalid. */ |
64 | GIT_OBJ__EXT1 = 0, /**< Reserved for future use. */ | |
65 | GIT_OBJ_COMMIT = 1, /**< A commit object. */ | |
66 | GIT_OBJ_TREE = 2, /**< A tree (directory listing) object. */ | |
67 | GIT_OBJ_BLOB = 3, /**< A file revision object. */ | |
68 | GIT_OBJ_TAG = 4, /**< An annotated tag object. */ | |
69 | GIT_OBJ__EXT2 = 5, /**< Reserved for future use. */ | |
70 | GIT_OBJ_OFS_DELTA = 6, /**< A delta, base is given by an offset. */ | |
71 | GIT_OBJ_REF_DELTA = 7, /**< A delta, base is given by object id. */ | |
6533aadc | 72 | } git_otype; |
c15648cb SP |
73 | |
74 | /** A small object read from the database. */ | |
75 | typedef struct { | |
29f0e90f SP |
76 | void *data; /**< Raw, decompressed object data. */ |
77 | size_t len ; /**< Total number of bytes in data. */ | |
6533aadc SP |
78 | git_otype type; /**< Type of this object. */ |
79 | } git_sobj; | |
c15648cb SP |
80 | |
81 | /** | |
82 | * Read a small object from the database. | |
b51eb250 SP |
83 | * |
84 | * If GIT_ENOTFOUND then out->data is set to NULL. | |
85 | * | |
c15648cb SP |
86 | * @param out object descriptor to populate upon reading. |
87 | * @param db database to search for the object in. | |
88 | * @param id identity of the object to read. | |
b51eb250 SP |
89 | * @return |
90 | * - GIT_SUCCESS if the object was read; | |
91 | * - GIT_ENOTFOUND if the object is not in the database. | |
c15648cb | 92 | */ |
6533aadc | 93 | GIT_EXTERN(int) git_odb_read(git_sobj *out, git_odb *db, const git_oid *id); |
c15648cb SP |
94 | |
95 | /** | |
96 | * Read a small object from the database using only pack files. | |
b51eb250 SP |
97 | * |
98 | * If GIT_ENOTFOUND then out->data is set to NULL. | |
99 | * | |
c15648cb SP |
100 | * @param out object descriptor to populate upon reading. |
101 | * @param db database to search for the object in. | |
102 | * @param id identity of the object to read. | |
b51eb250 SP |
103 | * @return |
104 | * - GIT_SUCCESS if the object was read. | |
105 | * - GIT_ENOTFOUND if the object is not in the database. | |
c15648cb | 106 | */ |
6533aadc | 107 | GIT_EXTERN(int) git_odb__read_packed(git_sobj *out, git_odb *db, const git_oid *id); |
c15648cb SP |
108 | |
109 | /** | |
110 | * Read a small object from the database using only loose object files. | |
b51eb250 SP |
111 | * |
112 | * If GIT_ENOTFOUND then out->data is set to NULL. | |
113 | * | |
c15648cb SP |
114 | * @param out object descriptor to populate upon reading. |
115 | * @param db database to search for the object in. | |
116 | * @param id identity of the object to read. | |
b51eb250 SP |
117 | * @return |
118 | * - GIT_SUCCESS if the object was read. | |
119 | * - GIT_ENOTFOUND if the object is not in the database. | |
c15648cb | 120 | */ |
6533aadc | 121 | GIT_EXTERN(int) git_odb__read_loose(git_sobj *out, git_odb *db, const git_oid *id); |
c15648cb | 122 | |
111d5ccf SP |
123 | /** |
124 | * Release all memory used by the sobj structure. | |
125 | * | |
126 | * As a result of this call, obj->data will be set to NULL. | |
127 | * | |
128 | * If obj->data is already NULL, nothing happens. | |
129 | * | |
130 | * @param obj object descriptor to free. | |
131 | */ | |
6533aadc | 132 | GIT_EXTERN(void) git_sobj_close(git_sobj *obj); |
111d5ccf | 133 | |
c15648cb SP |
134 | /** @} */ |
135 | GIT_END_DECL | |
136 | #endif |