Blame


1 7b19e0f1 2017-11-05 stsp /*
2 a1fd68d8 2018-01-12 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 7b19e0f1 2017-11-05 stsp *
4 7b19e0f1 2017-11-05 stsp * Permission to use, copy, modify, and distribute this software for any
5 7b19e0f1 2017-11-05 stsp * purpose with or without fee is hereby granted, provided that the above
6 7b19e0f1 2017-11-05 stsp * copyright notice and this permission notice appear in all copies.
7 7b19e0f1 2017-11-05 stsp *
8 7b19e0f1 2017-11-05 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 7b19e0f1 2017-11-05 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 7b19e0f1 2017-11-05 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 7b19e0f1 2017-11-05 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 7b19e0f1 2017-11-05 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 7b19e0f1 2017-11-05 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 7b19e0f1 2017-11-05 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 7b19e0f1 2017-11-05 stsp */
16 7b19e0f1 2017-11-05 stsp
17 59ece79d 2018-02-12 stsp struct got_object_id;
18 d71d75ad 2017-11-05 stsp
19 f934cf2c 2018-02-12 stsp struct got_blob_object;
20 883f0469 2018-06-23 stsp struct got_tree_object;
21 f4a881ce 2018-11-17 stsp struct got_tag_object;
22 d1cda826 2017-11-06 stsp
23 0ffeb3c2 2017-11-26 stsp struct got_tree_entry {
24 0ffeb3c2 2017-11-26 stsp SIMPLEQ_ENTRY(got_tree_entry) entry;
25 0ffeb3c2 2017-11-26 stsp mode_t mode;
26 0ffeb3c2 2017-11-26 stsp char *name;
27 59ece79d 2018-02-12 stsp struct got_object_id *id;
28 0ffeb3c2 2017-11-26 stsp };
29 0ffeb3c2 2017-11-26 stsp
30 883f0469 2018-06-23 stsp SIMPLEQ_HEAD(got_tree_entries_queue, got_tree_entry);
31 f6be5c30 2018-06-22 stsp
32 883f0469 2018-06-23 stsp struct got_tree_entries {
33 883f0469 2018-06-23 stsp int nentries;
34 883f0469 2018-06-23 stsp struct got_tree_entries_queue head;
35 d1cda826 2017-11-06 stsp };
36 d1cda826 2017-11-06 stsp
37 79f35eb3 2018-06-11 stsp struct got_object_qid {
38 79f35eb3 2018-06-11 stsp SIMPLEQ_ENTRY(got_object_qid) entry;
39 59ece79d 2018-02-12 stsp struct got_object_id *id;
40 d1cda826 2017-11-06 stsp };
41 d1cda826 2017-11-06 stsp
42 79f35eb3 2018-06-11 stsp SIMPLEQ_HEAD(got_object_id_queue, got_object_qid);
43 b43fbaa0 2018-06-11 stsp
44 dbc6a6b6 2018-07-12 stsp const struct got_error *got_object_qid_alloc(struct got_object_qid **,
45 dbc6a6b6 2018-07-12 stsp struct got_object_id *);
46 dbc6a6b6 2018-07-12 stsp void got_object_qid_free(struct got_object_qid *);
47 dbc6a6b6 2018-07-12 stsp
48 d1cda826 2017-11-06 stsp struct got_commit_object {
49 59ece79d 2018-02-12 stsp struct got_object_id *tree_id;
50 d1cda826 2017-11-06 stsp unsigned int nparents;
51 79f35eb3 2018-06-11 stsp struct got_object_id_queue parent_ids;
52 d1cda826 2017-11-06 stsp char *author;
53 ccb26ccd 2018-11-05 stsp time_t author_time; /* UTC */
54 ccb26ccd 2018-11-05 stsp time_t author_gmtoff;
55 d1cda826 2017-11-06 stsp char *committer;
56 ccb26ccd 2018-11-05 stsp time_t committer_time; /* UTC */
57 ccb26ccd 2018-11-05 stsp time_t committer_gmtoff;
58 d1cda826 2017-11-06 stsp char *logmsg;
59 1943de01 2018-06-22 stsp
60 1943de01 2018-06-22 stsp int refcnt; /* for internal use only */
61 d1cda826 2017-11-06 stsp };
62 d1cda826 2017-11-06 stsp
63 0c60ce5a 2018-04-02 stsp /* A generic object. Used as a handle which holds an ID and an object type. */
64 eef6493a 2018-01-19 stsp struct got_object;
65 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_COMMIT 1
66 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_TREE 2
67 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_BLOB 3
68 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_TAG 4
69 f9a4270b 2017-12-03 stsp /* 5 is reserved */
70 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_OFFSET_DELTA 6
71 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_REF_DELTA 7
72 ab9a70b2 2017-11-06 stsp
73 ab9a70b2 2017-11-06 stsp struct got_repository;
74 ab9a70b2 2017-11-06 stsp
75 0c60ce5a 2018-04-02 stsp /*
76 0c60ce5a 2018-04-02 stsp * Obtain a string representation of an object ID. The output depends on
77 0c60ce5a 2018-04-02 stsp * the hash function used by the repository format (currently SHA1).
78 0c60ce5a 2018-04-02 stsp */
79 ef0981d5 2018-02-12 stsp const struct got_error *got_object_id_str(char **, struct got_object_id *);
80 0c60ce5a 2018-04-02 stsp
81 0c60ce5a 2018-04-02 stsp /*
82 0c60ce5a 2018-04-02 stsp * Compare two object IDs. Return value behaves like memcmp(3).
83 0c60ce5a 2018-04-02 stsp */
84 984e8a45 2018-11-05 stsp int got_object_id_cmp(const struct got_object_id *,
85 984e8a45 2018-11-05 stsp const struct got_object_id *);
86 0c60ce5a 2018-04-02 stsp
87 0c60ce5a 2018-04-02 stsp /*
88 0c60ce5a 2018-04-02 stsp * Created a newly allocated copy of an object ID.
89 0c60ce5a 2018-04-02 stsp * The caller should dispose of it with free(3).
90 0c60ce5a 2018-04-02 stsp */
91 8bf5b3c9 2018-03-17 stsp struct got_object_id *got_object_id_dup(struct got_object_id *);
92 0c60ce5a 2018-04-02 stsp
93 0c60ce5a 2018-04-02 stsp /*
94 0c60ce5a 2018-04-02 stsp * Get a newly allocated copy of an object's ID.
95 6402fb3c 2018-09-15 stsp * The caller must treat the ID as read-only and must not call free(3) on it.
96 6402fb3c 2018-09-15 stsp * Use got_object_id_dup() to get a writable copy.
97 0c60ce5a 2018-04-02 stsp */
98 3235492e 2018-04-01 stsp struct got_object_id *got_object_get_id(struct got_object *);
99 0c60ce5a 2018-04-02 stsp
100 0c60ce5a 2018-04-02 stsp /*
101 bacc9935 2018-05-20 stsp * Get a newly allocated copy of an object's ID string.
102 bacc9935 2018-05-20 stsp * The caller should dispose of it with free(3).
103 bacc9935 2018-05-20 stsp */
104 bacc9935 2018-05-20 stsp const struct got_error *got_object_get_id_str(char **, struct got_object *);
105 bacc9935 2018-05-20 stsp
106 bacc9935 2018-05-20 stsp /*
107 27d434c2 2018-09-15 stsp * Get a newly allocated ID of the object which resides at the specified
108 27d434c2 2018-09-15 stsp * path in the tree of the specified commit.
109 27d434c2 2018-09-15 stsp * The caller should dispose of it with free(3).
110 27d434c2 2018-09-15 stsp */
111 27d434c2 2018-09-15 stsp const struct got_error *
112 27d434c2 2018-09-15 stsp got_object_id_by_path(struct got_object_id **, struct got_repository *,
113 27d434c2 2018-09-15 stsp struct got_object_id *, const char *);
114 27d434c2 2018-09-15 stsp
115 27d434c2 2018-09-15 stsp /*
116 0c60ce5a 2018-04-02 stsp * Obtain the type of an object.
117 0c60ce5a 2018-04-02 stsp * Returns one of the GOT_OBJ_TYPE_x values (see above).
118 0c60ce5a 2018-04-02 stsp */
119 b107e67f 2018-01-19 stsp int got_object_get_type(struct got_object *);
120 0c60ce5a 2018-04-02 stsp
121 0c60ce5a 2018-04-02 stsp /*
122 0c60ce5a 2018-04-02 stsp * Attempt to open the object in a repository with the provided ID.
123 0c60ce5a 2018-04-02 stsp * Caller must dispose of it with got_object_close().
124 0c60ce5a 2018-04-02 stsp */
125 ab9a70b2 2017-11-06 stsp const struct got_error *got_object_open(struct got_object **,
126 ab9a70b2 2017-11-06 stsp struct got_repository *, struct got_object_id *);
127 0c60ce5a 2018-04-02 stsp
128 0c60ce5a 2018-04-02 stsp /*
129 0c60ce5a 2018-04-02 stsp * Attempt to map the provided ID string to an object ID and then
130 0c60ce5a 2018-04-02 stsp * attempt to open the object in a repository with this ID.
131 0c60ce5a 2018-04-02 stsp * The form of an ID string depends on the hash function used by the
132 0c60ce5a 2018-04-02 stsp * repository format (currently SHA1).
133 0c60ce5a 2018-04-02 stsp * Caller must dispose of the object with got_object_close().
134 0c60ce5a 2018-04-02 stsp */
135 6dfa2fd3 2018-02-12 stsp const struct got_error *got_object_open_by_id_str(struct got_object **,
136 0c60ce5a 2018-04-02 stsp struct got_repository *, const char *);
137 0c60ce5a 2018-04-02 stsp
138 0c60ce5a 2018-04-02 stsp /* Dispose of an object. */
139 ab9a70b2 2017-11-06 stsp void got_object_close(struct got_object *);
140 0c60ce5a 2018-04-02 stsp
141 0c60ce5a 2018-04-02 stsp /*
142 0c60ce5a 2018-04-02 stsp * Attempt to open a commit object in a repository.
143 0c60ce5a 2018-04-02 stsp * The provided object must be of type GOT_OBJ_TYPE_COMMIT.
144 0c60ce5a 2018-04-02 stsp * The caller must dispose of the commit with got_object_commit_close().
145 0c60ce5a 2018-04-02 stsp */
146 d1cda826 2017-11-06 stsp const struct got_error *got_object_commit_open(struct got_commit_object **,
147 d1cda826 2017-11-06 stsp struct got_repository *, struct got_object *);
148 0c60ce5a 2018-04-02 stsp
149 0c60ce5a 2018-04-02 stsp /* Dispose of a commit object. */
150 d1cda826 2017-11-06 stsp void got_object_commit_close(struct got_commit_object *);
151 0c60ce5a 2018-04-02 stsp
152 0c60ce5a 2018-04-02 stsp /*
153 0c60ce5a 2018-04-02 stsp * Attempt to open a tree object in a repository.
154 0c60ce5a 2018-04-02 stsp * The provided object must be of type GOT_OBJ_TYPE_TREE.
155 0c60ce5a 2018-04-02 stsp * The caller must dispose of the tree with got_object_tree_close().
156 0c60ce5a 2018-04-02 stsp */
157 0ffeb3c2 2017-11-26 stsp const struct got_error *got_object_tree_open(struct got_tree_object **,
158 0ffeb3c2 2017-11-26 stsp struct got_repository *, struct got_object *);
159 0c60ce5a 2018-04-02 stsp
160 0c60ce5a 2018-04-02 stsp /* Dispose of a tree object. */
161 0ffeb3c2 2017-11-26 stsp void got_object_tree_close(struct got_tree_object *);
162 0c60ce5a 2018-04-02 stsp
163 883f0469 2018-06-23 stsp /* Get the entries of a tree object. */
164 883f0469 2018-06-23 stsp const struct got_tree_entries *got_object_tree_get_entries(
165 883f0469 2018-06-23 stsp struct got_tree_object *);
166 883f0469 2018-06-23 stsp
167 0c60ce5a 2018-04-02 stsp /*
168 07862c20 2018-09-15 stsp * Compare two trees and indicate whether the entry at the specified path
169 31cedeaf 2018-09-15 stsp * differs between them. The path must not be the root path "/"; the function
170 31cedeaf 2018-09-15 stsp * got_object_id_cmp() should be used instead to compare the tree roots.
171 07862c20 2018-09-15 stsp */
172 07862c20 2018-09-15 stsp const struct got_error *got_object_tree_path_changed(int *,
173 07862c20 2018-09-15 stsp struct got_tree_object *, struct got_tree_object *, const char *,
174 07862c20 2018-09-15 stsp struct got_repository *);
175 07862c20 2018-09-15 stsp
176 07862c20 2018-09-15 stsp /*
177 0c60ce5a 2018-04-02 stsp * Attempt to open a blob object in a repository.
178 0c60ce5a 2018-04-02 stsp * The provided object must be of type GOT_OBJ_TYPE_BLOB.
179 0c60ce5a 2018-04-02 stsp * The size_t argument specifies the block size of an associated read buffer.
180 0c60ce5a 2018-04-02 stsp * The caller must dispose of the blob with got_object_blob_close().
181 0c60ce5a 2018-04-02 stsp */
182 68482ea3 2017-11-27 stsp const struct got_error *got_object_blob_open(struct got_blob_object **,
183 68482ea3 2017-11-27 stsp struct got_repository *, struct got_object *, size_t);
184 0c60ce5a 2018-04-02 stsp
185 0c60ce5a 2018-04-02 stsp /* Dispose of a blob object. */
186 68482ea3 2017-11-27 stsp void got_object_blob_close(struct got_blob_object *);
187 0c60ce5a 2018-04-02 stsp
188 0c60ce5a 2018-04-02 stsp /*
189 0c60ce5a 2018-04-02 stsp * Write the string representation of the object ID of a blob to a buffer.
190 0c60ce5a 2018-04-02 stsp * The size_t argument speficies the size of the buffer. In the current
191 0c60ce5a 2018-04-02 stsp * implementation, it must be at least SHA1_DIGEST_STRING_LENGTH bytes.
192 0c60ce5a 2018-04-02 stsp * XXX This is a bad API, use got_object_id_str() instead.
193 0c60ce5a 2018-04-02 stsp */
194 f934cf2c 2018-02-12 stsp char *got_object_blob_id_str(struct got_blob_object*, char *, size_t);
195 0c60ce5a 2018-04-02 stsp
196 0c60ce5a 2018-04-02 stsp /*
197 0c60ce5a 2018-04-02 stsp * Get the length of header data at the beginning of the blob's read buffer.
198 0c60ce5a 2018-04-02 stsp * Note that header data is only present upon the first invocation of
199 0c60ce5a 2018-04-02 stsp * got_object_blob_read_block() after the blob is opened.
200 0c60ce5a 2018-04-02 stsp */
201 f934cf2c 2018-02-12 stsp size_t got_object_blob_get_hdrlen(struct got_blob_object *);
202 0c60ce5a 2018-04-02 stsp
203 0c60ce5a 2018-04-02 stsp /*
204 0c60ce5a 2018-04-02 stsp * Get a pointer to the blob's read buffer.
205 0c60ce5a 2018-04-02 stsp * The read buffer is filled by got_object_blob_read_block().
206 0c60ce5a 2018-04-02 stsp */
207 f934cf2c 2018-02-12 stsp const uint8_t *got_object_blob_get_read_buf(struct got_blob_object *);
208 0c60ce5a 2018-04-02 stsp
209 0c60ce5a 2018-04-02 stsp /*
210 0c60ce5a 2018-04-02 stsp * Read the next chunk of data from a blob, up to the blob's read buffer
211 0c60ce5a 2018-04-02 stsp * block size. The size_t output argument indicates how many bytes have
212 0c60ce5a 2018-04-02 stsp * been read into the blob's read buffer. Zero bytes will be reported if
213 0c60ce5a 2018-04-02 stsp * all data in the blob has been read.
214 0c60ce5a 2018-04-02 stsp */
215 eb651edf 2018-02-11 stsp const struct got_error *got_object_blob_read_block(size_t *,
216 eb651edf 2018-02-11 stsp struct got_blob_object *);
217 be6a1b5a 2018-06-11 stsp
218 35e9ba5d 2018-06-21 stsp /*
219 35e9ba5d 2018-06-21 stsp * Read the entire content of a blob and write it to the specified file.
220 84451b3e 2018-07-10 stsp * Flush and rewind the file as well. Indicate the amount of bytes
221 84451b3e 2018-07-10 stsp * written in the first size_t output argument, and the number of lines
222 84451b3e 2018-07-10 stsp * in the file in the second size_t output argument (NULL can be passed
223 84451b3e 2018-07-10 stsp * for either output argument).
224 35e9ba5d 2018-06-21 stsp */
225 84451b3e 2018-07-10 stsp const struct got_error *got_object_blob_dump_to_file(size_t *, size_t *,
226 84451b3e 2018-07-10 stsp FILE *, struct got_blob_object *);
227 35e9ba5d 2018-06-21 stsp
228 f4a881ce 2018-11-17 stsp /*
229 f4a881ce 2018-11-17 stsp * Attempt to open a tag object in a repository.
230 f4a881ce 2018-11-17 stsp * The provided object must be of type GOT_OBJ_TYPE_TAG.
231 f4a881ce 2018-11-17 stsp * The caller must dispose of the tree with got_object_tag_close().
232 f4a881ce 2018-11-17 stsp */
233 f4a881ce 2018-11-17 stsp const struct got_error *got_object_tag_open(struct got_tag_object **,
234 f4a881ce 2018-11-17 stsp struct got_repository *, struct got_object *);
235 f4a881ce 2018-11-17 stsp
236 f4a881ce 2018-11-17 stsp /* Dispose of a tag object. */
237 f4a881ce 2018-11-17 stsp void got_object_tag_close(struct got_tag_object *);
238 f4a881ce 2018-11-17 stsp
239 be6a1b5a 2018-06-11 stsp const struct got_error *
240 be6a1b5a 2018-06-11 stsp got_object_open_as_commit(struct got_commit_object **,
241 be6a1b5a 2018-06-11 stsp struct got_repository *, struct got_object_id *);
242 776d4d29 2018-06-17 stsp const struct got_error *
243 776d4d29 2018-06-17 stsp got_object_open_as_tree(struct got_tree_object **,
244 776d4d29 2018-06-17 stsp struct got_repository *, struct got_object_id *);
245 a19581a2 2018-06-21 stsp const struct got_error *
246 a19581a2 2018-06-21 stsp got_object_open_as_blob(struct got_blob_object **,
247 a19581a2 2018-06-21 stsp struct got_repository *, struct got_object_id *, size_t);
248 f4a881ce 2018-11-17 stsp const struct got_error *got_object_open_as_tag(struct got_tag_object **,
249 f4a881ce 2018-11-17 stsp struct got_repository *, struct got_object_id *);
250 be6a1b5a 2018-06-11 stsp
251 bff6ca00 2018-04-23 stsp const struct got_error *got_object_commit_add_parent(struct got_commit_object *,
252 bff6ca00 2018-04-23 stsp const char *);