1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
/*
* Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
struct got_object_id;
struct got_blob_object;
struct got_tree_object;
struct got_tag_object;
struct got_commit_object;
struct got_tree_entry {
SIMPLEQ_ENTRY(got_tree_entry) entry;
mode_t mode;
char *name;
struct got_object_id *id;
};
SIMPLEQ_HEAD(got_tree_entries_queue, got_tree_entry);
struct got_tree_entries {
int nentries;
struct got_tree_entries_queue head;
};
struct got_object_qid {
SIMPLEQ_ENTRY(got_object_qid) entry;
struct got_object_id *id;
};
SIMPLEQ_HEAD(got_object_id_queue, got_object_qid);
const struct got_error *got_object_qid_alloc(struct got_object_qid **,
struct got_object_id *);
void got_object_qid_free(struct got_object_qid *);
/* Object types. */
#define GOT_OBJ_TYPE_COMMIT 1
#define GOT_OBJ_TYPE_TREE 2
#define GOT_OBJ_TYPE_BLOB 3
#define GOT_OBJ_TYPE_TAG 4
/* 5 is reserved */
#define GOT_OBJ_TYPE_OFFSET_DELTA 6
#define GOT_OBJ_TYPE_REF_DELTA 7
struct got_repository;
/*
* Obtain a string representation of an object ID. The output depends on
* the hash function used by the repository format (currently SHA1).
*/
const struct got_error *got_object_id_str(char **, struct got_object_id *);
/*
* Compare two object IDs. Return value behaves like memcmp(3).
*/
int got_object_id_cmp(const struct got_object_id *,
const struct got_object_id *);
/*
* Created a newly allocated copy of an object ID.
* The caller should dispose of it with free(3).
*/
struct got_object_id *got_object_id_dup(struct got_object_id *);
/*
* Get a newly allocated ID of the object which resides at the specified
* path in the tree of the specified commit.
* The caller should dispose of it with free(3).
*/
const struct got_error *
got_object_id_by_path(struct got_object_id **, struct got_repository *,
struct got_object_id *, const char *);
/*
* Obtain the type of an object.
* Returns one of the GOT_OBJ_TYPE_x values (see above).
*/
const struct got_error *got_object_get_type(int *, struct got_repository *,
struct got_object_id *);
/*
* Attempt to resolve the textual representation of an object ID
* to the ID of an existing object in the repository.
* The caller should dispose of the ID with free(3).
*/
const struct got_error *
got_object_resolve_id_str(struct got_object_id **, struct got_repository *,
const char *);
/*
* Attempt to open a commit object in a repository.
* The caller must dispose of the commit with got_object_commit_close().
*/
const struct got_error *
got_object_open_as_commit(struct got_commit_object **,
struct got_repository *, struct got_object_id *);
/* Dispose of a commit object. */
void got_object_commit_close(struct got_commit_object *);
/* Obtain the ID of the tree created in a commit. */
struct got_object_id *got_object_commit_get_tree_id(struct got_commit_object *);
/* Obtain the number of parent commits of a commit. */
int got_object_commit_get_nparents(struct got_commit_object *);
/* Obtain the list of parent commits of a commit. */
const struct got_object_id_queue *got_object_commit_get_parent_ids(
struct got_commit_object *);
/* Get the author's name and email address. */
const char *got_object_commit_get_author(struct got_commit_object *);
/* Get an author's commit timestamp in UTC. */
time_t got_object_commit_get_author_time(struct got_commit_object *);
/* Get an author's timezone offset. */
time_t got_object_commit_get_author_gmtoff(struct got_commit_object *);
/* Get the committer's name and email address. */
const char *got_object_commit_get_committer(struct got_commit_object *);
/* Get a committer's commit timestamp in UTC. */
time_t got_object_commit_get_committer_time(struct got_commit_object *);
/* Get a committer's timezone offset. */
time_t got_object_commit_get_committer_gmtoff(struct got_commit_object *);
/* Get the commit log message. */
const char *got_object_commit_get_logmsg(struct got_commit_object *);
/*
* Attempt to open a tree object in a repository.
* The caller must dispose of the tree with got_object_tree_close().
*/
const struct got_error *
got_object_open_as_tree(struct got_tree_object **,
struct got_repository *, struct got_object_id *);
/* Dispose of a tree object. */
void got_object_tree_close(struct got_tree_object *);
/* Get the entries of a tree object. */
const struct got_tree_entries *got_object_tree_get_entries(
struct got_tree_object *);
/*
* Compare two trees and indicate whether the entry at the specified path
* differs between them. The path must not be the root path "/"; the function
* got_object_id_cmp() should be used instead to compare the tree roots.
*/
const struct got_error *got_object_tree_path_changed(int *,
struct got_tree_object *, struct got_tree_object *, const char *,
struct got_repository *);
/*
* Attempt to open a blob object in a repository.
* The size_t argument specifies the block size of an associated read buffer.
* The caller must dispose of the blob with got_object_blob_close().
*/
const struct got_error *
got_object_open_as_blob(struct got_blob_object **,
struct got_repository *, struct got_object_id *, size_t);
/* Dispose of a blob object. */
const struct got_error *got_object_blob_close(struct got_blob_object *);
/*
* Get the length of header data at the beginning of the blob's read buffer.
* Note that header data is only present upon the first invocation of
* got_object_blob_read_block() after the blob is opened.
*/
size_t got_object_blob_get_hdrlen(struct got_blob_object *);
/*
* Get a pointer to the blob's read buffer.
* The read buffer is filled by got_object_blob_read_block().
*/
const uint8_t *got_object_blob_get_read_buf(struct got_blob_object *);
/*
* Read the next chunk of data from a blob, up to the blob's read buffer
* block size. The size_t output argument indicates how many bytes have
* been read into the blob's read buffer. Zero bytes will be reported if
* all data in the blob has been read.
*/
const struct got_error *got_object_blob_read_block(size_t *,
struct got_blob_object *);
/*
* Read the entire content of a blob and write it to the specified file.
* Flush and rewind the file as well. Indicate the amount of bytes
* written in the size_t output argument, and the number of lines in
* the file in int argument (NULL can be passed for either output argument).
*/
const struct got_error *got_object_blob_dump_to_file(size_t *, int *,
FILE *, struct got_blob_object *);
/*
* Attempt to open a tag object in a repository.
* The caller must dispose of the tree with got_object_tag_close().
*/
const struct got_error *got_object_open_as_tag(struct got_tag_object **,
struct got_repository *, struct got_object_id *);
/* Dispose of a tag object. */
void got_object_tag_close(struct got_tag_object *);
/* Get type of the object a tag points to. */
int got_object_tag_get_object_type(struct got_tag_object *);
/*
* Get ID of the object a tag points to.
* This must not be freed by the caller. Use got_object_id_dup() if needed.
*/
struct got_object_id *got_object_tag_get_object_id(struct got_tag_object *);
const struct got_error *got_object_commit_add_parent(struct got_commit_object *,
const char *);