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 dd88155e 2019-06-29 stsp void got_object_id_queue_free(struct got_object_id_queue *);
49 dbc6a6b6 2018-07-12 stsp
50 15a94983 2018-12-23 stsp /* Object types. */
51 dd88155e 2019-06-29 stsp #define GOT_OBJ_TYPE_ANY 0 /* wildcard value at run-time */
52 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_COMMIT 1
53 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_TREE 2
54 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_BLOB 3
55 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_TAG 4
56 f9a4270b 2017-12-03 stsp /* 5 is reserved */
57 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_OFFSET_DELTA 6
58 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_REF_DELTA 7
59 ab9a70b2 2017-11-06 stsp
60 8aa93786 2019-08-22 stsp /*
61 8aa93786 2019-08-22 stsp * Labels used in object data.
62 8aa93786 2019-08-22 stsp */
63 8aa93786 2019-08-22 stsp
64 8aa93786 2019-08-22 stsp #define GOT_OBJ_LABEL_COMMIT "commit"
65 8aa93786 2019-08-22 stsp #define GOT_OBJ_LABEL_TREE "tree"
66 8aa93786 2019-08-22 stsp #define GOT_OBJ_LABEL_BLOB "blob"
67 8aa93786 2019-08-22 stsp #define GOT_OBJ_LABEL_TAG "tag"
68 8aa93786 2019-08-22 stsp
69 8aa93786 2019-08-22 stsp #define GOT_COMMIT_LABEL_TREE "tree "
70 8aa93786 2019-08-22 stsp #define GOT_COMMIT_LABEL_PARENT "parent "
71 8aa93786 2019-08-22 stsp #define GOT_COMMIT_LABEL_AUTHOR "author "
72 8aa93786 2019-08-22 stsp #define GOT_COMMIT_LABEL_COMMITTER "committer "
73 8aa93786 2019-08-22 stsp
74 8aa93786 2019-08-22 stsp #define GOT_TAG_LABEL_OBJECT "object "
75 8aa93786 2019-08-22 stsp #define GOT_TAG_LABEL_TYPE "type "
76 8aa93786 2019-08-22 stsp #define GOT_TAG_LABEL_TAG "tag "
77 8aa93786 2019-08-22 stsp #define GOT_TAG_LABEL_TAGGER "tagger "
78 8aa93786 2019-08-22 stsp
79 ab9a70b2 2017-11-06 stsp struct got_repository;
80 ab9a70b2 2017-11-06 stsp
81 0c60ce5a 2018-04-02 stsp /*
82 0c60ce5a 2018-04-02 stsp * Obtain a string representation of an object ID. The output depends on
83 0c60ce5a 2018-04-02 stsp * the hash function used by the repository format (currently SHA1).
84 0c60ce5a 2018-04-02 stsp */
85 ef0981d5 2018-02-12 stsp const struct got_error *got_object_id_str(char **, struct got_object_id *);
86 0c60ce5a 2018-04-02 stsp
87 0c60ce5a 2018-04-02 stsp /*
88 0c60ce5a 2018-04-02 stsp * Compare two object IDs. Return value behaves like memcmp(3).
89 0c60ce5a 2018-04-02 stsp */
90 984e8a45 2018-11-05 stsp int got_object_id_cmp(const struct got_object_id *,
91 984e8a45 2018-11-05 stsp const struct got_object_id *);
92 0c60ce5a 2018-04-02 stsp
93 0c60ce5a 2018-04-02 stsp /*
94 0c60ce5a 2018-04-02 stsp * Created a newly allocated copy of an object ID.
95 0c60ce5a 2018-04-02 stsp * The caller should dispose of it with free(3).
96 0c60ce5a 2018-04-02 stsp */
97 8bf5b3c9 2018-03-17 stsp struct got_object_id *got_object_id_dup(struct got_object_id *);
98 0c60ce5a 2018-04-02 stsp
99 0c60ce5a 2018-04-02 stsp /*
100 27d434c2 2018-09-15 stsp * Get a newly allocated ID of the object which resides at the specified
101 27d434c2 2018-09-15 stsp * path in the tree of the specified commit.
102 27d434c2 2018-09-15 stsp * The caller should dispose of it with free(3).
103 27d434c2 2018-09-15 stsp */
104 6c34b1aa 2019-03-18 stsp const struct got_error *got_object_id_by_path(struct got_object_id **,
105 6c34b1aa 2019-03-18 stsp struct got_repository *, struct got_object_id *, const char *);
106 27d434c2 2018-09-15 stsp
107 27d434c2 2018-09-15 stsp /*
108 0c60ce5a 2018-04-02 stsp * Obtain the type of an object.
109 0c60ce5a 2018-04-02 stsp * Returns one of the GOT_OBJ_TYPE_x values (see above).
110 0c60ce5a 2018-04-02 stsp */
111 15a94983 2018-12-23 stsp const struct got_error *got_object_get_type(int *, struct got_repository *,
112 15a94983 2018-12-23 stsp struct got_object_id *);
113 0c60ce5a 2018-04-02 stsp
114 0c60ce5a 2018-04-02 stsp /*
115 15a94983 2018-12-23 stsp * Attempt to resolve the textual representation of an object ID
116 15a94983 2018-12-23 stsp * to the ID of an existing object in the repository.
117 15a94983 2018-12-23 stsp * The caller should dispose of the ID with free(3).
118 0c60ce5a 2018-04-02 stsp */
119 6c34b1aa 2019-03-18 stsp const struct got_error *got_object_resolve_id_str(struct got_object_id **,
120 6c34b1aa 2019-03-18 stsp struct got_repository *, const char *);
121 0c60ce5a 2018-04-02 stsp
122 0c60ce5a 2018-04-02 stsp /*
123 0c60ce5a 2018-04-02 stsp * Attempt to open a commit object in a repository.
124 0c60ce5a 2018-04-02 stsp * The caller must dispose of the commit with got_object_commit_close().
125 0c60ce5a 2018-04-02 stsp */
126 6c34b1aa 2019-03-18 stsp const struct got_error *got_object_open_as_commit(struct got_commit_object **,
127 15a94983 2018-12-23 stsp struct got_repository *, struct got_object_id *);
128 0c60ce5a 2018-04-02 stsp
129 0c60ce5a 2018-04-02 stsp /* Dispose of a commit object. */
130 d1cda826 2017-11-06 stsp void got_object_commit_close(struct got_commit_object *);
131 0c60ce5a 2018-04-02 stsp
132 45d799e2 2018-12-23 stsp /* Obtain the ID of the tree created in a commit. */
133 45d799e2 2018-12-23 stsp struct got_object_id *got_object_commit_get_tree_id(struct got_commit_object *);
134 45d799e2 2018-12-23 stsp
135 45d799e2 2018-12-23 stsp /* Obtain the number of parent commits of a commit. */
136 45d799e2 2018-12-23 stsp int got_object_commit_get_nparents(struct got_commit_object *);
137 45d799e2 2018-12-23 stsp
138 45d799e2 2018-12-23 stsp /* Obtain the list of parent commits of a commit. */
139 45d799e2 2018-12-23 stsp const struct got_object_id_queue *got_object_commit_get_parent_ids(
140 45d799e2 2018-12-23 stsp struct got_commit_object *);
141 45d799e2 2018-12-23 stsp
142 45d799e2 2018-12-23 stsp /* Get the author's name and email address. */
143 45d799e2 2018-12-23 stsp const char *got_object_commit_get_author(struct got_commit_object *);
144 45d799e2 2018-12-23 stsp
145 2df4e4ff 2018-12-23 stsp /* Get an author's commit timestamp in UTC. */
146 45d799e2 2018-12-23 stsp time_t got_object_commit_get_author_time(struct got_commit_object *);
147 45d799e2 2018-12-23 stsp
148 45d799e2 2018-12-23 stsp /* Get an author's timezone offset. */
149 45d799e2 2018-12-23 stsp time_t got_object_commit_get_author_gmtoff(struct got_commit_object *);
150 45d799e2 2018-12-23 stsp
151 45d799e2 2018-12-23 stsp /* Get the committer's name and email address. */
152 45d799e2 2018-12-23 stsp const char *got_object_commit_get_committer(struct got_commit_object *);
153 45d799e2 2018-12-23 stsp
154 450eaa8b 2018-12-23 stsp /* Get a committer's commit timestamp in UTC. */
155 45d799e2 2018-12-23 stsp time_t got_object_commit_get_committer_time(struct got_commit_object *);
156 45d799e2 2018-12-23 stsp
157 450eaa8b 2018-12-23 stsp /* Get a committer's timezone offset. */
158 45d799e2 2018-12-23 stsp time_t got_object_commit_get_committer_gmtoff(struct got_commit_object *);
159 45d799e2 2018-12-23 stsp
160 24ea5512 2019-08-22 stsp /*
161 24ea5512 2019-08-22 stsp * Get the commit log message.
162 24ea5512 2019-08-22 stsp * PGP-signatures contained in the log message will be stripped.
163 24ea5512 2019-08-22 stsp * The caller must dispose of it with free(3).
164 24ea5512 2019-08-22 stsp */
165 5943eee2 2019-08-13 stsp const struct got_error *got_object_commit_get_logmsg(char **,
166 5943eee2 2019-08-13 stsp struct got_commit_object *);
167 45d799e2 2018-12-23 stsp
168 24ea5512 2019-08-22 stsp /* Get the raw commit log message.*/
169 24ea5512 2019-08-22 stsp const char *got_object_commit_get_logmsg_raw(struct got_commit_object *);
170 24ea5512 2019-08-22 stsp
171 0c60ce5a 2018-04-02 stsp /*
172 0c60ce5a 2018-04-02 stsp * Attempt to open a tree object in a repository.
173 0c60ce5a 2018-04-02 stsp * The caller must dispose of the tree with got_object_tree_close().
174 0c60ce5a 2018-04-02 stsp */
175 6c34b1aa 2019-03-18 stsp const struct got_error *got_object_open_as_tree(struct got_tree_object **,
176 15a94983 2018-12-23 stsp struct got_repository *, struct got_object_id *);
177 0c60ce5a 2018-04-02 stsp
178 0c60ce5a 2018-04-02 stsp /* Dispose of a tree object. */
179 0ffeb3c2 2017-11-26 stsp void got_object_tree_close(struct got_tree_object *);
180 0c60ce5a 2018-04-02 stsp
181 883f0469 2018-06-23 stsp /* Get the entries of a tree object. */
182 883f0469 2018-06-23 stsp const struct got_tree_entries *got_object_tree_get_entries(
183 883f0469 2018-06-23 stsp struct got_tree_object *);
184 883f0469 2018-06-23 stsp
185 a129376b 2019-03-28 stsp /* Find a particular entry in a tree. */
186 a129376b 2019-03-28 stsp const struct got_tree_entry *got_object_tree_find_entry(
187 a129376b 2019-03-28 stsp struct got_tree_object *, const char *);
188 a129376b 2019-03-28 stsp
189 63c5ca5d 2019-08-24 stsp /* Return non-zero if the specified tree entry is a Git submodule. */
190 63c5ca5d 2019-08-24 stsp int got_object_tree_entry_is_submodule(const struct got_tree_entry *);
191 63c5ca5d 2019-08-24 stsp
192 0c60ce5a 2018-04-02 stsp /*
193 07862c20 2018-09-15 stsp * Compare two trees and indicate whether the entry at the specified path
194 31cedeaf 2018-09-15 stsp * differs between them. The path must not be the root path "/"; the function
195 31cedeaf 2018-09-15 stsp * got_object_id_cmp() should be used instead to compare the tree roots.
196 07862c20 2018-09-15 stsp */
197 07862c20 2018-09-15 stsp const struct got_error *got_object_tree_path_changed(int *,
198 07862c20 2018-09-15 stsp struct got_tree_object *, struct got_tree_object *, const char *,
199 07862c20 2018-09-15 stsp struct got_repository *);
200 07862c20 2018-09-15 stsp
201 07862c20 2018-09-15 stsp /*
202 0c60ce5a 2018-04-02 stsp * Attempt to open a blob object in a repository.
203 0c60ce5a 2018-04-02 stsp * The size_t argument specifies the block size of an associated read buffer.
204 0c60ce5a 2018-04-02 stsp * The caller must dispose of the blob with got_object_blob_close().
205 0c60ce5a 2018-04-02 stsp */
206 6c34b1aa 2019-03-18 stsp const struct got_error *got_object_open_as_blob(struct got_blob_object **,
207 15a94983 2018-12-23 stsp struct got_repository *, struct got_object_id *, size_t);
208 0c60ce5a 2018-04-02 stsp
209 0c60ce5a 2018-04-02 stsp /* Dispose of a blob object. */
210 fb43ecf1 2019-02-11 stsp const struct got_error *got_object_blob_close(struct got_blob_object *);
211 0c60ce5a 2018-04-02 stsp
212 0c60ce5a 2018-04-02 stsp /*
213 0c60ce5a 2018-04-02 stsp * Get the length of header data at the beginning of the blob's read buffer.
214 0c60ce5a 2018-04-02 stsp * Note that header data is only present upon the first invocation of
215 0c60ce5a 2018-04-02 stsp * got_object_blob_read_block() after the blob is opened.
216 0c60ce5a 2018-04-02 stsp */
217 f934cf2c 2018-02-12 stsp size_t got_object_blob_get_hdrlen(struct got_blob_object *);
218 0c60ce5a 2018-04-02 stsp
219 0c60ce5a 2018-04-02 stsp /*
220 0c60ce5a 2018-04-02 stsp * Get a pointer to the blob's read buffer.
221 0c60ce5a 2018-04-02 stsp * The read buffer is filled by got_object_blob_read_block().
222 0c60ce5a 2018-04-02 stsp */
223 f934cf2c 2018-02-12 stsp const uint8_t *got_object_blob_get_read_buf(struct got_blob_object *);
224 0c60ce5a 2018-04-02 stsp
225 0c60ce5a 2018-04-02 stsp /*
226 0c60ce5a 2018-04-02 stsp * Read the next chunk of data from a blob, up to the blob's read buffer
227 0c60ce5a 2018-04-02 stsp * block size. The size_t output argument indicates how many bytes have
228 0c60ce5a 2018-04-02 stsp * been read into the blob's read buffer. Zero bytes will be reported if
229 0c60ce5a 2018-04-02 stsp * all data in the blob has been read.
230 0c60ce5a 2018-04-02 stsp */
231 eb651edf 2018-02-11 stsp const struct got_error *got_object_blob_read_block(size_t *,
232 eb651edf 2018-02-11 stsp struct got_blob_object *);
233 be6a1b5a 2018-06-11 stsp
234 35e9ba5d 2018-06-21 stsp /*
235 35e9ba5d 2018-06-21 stsp * Read the entire content of a blob and write it to the specified file.
236 84451b3e 2018-07-10 stsp * Flush and rewind the file as well. Indicate the amount of bytes
237 6c4c42e0 2019-06-24 stsp * written in the size_t output argument, and the number of lines in the
238 0f6650ff 2019-08-14 stsp * file in the int argument, and line offsets in the off_t argument
239 6c4c42e0 2019-06-24 stsp * (NULL can be passed for any 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 6c4c42e0 2019-06-24 stsp off_t **, 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 01073a5d 2019-08-22 stsp * The caller must dispose of the tree with got_tag_object_close().
247 f4a881ce 2018-11-17 stsp */
248 15a94983 2018-12-23 stsp const struct got_error *got_object_open_as_tag(struct got_tag_object **,
249 15a94983 2018-12-23 stsp struct got_repository *, struct got_object_id *);
250 f4a881ce 2018-11-17 stsp
251 f4a881ce 2018-11-17 stsp /* Dispose of a tag object. */
252 f4a881ce 2018-11-17 stsp void got_object_tag_close(struct got_tag_object *);
253 f4a881ce 2018-11-17 stsp
254 d24820bf 2019-08-11 stsp /* Get the name of a tag. */
255 d24820bf 2019-08-11 stsp const char *got_object_tag_get_name(struct got_tag_object *);
256 d24820bf 2019-08-11 stsp
257 0bd18d37 2019-02-01 stsp /* Get type of the object a tag points to. */
258 0bd18d37 2019-02-01 stsp int got_object_tag_get_object_type(struct got_tag_object *);
259 0bd18d37 2019-02-01 stsp
260 0bd18d37 2019-02-01 stsp /*
261 0bd18d37 2019-02-01 stsp * Get ID of the object a tag points to.
262 0bd18d37 2019-02-01 stsp * This must not be freed by the caller. Use got_object_id_dup() if needed.
263 0bd18d37 2019-02-01 stsp */
264 0bd18d37 2019-02-01 stsp struct got_object_id *got_object_tag_get_object_id(struct got_tag_object *);
265 0bd18d37 2019-02-01 stsp
266 01073a5d 2019-08-22 stsp
267 01073a5d 2019-08-22 stsp /* Get the timestamp of the tag. */
268 01073a5d 2019-08-22 stsp time_t got_object_tag_get_tagger_time(struct got_tag_object *);
269 01073a5d 2019-08-22 stsp
270 01073a5d 2019-08-22 stsp /* Get the tag's timestamp's GMT offset. */
271 01073a5d 2019-08-22 stsp time_t got_object_tag_get_tagger_gmtoff(struct got_tag_object *);
272 01073a5d 2019-08-22 stsp
273 01073a5d 2019-08-22 stsp /* Get the author of the tag. */
274 01073a5d 2019-08-22 stsp const char *got_object_tag_get_tagger(struct got_tag_object *);
275 01073a5d 2019-08-22 stsp
276 01073a5d 2019-08-22 stsp /* Get the tag message associated with the tag. */
277 01073a5d 2019-08-22 stsp const char *got_object_tag_get_message(struct got_tag_object *);
278 01073a5d 2019-08-22 stsp
279 bff6ca00 2018-04-23 stsp const struct got_error *got_object_commit_add_parent(struct got_commit_object *,
280 bff6ca00 2018-04-23 stsp const char *);
281 8e7bd50a 2019-08-22 stsp
282 8e7bd50a 2019-08-22 stsp /* Create a new tag object in the repository. */
283 8e7bd50a 2019-08-22 stsp const struct got_error *got_object_tag_create(struct got_object_id **,
284 8e7bd50a 2019-08-22 stsp const char *, struct got_object_id *, const char *,
285 8e7bd50a 2019-08-22 stsp time_t, const char *, struct got_repository *);