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