Hash :
e40622f4
Author :
Date :
2020-07-23T14:21:28
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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
/*
* 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_tree_entry;
struct got_tag_object;
struct got_commit_object;
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 *);
void got_object_id_queue_free(struct got_object_id_queue *);
/* Object types. */
#define GOT_OBJ_TYPE_ANY 0 /* wildcard value at run-time */
#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
/*
* Labels used in object data.
*/
#define GOT_OBJ_LABEL_COMMIT "commit"
#define GOT_OBJ_LABEL_TREE "tree"
#define GOT_OBJ_LABEL_BLOB "blob"
#define GOT_OBJ_LABEL_TAG "tag"
#define GOT_COMMIT_LABEL_TREE "tree "
#define GOT_COMMIT_LABEL_PARENT "parent "
#define GOT_COMMIT_LABEL_AUTHOR "author "
#define GOT_COMMIT_LABEL_COMMITTER "committer "
#define GOT_TAG_LABEL_OBJECT "object "
#define GOT_TAG_LABEL_TYPE "type "
#define GOT_TAG_LABEL_TAG "tag "
#define GOT_TAG_LABEL_TAGGER "tagger "
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.
* PGP-signatures contained in the log message will be stripped.
* The caller must dispose of it with free(3).
*/
const struct got_error *got_object_commit_get_logmsg(char **,
struct got_commit_object *);
/* Get the raw commit log message.*/
const char *got_object_commit_get_logmsg_raw(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 number of entries in this tree object. */
int got_object_tree_get_nentries(struct got_tree_object *);
/* Get the first tree entry from a tree, or NULL if there is none. */
struct got_tree_entry *got_object_tree_get_first_entry(struct got_tree_object *);
/* Get the last tree entry from a tree, or NULL if there is none. */
struct got_tree_entry *got_object_tree_get_last_entry(struct got_tree_object *);
/* Get the entry with the specified index from a tree object. */
struct got_tree_entry *got_object_tree_get_entry(
struct got_tree_object *, int);
/* Find a particular entry in a tree by name. */
struct got_tree_entry *got_object_tree_find_entry(
struct got_tree_object *, const char *);
/* Get the file permission mode of a tree entry. */
mode_t got_tree_entry_get_mode(struct got_tree_entry *);
/* Get the name of a tree entry. */
const char *got_tree_entry_get_name(struct got_tree_entry *);
/* Get the object ID of a tree entry. */
struct got_object_id *got_tree_entry_get_id(struct got_tree_entry *);
/*
* Get a string containing the target path of a given a symlink tree entry.
* The caller should dispose of it with free(3).
*/
const struct got_error *got_tree_entry_get_symlink_target(char **,
struct got_tree_entry *, struct got_repository *);
/* Get the index of a tree entry. */
int got_tree_entry_get_index(struct got_tree_entry *);
/* Get the next tree entry from a tree, or NULL if there is none. */
struct got_tree_entry *got_tree_entry_get_next(struct got_tree_object *,
struct got_tree_entry *);
/* Get the previous tree entry from a tree, or NULL if there is none. */
struct got_tree_entry *got_tree_entry_get_prev(struct got_tree_object *,
struct got_tree_entry *);
/* Return non-zero if the specified tree entry is a Git submodule. */
int got_object_tree_entry_is_submodule(struct got_tree_entry *);
/* Return non-zero if the specified tree entry is a symbolic link. */
int got_object_tree_entry_is_symlink(struct got_tree_entry *);
/*
* Resolve an in-repository symlink at the specified path in the tree
* corresponding to the specified commit. If the specified path is not
* a symlink then set *link_target to NULL.
* Otherwise, resolve symlinks recursively and return the final link
* target path. The caller must dispose of it with free(3).
*/
const struct got_error *got_object_resolve_symlinks(char **, const char *,
struct got_object_id *, struct got_repository *);
/*
* 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 *);
/* Rewind an open blob's data stream back to the beginning. */
void got_object_blob_rewind(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 the int argument, and line offsets in the off_t argument
* (NULL can be passed for any output argument).
*/
const struct got_error *got_object_blob_dump_to_file(size_t *, int *,
off_t **, FILE *, struct got_blob_object *);
/*
* Attempt to open a tag object in a repository.
* The caller must dispose of the tree with got_tag_object_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 the name of a tag. */
const char *got_object_tag_get_name(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 *);
/* Get the timestamp of the tag. */
time_t got_object_tag_get_tagger_time(struct got_tag_object *);
/* Get the tag's timestamp's GMT offset. */
time_t got_object_tag_get_tagger_gmtoff(struct got_tag_object *);
/* Get the author of the tag. */
const char *got_object_tag_get_tagger(struct got_tag_object *);
/* Get the tag message associated with the tag. */
const char *got_object_tag_get_message(struct got_tag_object *);
const struct got_error *got_object_commit_add_parent(struct got_commit_object *,
const char *);
/* Create a new tag object in the repository. */
const struct got_error *got_object_tag_create(struct got_object_id **,
const char *, struct got_object_id *, const char *,
time_t, const char *, struct got_repository *);