2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 struct got_blob_object;
21 struct got_tree_entry {
22 SIMPLEQ_ENTRY(got_tree_entry) entry;
25 struct got_object_id *id;
28 struct got_tree_object {
30 SIMPLEQ_HEAD(, got_tree_entry) entries;
33 struct got_parent_id {
34 SIMPLEQ_ENTRY(got_parent_id) entry;
35 struct got_object_id *id;
38 struct got_commit_object {
39 struct got_object_id *tree_id;
40 unsigned int nparents;
41 SIMPLEQ_HEAD(, got_parent_id) parent_ids;
43 time_t author_time; /* UTC */
45 time_t committer_time; /* UTC */
49 /* A generic object. Used as a handle which holds an ID and an object type. */
51 #define GOT_OBJ_TYPE_COMMIT 1
52 #define GOT_OBJ_TYPE_TREE 2
53 #define GOT_OBJ_TYPE_BLOB 3
54 #define GOT_OBJ_TYPE_TAG 4
56 #define GOT_OBJ_TYPE_OFFSET_DELTA 6
57 #define GOT_OBJ_TYPE_REF_DELTA 7
59 struct got_repository;
62 * Obtain a string representation of an object ID. The output depends on
63 * the hash function used by the repository format (currently SHA1).
65 const struct got_error *got_object_id_str(char **, struct got_object_id *);
68 * Compare two object IDs. Return value behaves like memcmp(3).
70 int got_object_id_cmp(struct got_object_id *, struct got_object_id *);
73 * Created a newly allocated copy of an object ID.
74 * The caller should dispose of it with free(3).
76 struct got_object_id *got_object_id_dup(struct got_object_id *);
79 * Get a newly allocated copy of an object's ID.
80 * The caller should dispose of it with free(3).
82 struct got_object_id *got_object_get_id(struct got_object *);
85 * Get a newly allocated copy of an object's ID string.
86 * The caller should dispose of it with free(3).
88 const struct got_error *got_object_get_id_str(char **, struct got_object *);
91 * Obtain the type of an object.
92 * Returns one of the GOT_OBJ_TYPE_x values (see above).
94 int got_object_get_type(struct got_object *);
97 * Attempt to open the object in a repository with the provided ID.
98 * Caller must dispose of it with got_object_close().
100 const struct got_error *got_object_open(struct got_object **,
101 struct got_repository *, struct got_object_id *);
104 * Attempt to map the provided ID string to an object ID and then
105 * attempt to open the object in a repository with this ID.
106 * The form of an ID string depends on the hash function used by the
107 * repository format (currently SHA1).
108 * Caller must dispose of the object with got_object_close().
110 const struct got_error *got_object_open_by_id_str(struct got_object **,
111 struct got_repository *, const char *);
113 /* Dispose of an object. */
114 void got_object_close(struct got_object *);
117 * Attempt to open a commit object in a repository.
118 * The provided object must be of type GOT_OBJ_TYPE_COMMIT.
119 * The caller must dispose of the commit with got_object_commit_close().
121 const struct got_error *got_object_commit_open(struct got_commit_object **,
122 struct got_repository *, struct got_object *);
124 /* Dispose of a commit object. */
125 void got_object_commit_close(struct got_commit_object *);
128 * Attempt to open a tree object in a repository.
129 * The provided object must be of type GOT_OBJ_TYPE_TREE.
130 * The caller must dispose of the tree with got_object_tree_close().
132 const struct got_error *got_object_tree_open(struct got_tree_object **,
133 struct got_repository *, struct got_object *);
135 /* Dispose of a tree object. */
136 void got_object_tree_close(struct got_tree_object *);
139 * Attempt to open a blob object in a repository.
140 * The provided object must be of type GOT_OBJ_TYPE_BLOB.
141 * The size_t argument specifies the block size of an associated read buffer.
142 * The caller must dispose of the blob with got_object_blob_close().
144 const struct got_error *got_object_blob_open(struct got_blob_object **,
145 struct got_repository *, struct got_object *, size_t);
147 /* Dispose of a blob object. */
148 void got_object_blob_close(struct got_blob_object *);
151 * Write the string representation of the object ID of a blob to a buffer.
152 * The size_t argument speficies the size of the buffer. In the current
153 * implementation, it must be at least SHA1_DIGEST_STRING_LENGTH bytes.
154 * XXX This is a bad API, use got_object_id_str() instead.
156 char *got_object_blob_id_str(struct got_blob_object*, char *, size_t);
159 * Get the length of header data at the beginning of the blob's read buffer.
160 * Note that header data is only present upon the first invocation of
161 * got_object_blob_read_block() after the blob is opened.
163 size_t got_object_blob_get_hdrlen(struct got_blob_object *);
166 * Get a pointer to the blob's read buffer.
167 * The read buffer is filled by got_object_blob_read_block().
169 const uint8_t *got_object_blob_get_read_buf(struct got_blob_object *);
172 * Read the next chunk of data from a blob, up to the blob's read buffer
173 * block size. The size_t output argument indicates how many bytes have
174 * been read into the blob's read buffer. Zero bytes will be reported if
175 * all data in the blob has been read.
177 const struct got_error *got_object_blob_read_block(size_t *,
178 struct got_blob_object *);
179 const struct got_error *got_object_commit_add_parent(struct got_commit_object *,