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 d1cda826 2017-11-06 stsp
21 0ffeb3c2 2017-11-26 stsp struct got_tree_entry {
22 0ffeb3c2 2017-11-26 stsp SIMPLEQ_ENTRY(got_tree_entry) entry;
23 0ffeb3c2 2017-11-26 stsp mode_t mode;
24 0ffeb3c2 2017-11-26 stsp char *name;
25 59ece79d 2018-02-12 stsp struct got_object_id *id;
26 0ffeb3c2 2017-11-26 stsp };
27 0ffeb3c2 2017-11-26 stsp
28 d1cda826 2017-11-06 stsp struct got_tree_object {
29 0ffeb3c2 2017-11-26 stsp int nentries;
30 0ffeb3c2 2017-11-26 stsp SIMPLEQ_HEAD(, got_tree_entry) entries;
31 d1cda826 2017-11-06 stsp };
32 d1cda826 2017-11-06 stsp
33 d1cda826 2017-11-06 stsp struct got_parent_id {
34 d1cda826 2017-11-06 stsp SIMPLEQ_ENTRY(got_parent_id) entry;
35 59ece79d 2018-02-12 stsp struct got_object_id *id;
36 d1cda826 2017-11-06 stsp };
37 d1cda826 2017-11-06 stsp
38 d1cda826 2017-11-06 stsp struct got_commit_object {
39 59ece79d 2018-02-12 stsp struct got_object_id *tree_id;
40 d1cda826 2017-11-06 stsp unsigned int nparents;
41 d1cda826 2017-11-06 stsp SIMPLEQ_HEAD(, got_parent_id) parent_ids;
42 d1cda826 2017-11-06 stsp char *author;
43 6c281f94 2018-06-11 stsp time_t author_time; /* local time */
44 6c281f94 2018-06-11 stsp char *author_tzoff; /* timezone offset description */
45 d1cda826 2017-11-06 stsp char *committer;
46 6c281f94 2018-06-11 stsp time_t committer_time; /* local time */
47 6c281f94 2018-06-11 stsp char *committer_tzoff; /* timezone offset description */
48 d1cda826 2017-11-06 stsp char *logmsg;
49 d1cda826 2017-11-06 stsp };
50 d1cda826 2017-11-06 stsp
51 0c60ce5a 2018-04-02 stsp /* A generic object. Used as a handle which holds an ID and an object type. */
52 eef6493a 2018-01-19 stsp struct got_object;
53 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_COMMIT 1
54 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_TREE 2
55 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_BLOB 3
56 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_TAG 4
57 f9a4270b 2017-12-03 stsp /* 5 is reserved */
58 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_OFFSET_DELTA 6
59 9b1d5162 2017-12-03 stsp #define GOT_OBJ_TYPE_REF_DELTA 7
60 ab9a70b2 2017-11-06 stsp
61 ab9a70b2 2017-11-06 stsp struct got_repository;
62 ab9a70b2 2017-11-06 stsp
63 0c60ce5a 2018-04-02 stsp /*
64 0c60ce5a 2018-04-02 stsp * Obtain a string representation of an object ID. The output depends on
65 0c60ce5a 2018-04-02 stsp * the hash function used by the repository format (currently SHA1).
66 0c60ce5a 2018-04-02 stsp */
67 ef0981d5 2018-02-12 stsp const struct got_error *got_object_id_str(char **, struct got_object_id *);
68 0c60ce5a 2018-04-02 stsp
69 0c60ce5a 2018-04-02 stsp /*
70 0c60ce5a 2018-04-02 stsp * Compare two object IDs. Return value behaves like memcmp(3).
71 0c60ce5a 2018-04-02 stsp */
72 a1fd68d8 2018-01-12 stsp int got_object_id_cmp(struct got_object_id *, struct got_object_id *);
73 0c60ce5a 2018-04-02 stsp
74 0c60ce5a 2018-04-02 stsp /*
75 0c60ce5a 2018-04-02 stsp * Created a newly allocated copy of an object ID.
76 0c60ce5a 2018-04-02 stsp * The caller should dispose of it with free(3).
77 0c60ce5a 2018-04-02 stsp */
78 8bf5b3c9 2018-03-17 stsp struct got_object_id *got_object_id_dup(struct got_object_id *);
79 0c60ce5a 2018-04-02 stsp
80 0c60ce5a 2018-04-02 stsp /*
81 0c60ce5a 2018-04-02 stsp * Get a newly allocated copy of an object's ID.
82 0c60ce5a 2018-04-02 stsp * The caller should dispose of it with free(3).
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 0c60ce5a 2018-04-02 stsp * Obtain the type of an object.
94 0c60ce5a 2018-04-02 stsp * Returns one of the GOT_OBJ_TYPE_x values (see above).
95 0c60ce5a 2018-04-02 stsp */
96 b107e67f 2018-01-19 stsp int got_object_get_type(struct got_object *);
97 0c60ce5a 2018-04-02 stsp
98 0c60ce5a 2018-04-02 stsp /*
99 0c60ce5a 2018-04-02 stsp * Attempt to open the object in a repository with the provided ID.
100 0c60ce5a 2018-04-02 stsp * Caller must dispose of it with got_object_close().
101 0c60ce5a 2018-04-02 stsp */
102 ab9a70b2 2017-11-06 stsp const struct got_error *got_object_open(struct got_object **,
103 ab9a70b2 2017-11-06 stsp struct got_repository *, struct got_object_id *);
104 0c60ce5a 2018-04-02 stsp
105 0c60ce5a 2018-04-02 stsp /*
106 0c60ce5a 2018-04-02 stsp * Attempt to map the provided ID string to an object ID and then
107 0c60ce5a 2018-04-02 stsp * attempt to open the object in a repository with this ID.
108 0c60ce5a 2018-04-02 stsp * The form of an ID string depends on the hash function used by the
109 0c60ce5a 2018-04-02 stsp * repository format (currently SHA1).
110 0c60ce5a 2018-04-02 stsp * Caller must dispose of the object with got_object_close().
111 0c60ce5a 2018-04-02 stsp */
112 6dfa2fd3 2018-02-12 stsp const struct got_error *got_object_open_by_id_str(struct got_object **,
113 0c60ce5a 2018-04-02 stsp struct got_repository *, const char *);
114 0c60ce5a 2018-04-02 stsp
115 0c60ce5a 2018-04-02 stsp /* Dispose of an object. */
116 ab9a70b2 2017-11-06 stsp void got_object_close(struct got_object *);
117 0c60ce5a 2018-04-02 stsp
118 0c60ce5a 2018-04-02 stsp /*
119 0c60ce5a 2018-04-02 stsp * Attempt to open a commit object in a repository.
120 0c60ce5a 2018-04-02 stsp * The provided object must be of type GOT_OBJ_TYPE_COMMIT.
121 0c60ce5a 2018-04-02 stsp * The caller must dispose of the commit with got_object_commit_close().
122 0c60ce5a 2018-04-02 stsp */
123 d1cda826 2017-11-06 stsp const struct got_error *got_object_commit_open(struct got_commit_object **,
124 d1cda826 2017-11-06 stsp struct got_repository *, struct got_object *);
125 0c60ce5a 2018-04-02 stsp
126 0c60ce5a 2018-04-02 stsp /* Dispose of a commit object. */
127 d1cda826 2017-11-06 stsp void got_object_commit_close(struct got_commit_object *);
128 0c60ce5a 2018-04-02 stsp
129 0c60ce5a 2018-04-02 stsp /*
130 0c60ce5a 2018-04-02 stsp * Attempt to open a tree object in a repository.
131 0c60ce5a 2018-04-02 stsp * The provided object must be of type GOT_OBJ_TYPE_TREE.
132 0c60ce5a 2018-04-02 stsp * The caller must dispose of the tree with got_object_tree_close().
133 0c60ce5a 2018-04-02 stsp */
134 0ffeb3c2 2017-11-26 stsp const struct got_error *got_object_tree_open(struct got_tree_object **,
135 0ffeb3c2 2017-11-26 stsp struct got_repository *, struct got_object *);
136 0c60ce5a 2018-04-02 stsp
137 0c60ce5a 2018-04-02 stsp /* Dispose of a tree object. */
138 0ffeb3c2 2017-11-26 stsp void got_object_tree_close(struct got_tree_object *);
139 0c60ce5a 2018-04-02 stsp
140 0c60ce5a 2018-04-02 stsp /*
141 0c60ce5a 2018-04-02 stsp * Attempt to open a blob object in a repository.
142 0c60ce5a 2018-04-02 stsp * The provided object must be of type GOT_OBJ_TYPE_BLOB.
143 0c60ce5a 2018-04-02 stsp * The size_t argument specifies the block size of an associated read buffer.
144 0c60ce5a 2018-04-02 stsp * The caller must dispose of the blob with got_object_blob_close().
145 0c60ce5a 2018-04-02 stsp */
146 68482ea3 2017-11-27 stsp const struct got_error *got_object_blob_open(struct got_blob_object **,
147 68482ea3 2017-11-27 stsp struct got_repository *, struct got_object *, size_t);
148 0c60ce5a 2018-04-02 stsp
149 0c60ce5a 2018-04-02 stsp /* Dispose of a blob object. */
150 68482ea3 2017-11-27 stsp void got_object_blob_close(struct got_blob_object *);
151 0c60ce5a 2018-04-02 stsp
152 0c60ce5a 2018-04-02 stsp /*
153 0c60ce5a 2018-04-02 stsp * Write the string representation of the object ID of a blob to a buffer.
154 0c60ce5a 2018-04-02 stsp * The size_t argument speficies the size of the buffer. In the current
155 0c60ce5a 2018-04-02 stsp * implementation, it must be at least SHA1_DIGEST_STRING_LENGTH bytes.
156 0c60ce5a 2018-04-02 stsp * XXX This is a bad API, use got_object_id_str() instead.
157 0c60ce5a 2018-04-02 stsp */
158 f934cf2c 2018-02-12 stsp char *got_object_blob_id_str(struct got_blob_object*, char *, size_t);
159 0c60ce5a 2018-04-02 stsp
160 0c60ce5a 2018-04-02 stsp /*
161 0c60ce5a 2018-04-02 stsp * Get the length of header data at the beginning of the blob's read buffer.
162 0c60ce5a 2018-04-02 stsp * Note that header data is only present upon the first invocation of
163 0c60ce5a 2018-04-02 stsp * got_object_blob_read_block() after the blob is opened.
164 0c60ce5a 2018-04-02 stsp */
165 f934cf2c 2018-02-12 stsp size_t got_object_blob_get_hdrlen(struct got_blob_object *);
166 0c60ce5a 2018-04-02 stsp
167 0c60ce5a 2018-04-02 stsp /*
168 0c60ce5a 2018-04-02 stsp * Get a pointer to the blob's read buffer.
169 0c60ce5a 2018-04-02 stsp * The read buffer is filled by got_object_blob_read_block().
170 0c60ce5a 2018-04-02 stsp */
171 f934cf2c 2018-02-12 stsp const uint8_t *got_object_blob_get_read_buf(struct got_blob_object *);
172 0c60ce5a 2018-04-02 stsp
173 0c60ce5a 2018-04-02 stsp /*
174 0c60ce5a 2018-04-02 stsp * Read the next chunk of data from a blob, up to the blob's read buffer
175 0c60ce5a 2018-04-02 stsp * block size. The size_t output argument indicates how many bytes have
176 0c60ce5a 2018-04-02 stsp * been read into the blob's read buffer. Zero bytes will be reported if
177 0c60ce5a 2018-04-02 stsp * all data in the blob has been read.
178 0c60ce5a 2018-04-02 stsp */
179 eb651edf 2018-02-11 stsp const struct got_error *got_object_blob_read_block(size_t *,
180 eb651edf 2018-02-11 stsp struct got_blob_object *);
181 bff6ca00 2018-04-23 stsp const struct got_error *got_object_commit_add_parent(struct got_commit_object *,
182 bff6ca00 2018-04-23 stsp const char *);