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 45d799e2 2018-12-23 stsp struct got_commit_object;
23 d1cda826 2017-11-06 stsp
24 0ffeb3c2 2017-11-26 stsp struct got_tree_entry {
25 0ffeb3c2 2017-11-26 stsp SIMPLEQ_ENTRY(got_tree_entry) entry;
26 0ffeb3c2 2017-11-26 stsp mode_t mode;
27 0ffeb3c2 2017-11-26 stsp char *name;
28 59ece79d 2018-02-12 stsp struct got_object_id *id;
29 0ffeb3c2 2017-11-26 stsp };
30 0ffeb3c2 2017-11-26 stsp
31 883f0469 2018-06-23 stsp SIMPLEQ_HEAD(got_tree_entries_queue, got_tree_entry);
32 f6be5c30 2018-06-22 stsp
33 883f0469 2018-06-23 stsp struct got_tree_entries {
34 883f0469 2018-06-23 stsp int nentries;
35 883f0469 2018-06-23 stsp struct got_tree_entries_queue head;
36 d1cda826 2017-11-06 stsp };
37 d1cda826 2017-11-06 stsp
38 79f35eb3 2018-06-11 stsp struct got_object_qid {
39 79f35eb3 2018-06-11 stsp SIMPLEQ_ENTRY(got_object_qid) entry;
40 59ece79d 2018-02-12 stsp struct got_object_id *id;
41 d1cda826 2017-11-06 stsp };
42 d1cda826 2017-11-06 stsp
43 79f35eb3 2018-06-11 stsp SIMPLEQ_HEAD(got_object_id_queue, got_object_qid);
44 b43fbaa0 2018-06-11 stsp
45 dbc6a6b6 2018-07-12 stsp const struct got_error *got_object_qid_alloc(struct got_object_qid **,
46 dbc6a6b6 2018-07-12 stsp struct got_object_id *);
47 dbc6a6b6 2018-07-12 stsp void got_object_qid_free(struct got_object_qid *);
48 dbc6a6b6 2018-07-12 stsp
49 0c60ce5a 2018-04-02 stsp /* A generic object. Used as a handle which holds an ID and an object type. */
50 eef6493a 2018-01-19 stsp struct got_object;
51 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_COMMIT 1
52 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_TREE 2
53 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_BLOB 3
54 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_TAG 4
55 f9a4270b 2017-12-03 stsp /* 5 is reserved */
56 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_OFFSET_DELTA 6
57 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_REF_DELTA 7
58 ab9a70b2 2017-11-06 stsp
59 ab9a70b2 2017-11-06 stsp struct got_repository;
60 ab9a70b2 2017-11-06 stsp
61 0c60ce5a 2018-04-02 stsp /*
62 0c60ce5a 2018-04-02 stsp * Obtain a string representation of an object ID. The output depends on
63 0c60ce5a 2018-04-02 stsp * the hash function used by the repository format (currently SHA1).
64 0c60ce5a 2018-04-02 stsp */
65 ef0981d5 2018-02-12 stsp const struct got_error *got_object_id_str(char **, struct got_object_id *);
66 0c60ce5a 2018-04-02 stsp
67 0c60ce5a 2018-04-02 stsp /*
68 0c60ce5a 2018-04-02 stsp * Compare two object IDs. Return value behaves like memcmp(3).
69 0c60ce5a 2018-04-02 stsp */
70 984e8a45 2018-11-05 stsp int got_object_id_cmp(const struct got_object_id *,
71 984e8a45 2018-11-05 stsp const struct got_object_id *);
72 0c60ce5a 2018-04-02 stsp
73 0c60ce5a 2018-04-02 stsp /*
74 0c60ce5a 2018-04-02 stsp * Created a newly allocated copy of an object ID.
75 0c60ce5a 2018-04-02 stsp * The caller should dispose of it with free(3).
76 0c60ce5a 2018-04-02 stsp */
77 8bf5b3c9 2018-03-17 stsp struct got_object_id *got_object_id_dup(struct got_object_id *);
78 0c60ce5a 2018-04-02 stsp
79 0c60ce5a 2018-04-02 stsp /*
80 0c60ce5a 2018-04-02 stsp * Get a newly allocated copy of an object's ID.
81 6402fb3c 2018-09-15 stsp * The caller must treat the ID as read-only and must not call free(3) on it.
82 6402fb3c 2018-09-15 stsp * Use got_object_id_dup() to get a writable copy.
83 0c60ce5a 2018-04-02 stsp */
84 3235492e 2018-04-01 stsp struct got_object_id *got_object_get_id(struct got_object *);
85 0c60ce5a 2018-04-02 stsp
86 0c60ce5a 2018-04-02 stsp /*
87 bacc9935 2018-05-20 stsp * Get a newly allocated copy of an object's ID string.
88 bacc9935 2018-05-20 stsp * The caller should dispose of it with free(3).
89 bacc9935 2018-05-20 stsp */
90 bacc9935 2018-05-20 stsp const struct got_error *got_object_get_id_str(char **, struct got_object *);
91 bacc9935 2018-05-20 stsp
92 bacc9935 2018-05-20 stsp /*
93 27d434c2 2018-09-15 stsp * Get a newly allocated ID of the object which resides at the specified
94 27d434c2 2018-09-15 stsp * path in the tree of the specified commit.
95 27d434c2 2018-09-15 stsp * The caller should dispose of it with free(3).
96 27d434c2 2018-09-15 stsp */
97 27d434c2 2018-09-15 stsp const struct got_error *
98 27d434c2 2018-09-15 stsp got_object_id_by_path(struct got_object_id **, struct got_repository *,
99 27d434c2 2018-09-15 stsp struct got_object_id *, const char *);
100 27d434c2 2018-09-15 stsp
101 27d434c2 2018-09-15 stsp /*
102 0c60ce5a 2018-04-02 stsp * Obtain the type of an object.
103 0c60ce5a 2018-04-02 stsp * Returns one of the GOT_OBJ_TYPE_x values (see above).
104 0c60ce5a 2018-04-02 stsp */
105 b107e67f 2018-01-19 stsp int got_object_get_type(struct got_object *);
106 0c60ce5a 2018-04-02 stsp
107 0c60ce5a 2018-04-02 stsp /*
108 0c60ce5a 2018-04-02 stsp * Attempt to open the object in a repository with the provided ID.
109 0c60ce5a 2018-04-02 stsp * Caller must dispose of it with got_object_close().
110 0c60ce5a 2018-04-02 stsp */
111 ab9a70b2 2017-11-06 stsp const struct got_error *got_object_open(struct got_object **,
112 ab9a70b2 2017-11-06 stsp struct got_repository *, struct got_object_id *);
113 0c60ce5a 2018-04-02 stsp
114 0c60ce5a 2018-04-02 stsp /*
115 0c60ce5a 2018-04-02 stsp * Attempt to map the provided ID string to an object ID and then
116 0c60ce5a 2018-04-02 stsp * attempt to open the object in a repository with this ID.
117 0c60ce5a 2018-04-02 stsp * The form of an ID string depends on the hash function used by the
118 0c60ce5a 2018-04-02 stsp * repository format (currently SHA1).
119 0c60ce5a 2018-04-02 stsp * Caller must dispose of the object with got_object_close().
120 0c60ce5a 2018-04-02 stsp */
121 6dfa2fd3 2018-02-12 stsp const struct got_error *got_object_open_by_id_str(struct got_object **,
122 0c60ce5a 2018-04-02 stsp struct got_repository *, const char *);
123 0c60ce5a 2018-04-02 stsp
124 0c60ce5a 2018-04-02 stsp /* Dispose of an object. */
125 ab9a70b2 2017-11-06 stsp void got_object_close(struct got_object *);
126 0c60ce5a 2018-04-02 stsp
127 0c60ce5a 2018-04-02 stsp /*
128 0c60ce5a 2018-04-02 stsp * Attempt to open a commit object in a repository.
129 0c60ce5a 2018-04-02 stsp * The provided object must be of type GOT_OBJ_TYPE_COMMIT.
130 0c60ce5a 2018-04-02 stsp * The caller must dispose of the commit with got_object_commit_close().
131 0c60ce5a 2018-04-02 stsp */
132 d1cda826 2017-11-06 stsp const struct got_error *got_object_commit_open(struct got_commit_object **,
133 d1cda826 2017-11-06 stsp struct got_repository *, struct got_object *);
134 0c60ce5a 2018-04-02 stsp
135 0c60ce5a 2018-04-02 stsp /* Dispose of a commit object. */
136 d1cda826 2017-11-06 stsp void got_object_commit_close(struct got_commit_object *);
137 0c60ce5a 2018-04-02 stsp
138 45d799e2 2018-12-23 stsp /* Obtain the ID of the tree created in a commit. */
139 45d799e2 2018-12-23 stsp struct got_object_id *got_object_commit_get_tree_id(struct got_commit_object *);
140 45d799e2 2018-12-23 stsp
141 45d799e2 2018-12-23 stsp /* Obtain the number of parent commits of a commit. */
142 45d799e2 2018-12-23 stsp int got_object_commit_get_nparents(struct got_commit_object *);
143 45d799e2 2018-12-23 stsp
144 45d799e2 2018-12-23 stsp /* Obtain the list of parent commits of a commit. */
145 45d799e2 2018-12-23 stsp const struct got_object_id_queue *got_object_commit_get_parent_ids(
146 45d799e2 2018-12-23 stsp struct got_commit_object *);
147 45d799e2 2018-12-23 stsp
148 45d799e2 2018-12-23 stsp /* Get the author's name and email address. */
149 45d799e2 2018-12-23 stsp const char *got_object_commit_get_author(struct got_commit_object *);
150 45d799e2 2018-12-23 stsp
151 2df4e4ff 2018-12-23 stsp /* Get an author's commit timestamp in UTC. */
152 45d799e2 2018-12-23 stsp time_t got_object_commit_get_author_time(struct got_commit_object *);
153 45d799e2 2018-12-23 stsp
154 45d799e2 2018-12-23 stsp /* Get an author's timezone offset. */
155 45d799e2 2018-12-23 stsp time_t got_object_commit_get_author_gmtoff(struct got_commit_object *);
156 45d799e2 2018-12-23 stsp
157 45d799e2 2018-12-23 stsp /* Get the committer's name and email address. */
158 45d799e2 2018-12-23 stsp const char *got_object_commit_get_committer(struct got_commit_object *);
159 45d799e2 2018-12-23 stsp
160 2df4e4ff 2018-12-23 stsp /* Get an committer's commit timestamp in UTC. */
161 45d799e2 2018-12-23 stsp time_t got_object_commit_get_committer_time(struct got_commit_object *);
162 45d799e2 2018-12-23 stsp
163 45d799e2 2018-12-23 stsp /* Get an committer's timezone offset. */
164 45d799e2 2018-12-23 stsp time_t got_object_commit_get_committer_gmtoff(struct got_commit_object *);
165 45d799e2 2018-12-23 stsp
166 45d799e2 2018-12-23 stsp /* Get the commit log message. */
167 45d799e2 2018-12-23 stsp const char *got_object_commit_get_logmsg(struct got_commit_object *);
168 45d799e2 2018-12-23 stsp
169 0c60ce5a 2018-04-02 stsp /*
170 0c60ce5a 2018-04-02 stsp * Attempt to open a tree object in a repository.
171 0c60ce5a 2018-04-02 stsp * The provided object must be of type GOT_OBJ_TYPE_TREE.
172 0c60ce5a 2018-04-02 stsp * The caller must dispose of the tree with got_object_tree_close().
173 0c60ce5a 2018-04-02 stsp */
174 0ffeb3c2 2017-11-26 stsp const struct got_error *got_object_tree_open(struct got_tree_object **,
175 0ffeb3c2 2017-11-26 stsp struct got_repository *, struct got_object *);
176 0c60ce5a 2018-04-02 stsp
177 0c60ce5a 2018-04-02 stsp /* Dispose of a tree object. */
178 0ffeb3c2 2017-11-26 stsp void got_object_tree_close(struct got_tree_object *);
179 0c60ce5a 2018-04-02 stsp
180 883f0469 2018-06-23 stsp /* Get the entries of a tree object. */
181 883f0469 2018-06-23 stsp const struct got_tree_entries *got_object_tree_get_entries(
182 883f0469 2018-06-23 stsp struct got_tree_object *);
183 883f0469 2018-06-23 stsp
184 0c60ce5a 2018-04-02 stsp /*
185 07862c20 2018-09-15 stsp * Compare two trees and indicate whether the entry at the specified path
186 31cedeaf 2018-09-15 stsp * differs between them. The path must not be the root path "/"; the function
187 31cedeaf 2018-09-15 stsp * got_object_id_cmp() should be used instead to compare the tree roots.
188 07862c20 2018-09-15 stsp */
189 07862c20 2018-09-15 stsp const struct got_error *got_object_tree_path_changed(int *,
190 07862c20 2018-09-15 stsp struct got_tree_object *, struct got_tree_object *, const char *,
191 07862c20 2018-09-15 stsp struct got_repository *);
192 07862c20 2018-09-15 stsp
193 07862c20 2018-09-15 stsp /*
194 0c60ce5a 2018-04-02 stsp * Attempt to open a blob object in a repository.
195 0c60ce5a 2018-04-02 stsp * The provided object must be of type GOT_OBJ_TYPE_BLOB.
196 0c60ce5a 2018-04-02 stsp * The size_t argument specifies the block size of an associated read buffer.
197 0c60ce5a 2018-04-02 stsp * The caller must dispose of the blob with got_object_blob_close().
198 0c60ce5a 2018-04-02 stsp */
199 68482ea3 2017-11-27 stsp const struct got_error *got_object_blob_open(struct got_blob_object **,
200 68482ea3 2017-11-27 stsp struct got_repository *, struct got_object *, size_t);
201 0c60ce5a 2018-04-02 stsp
202 0c60ce5a 2018-04-02 stsp /* Dispose of a blob object. */
203 68482ea3 2017-11-27 stsp void got_object_blob_close(struct got_blob_object *);
204 0c60ce5a 2018-04-02 stsp
205 0c60ce5a 2018-04-02 stsp /*
206 0c60ce5a 2018-04-02 stsp * Write the string representation of the object ID of a blob to a buffer.
207 0c60ce5a 2018-04-02 stsp * The size_t argument speficies the size of the buffer. In the current
208 0c60ce5a 2018-04-02 stsp * implementation, it must be at least SHA1_DIGEST_STRING_LENGTH bytes.
209 0c60ce5a 2018-04-02 stsp * XXX This is a bad API, use got_object_id_str() instead.
210 0c60ce5a 2018-04-02 stsp */
211 f934cf2c 2018-02-12 stsp char *got_object_blob_id_str(struct got_blob_object*, char *, size_t);
212 0c60ce5a 2018-04-02 stsp
213 0c60ce5a 2018-04-02 stsp /*
214 0c60ce5a 2018-04-02 stsp * Get the length of header data at the beginning of the blob's read buffer.
215 0c60ce5a 2018-04-02 stsp * Note that header data is only present upon the first invocation of
216 0c60ce5a 2018-04-02 stsp * got_object_blob_read_block() after the blob is opened.
217 0c60ce5a 2018-04-02 stsp */
218 f934cf2c 2018-02-12 stsp size_t got_object_blob_get_hdrlen(struct got_blob_object *);
219 0c60ce5a 2018-04-02 stsp
220 0c60ce5a 2018-04-02 stsp /*
221 0c60ce5a 2018-04-02 stsp * Get a pointer to the blob's read buffer.
222 0c60ce5a 2018-04-02 stsp * The read buffer is filled by got_object_blob_read_block().
223 0c60ce5a 2018-04-02 stsp */
224 f934cf2c 2018-02-12 stsp const uint8_t *got_object_blob_get_read_buf(struct got_blob_object *);
225 0c60ce5a 2018-04-02 stsp
226 0c60ce5a 2018-04-02 stsp /*
227 0c60ce5a 2018-04-02 stsp * Read the next chunk of data from a blob, up to the blob's read buffer
228 0c60ce5a 2018-04-02 stsp * block size. The size_t output argument indicates how many bytes have
229 0c60ce5a 2018-04-02 stsp * been read into the blob's read buffer. Zero bytes will be reported if
230 0c60ce5a 2018-04-02 stsp * all data in the blob has been read.
231 0c60ce5a 2018-04-02 stsp */
232 eb651edf 2018-02-11 stsp const struct got_error *got_object_blob_read_block(size_t *,
233 eb651edf 2018-02-11 stsp struct got_blob_object *);
234 be6a1b5a 2018-06-11 stsp
235 35e9ba5d 2018-06-21 stsp /*
236 35e9ba5d 2018-06-21 stsp * Read the entire content of a blob and write it to the specified file.
237 84451b3e 2018-07-10 stsp * Flush and rewind the file as well. Indicate the amount of bytes
238 6fcac457 2018-11-19 stsp * written in the size_t output argument, and the number of lines in
239 6fcac457 2018-11-19 stsp * the file in int argument (NULL can be passed for either output argument).
240 35e9ba5d 2018-06-21 stsp */
241 6fcac457 2018-11-19 stsp const struct got_error *got_object_blob_dump_to_file(size_t *, int *,
242 84451b3e 2018-07-10 stsp FILE *, struct got_blob_object *);
243 35e9ba5d 2018-06-21 stsp
244 f4a881ce 2018-11-17 stsp /*
245 f4a881ce 2018-11-17 stsp * Attempt to open a tag object in a repository.
246 f4a881ce 2018-11-17 stsp * The provided object must be of type GOT_OBJ_TYPE_TAG.
247 f4a881ce 2018-11-17 stsp * The caller must dispose of the tree with got_object_tag_close().
248 f4a881ce 2018-11-17 stsp */
249 f4a881ce 2018-11-17 stsp const struct got_error *got_object_tag_open(struct got_tag_object **,
250 f4a881ce 2018-11-17 stsp struct got_repository *, struct got_object *);
251 f4a881ce 2018-11-17 stsp
252 f4a881ce 2018-11-17 stsp /* Dispose of a tag object. */
253 f4a881ce 2018-11-17 stsp void got_object_tag_close(struct got_tag_object *);
254 f4a881ce 2018-11-17 stsp
255 be6a1b5a 2018-06-11 stsp const struct got_error *
256 be6a1b5a 2018-06-11 stsp got_object_open_as_commit(struct got_commit_object **,
257 be6a1b5a 2018-06-11 stsp struct got_repository *, struct got_object_id *);
258 776d4d29 2018-06-17 stsp const struct got_error *
259 776d4d29 2018-06-17 stsp got_object_open_as_tree(struct got_tree_object **,
260 776d4d29 2018-06-17 stsp struct got_repository *, struct got_object_id *);
261 a19581a2 2018-06-21 stsp const struct got_error *
262 a19581a2 2018-06-21 stsp got_object_open_as_blob(struct got_blob_object **,
263 a19581a2 2018-06-21 stsp struct got_repository *, struct got_object_id *, size_t);
264 f4a881ce 2018-11-17 stsp const struct got_error *got_object_open_as_tag(struct got_tag_object **,
265 f4a881ce 2018-11-17 stsp struct got_repository *, struct got_object_id *);
266 be6a1b5a 2018-06-11 stsp
267 bff6ca00 2018-04-23 stsp const struct got_error *got_object_commit_add_parent(struct got_commit_object *,
268 bff6ca00 2018-04-23 stsp const char *);