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 15a94983 2018-12-23 stsp /* Object types. */
50 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_COMMIT 1
51 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_TREE 2
52 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_BLOB 3
53 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_TAG 4
54 f9a4270b 2017-12-03 stsp /* 5 is reserved */
55 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_OFFSET_DELTA 6
56 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_REF_DELTA 7
57 ab9a70b2 2017-11-06 stsp
58 ab9a70b2 2017-11-06 stsp struct got_repository;
59 ab9a70b2 2017-11-06 stsp
60 0c60ce5a 2018-04-02 stsp /*
61 0c60ce5a 2018-04-02 stsp * Obtain a string representation of an object ID. The output depends on
62 0c60ce5a 2018-04-02 stsp * the hash function used by the repository format (currently SHA1).
63 0c60ce5a 2018-04-02 stsp */
64 ef0981d5 2018-02-12 stsp const struct got_error *got_object_id_str(char **, struct got_object_id *);
65 0c60ce5a 2018-04-02 stsp
66 0c60ce5a 2018-04-02 stsp /*
67 0c60ce5a 2018-04-02 stsp * Compare two object IDs. Return value behaves like memcmp(3).
68 0c60ce5a 2018-04-02 stsp */
69 984e8a45 2018-11-05 stsp int got_object_id_cmp(const struct got_object_id *,
70 984e8a45 2018-11-05 stsp const struct got_object_id *);
71 0c60ce5a 2018-04-02 stsp
72 0c60ce5a 2018-04-02 stsp /*
73 0c60ce5a 2018-04-02 stsp * Created a newly allocated copy of an object ID.
74 0c60ce5a 2018-04-02 stsp * The caller should dispose of it with free(3).
75 0c60ce5a 2018-04-02 stsp */
76 8bf5b3c9 2018-03-17 stsp struct got_object_id *got_object_id_dup(struct got_object_id *);
77 0c60ce5a 2018-04-02 stsp
78 0c60ce5a 2018-04-02 stsp /*
79 27d434c2 2018-09-15 stsp * Get a newly allocated ID of the object which resides at the specified
80 27d434c2 2018-09-15 stsp * path in the tree of the specified commit.
81 27d434c2 2018-09-15 stsp * The caller should dispose of it with free(3).
82 27d434c2 2018-09-15 stsp */
83 27d434c2 2018-09-15 stsp const struct got_error *
84 27d434c2 2018-09-15 stsp got_object_id_by_path(struct got_object_id **, struct got_repository *,
85 27d434c2 2018-09-15 stsp struct got_object_id *, const char *);
86 27d434c2 2018-09-15 stsp
87 27d434c2 2018-09-15 stsp /*
88 0c60ce5a 2018-04-02 stsp * Obtain the type of an object.
89 0c60ce5a 2018-04-02 stsp * Returns one of the GOT_OBJ_TYPE_x values (see above).
90 0c60ce5a 2018-04-02 stsp */
91 15a94983 2018-12-23 stsp const struct got_error *got_object_get_type(int *, struct got_repository *,
92 15a94983 2018-12-23 stsp struct got_object_id *);
93 0c60ce5a 2018-04-02 stsp
94 0c60ce5a 2018-04-02 stsp /*
95 15a94983 2018-12-23 stsp * Attempt to resolve the textual representation of an object ID
96 15a94983 2018-12-23 stsp * to the ID of an existing object in the repository.
97 15a94983 2018-12-23 stsp * The caller should dispose of the ID with free(3).
98 0c60ce5a 2018-04-02 stsp */
99 15a94983 2018-12-23 stsp const struct got_error *
100 15a94983 2018-12-23 stsp got_object_resolve_id_str(struct got_object_id **, struct got_repository *,
101 15a94983 2018-12-23 stsp const char *);
102 0c60ce5a 2018-04-02 stsp
103 0c60ce5a 2018-04-02 stsp /*
104 0c60ce5a 2018-04-02 stsp * Attempt to open a commit object in a repository.
105 0c60ce5a 2018-04-02 stsp * The caller must dispose of the commit with got_object_commit_close().
106 0c60ce5a 2018-04-02 stsp */
107 15a94983 2018-12-23 stsp const struct got_error *
108 15a94983 2018-12-23 stsp got_object_open_as_commit(struct got_commit_object **,
109 15a94983 2018-12-23 stsp struct got_repository *, struct got_object_id *);
110 0c60ce5a 2018-04-02 stsp
111 0c60ce5a 2018-04-02 stsp /* Dispose of a commit object. */
112 d1cda826 2017-11-06 stsp void got_object_commit_close(struct got_commit_object *);
113 0c60ce5a 2018-04-02 stsp
114 45d799e2 2018-12-23 stsp /* Obtain the ID of the tree created in a commit. */
115 45d799e2 2018-12-23 stsp struct got_object_id *got_object_commit_get_tree_id(struct got_commit_object *);
116 45d799e2 2018-12-23 stsp
117 45d799e2 2018-12-23 stsp /* Obtain the number of parent commits of a commit. */
118 45d799e2 2018-12-23 stsp int got_object_commit_get_nparents(struct got_commit_object *);
119 45d799e2 2018-12-23 stsp
120 45d799e2 2018-12-23 stsp /* Obtain the list of parent commits of a commit. */
121 45d799e2 2018-12-23 stsp const struct got_object_id_queue *got_object_commit_get_parent_ids(
122 45d799e2 2018-12-23 stsp struct got_commit_object *);
123 45d799e2 2018-12-23 stsp
124 45d799e2 2018-12-23 stsp /* Get the author's name and email address. */
125 45d799e2 2018-12-23 stsp const char *got_object_commit_get_author(struct got_commit_object *);
126 45d799e2 2018-12-23 stsp
127 2df4e4ff 2018-12-23 stsp /* Get an author's commit timestamp in UTC. */
128 45d799e2 2018-12-23 stsp time_t got_object_commit_get_author_time(struct got_commit_object *);
129 45d799e2 2018-12-23 stsp
130 45d799e2 2018-12-23 stsp /* Get an author's timezone offset. */
131 45d799e2 2018-12-23 stsp time_t got_object_commit_get_author_gmtoff(struct got_commit_object *);
132 45d799e2 2018-12-23 stsp
133 45d799e2 2018-12-23 stsp /* Get the committer's name and email address. */
134 45d799e2 2018-12-23 stsp const char *got_object_commit_get_committer(struct got_commit_object *);
135 45d799e2 2018-12-23 stsp
136 450eaa8b 2018-12-23 stsp /* Get a committer's commit timestamp in UTC. */
137 45d799e2 2018-12-23 stsp time_t got_object_commit_get_committer_time(struct got_commit_object *);
138 45d799e2 2018-12-23 stsp
139 450eaa8b 2018-12-23 stsp /* Get a committer's timezone offset. */
140 45d799e2 2018-12-23 stsp time_t got_object_commit_get_committer_gmtoff(struct got_commit_object *);
141 45d799e2 2018-12-23 stsp
142 45d799e2 2018-12-23 stsp /* Get the commit log message. */
143 45d799e2 2018-12-23 stsp const char *got_object_commit_get_logmsg(struct got_commit_object *);
144 45d799e2 2018-12-23 stsp
145 0c60ce5a 2018-04-02 stsp /*
146 0c60ce5a 2018-04-02 stsp * Attempt to open a tree object in a repository.
147 0c60ce5a 2018-04-02 stsp * The caller must dispose of the tree with got_object_tree_close().
148 0c60ce5a 2018-04-02 stsp */
149 15a94983 2018-12-23 stsp const struct got_error *
150 15a94983 2018-12-23 stsp got_object_open_as_tree(struct got_tree_object **,
151 15a94983 2018-12-23 stsp struct got_repository *, struct got_object_id *);
152 0c60ce5a 2018-04-02 stsp
153 0c60ce5a 2018-04-02 stsp /* Dispose of a tree object. */
154 0ffeb3c2 2017-11-26 stsp void got_object_tree_close(struct got_tree_object *);
155 0c60ce5a 2018-04-02 stsp
156 883f0469 2018-06-23 stsp /* Get the entries of a tree object. */
157 883f0469 2018-06-23 stsp const struct got_tree_entries *got_object_tree_get_entries(
158 883f0469 2018-06-23 stsp struct got_tree_object *);
159 883f0469 2018-06-23 stsp
160 0c60ce5a 2018-04-02 stsp /*
161 07862c20 2018-09-15 stsp * Compare two trees and indicate whether the entry at the specified path
162 31cedeaf 2018-09-15 stsp * differs between them. The path must not be the root path "/"; the function
163 31cedeaf 2018-09-15 stsp * got_object_id_cmp() should be used instead to compare the tree roots.
164 07862c20 2018-09-15 stsp */
165 07862c20 2018-09-15 stsp const struct got_error *got_object_tree_path_changed(int *,
166 07862c20 2018-09-15 stsp struct got_tree_object *, struct got_tree_object *, const char *,
167 07862c20 2018-09-15 stsp struct got_repository *);
168 07862c20 2018-09-15 stsp
169 07862c20 2018-09-15 stsp /*
170 0c60ce5a 2018-04-02 stsp * Attempt to open a blob object in a repository.
171 0c60ce5a 2018-04-02 stsp * The size_t argument specifies the block size of an associated read buffer.
172 0c60ce5a 2018-04-02 stsp * The caller must dispose of the blob with got_object_blob_close().
173 0c60ce5a 2018-04-02 stsp */
174 15a94983 2018-12-23 stsp const struct got_error *
175 15a94983 2018-12-23 stsp got_object_open_as_blob(struct got_blob_object **,
176 15a94983 2018-12-23 stsp struct got_repository *, struct got_object_id *, size_t);
177 0c60ce5a 2018-04-02 stsp
178 0c60ce5a 2018-04-02 stsp /* Dispose of a blob object. */
179 68482ea3 2017-11-27 stsp void got_object_blob_close(struct got_blob_object *);
180 0c60ce5a 2018-04-02 stsp
181 0c60ce5a 2018-04-02 stsp /*
182 0c60ce5a 2018-04-02 stsp * Get the length of header data at the beginning of the blob's read buffer.
183 0c60ce5a 2018-04-02 stsp * Note that header data is only present upon the first invocation of
184 0c60ce5a 2018-04-02 stsp * got_object_blob_read_block() after the blob is opened.
185 0c60ce5a 2018-04-02 stsp */
186 f934cf2c 2018-02-12 stsp size_t got_object_blob_get_hdrlen(struct got_blob_object *);
187 0c60ce5a 2018-04-02 stsp
188 0c60ce5a 2018-04-02 stsp /*
189 0c60ce5a 2018-04-02 stsp * Get a pointer to the blob's read buffer.
190 0c60ce5a 2018-04-02 stsp * The read buffer is filled by got_object_blob_read_block().
191 0c60ce5a 2018-04-02 stsp */
192 f934cf2c 2018-02-12 stsp const uint8_t *got_object_blob_get_read_buf(struct got_blob_object *);
193 0c60ce5a 2018-04-02 stsp
194 0c60ce5a 2018-04-02 stsp /*
195 0c60ce5a 2018-04-02 stsp * Read the next chunk of data from a blob, up to the blob's read buffer
196 0c60ce5a 2018-04-02 stsp * block size. The size_t output argument indicates how many bytes have
197 0c60ce5a 2018-04-02 stsp * been read into the blob's read buffer. Zero bytes will be reported if
198 0c60ce5a 2018-04-02 stsp * all data in the blob has been read.
199 0c60ce5a 2018-04-02 stsp */
200 eb651edf 2018-02-11 stsp const struct got_error *got_object_blob_read_block(size_t *,
201 eb651edf 2018-02-11 stsp struct got_blob_object *);
202 be6a1b5a 2018-06-11 stsp
203 35e9ba5d 2018-06-21 stsp /*
204 35e9ba5d 2018-06-21 stsp * Read the entire content of a blob and write it to the specified file.
205 84451b3e 2018-07-10 stsp * Flush and rewind the file as well. Indicate the amount of bytes
206 6fcac457 2018-11-19 stsp * written in the size_t output argument, and the number of lines in
207 6fcac457 2018-11-19 stsp * the file in int argument (NULL can be passed for either output argument).
208 35e9ba5d 2018-06-21 stsp */
209 6fcac457 2018-11-19 stsp const struct got_error *got_object_blob_dump_to_file(size_t *, int *,
210 84451b3e 2018-07-10 stsp FILE *, struct got_blob_object *);
211 35e9ba5d 2018-06-21 stsp
212 f4a881ce 2018-11-17 stsp /*
213 f4a881ce 2018-11-17 stsp * Attempt to open a tag object in a repository.
214 f4a881ce 2018-11-17 stsp * The caller must dispose of the tree with got_object_tag_close().
215 f4a881ce 2018-11-17 stsp */
216 15a94983 2018-12-23 stsp const struct got_error *got_object_open_as_tag(struct got_tag_object **,
217 15a94983 2018-12-23 stsp struct got_repository *, struct got_object_id *);
218 f4a881ce 2018-11-17 stsp
219 f4a881ce 2018-11-17 stsp /* Dispose of a tag object. */
220 f4a881ce 2018-11-17 stsp void got_object_tag_close(struct got_tag_object *);
221 f4a881ce 2018-11-17 stsp
222 bff6ca00 2018-04-23 stsp const struct got_error *got_object_commit_add_parent(struct got_commit_object *,
223 bff6ca00 2018-04-23 stsp const char *);