Blob


1 /*
2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 struct got_zstream_buf {
18 z_stream z;
19 char *inbuf;
20 size_t inlen;
21 char *outbuf;
22 size_t outlen;
23 int flags;
24 #define GOT_ZSTREAM_F_HAVE_MORE 0x01
25 };
27 struct got_object_id {
28 u_int8_t sha1[SHA1_DIGEST_LENGTH];
29 };
31 struct got_blob_object {
32 FILE *f;
33 struct got_zstream_buf zb;
34 size_t hdrlen;
35 size_t blocksize;
36 uint8_t *read_buf;
37 int flags;
38 #define GOT_BLOB_F_COMPRESSED 0x01
39 struct got_object_id id;
40 };
42 struct got_tree_entry {
43 SIMPLEQ_ENTRY(got_tree_entry) entry;
44 mode_t mode;
45 char *name;
46 struct got_object_id id;
47 };
49 struct got_tree_object {
50 int nentries;
51 SIMPLEQ_HEAD(, got_tree_entry) entries;
52 };
54 struct got_parent_id {
55 SIMPLEQ_ENTRY(got_parent_id) entry;
56 struct got_object_id id;
57 };
59 SIMPLEQ_HEAD(got_parent_id_list, got_parent_id);
61 struct got_commit_object {
62 struct got_object_id tree_id;
63 unsigned int nparents;
64 SIMPLEQ_HEAD(, got_parent_id) parent_ids;
65 char *author;
66 char *committer;
67 char *logmsg;
68 };
70 struct got_object;
71 #define GOT_OBJ_TYPE_COMMIT 1
72 #define GOT_OBJ_TYPE_TREE 2
73 #define GOT_OBJ_TYPE_BLOB 3
74 #define GOT_OBJ_TYPE_TAG 4
75 /* 5 is reserved */
76 #define GOT_OBJ_TYPE_OFFSET_DELTA 6
77 #define GOT_OBJ_TYPE_REF_DELTA 7
79 struct got_repository;
81 char *got_object_id_str(struct got_object_id *, char *, size_t);
82 int got_object_id_cmp(struct got_object_id *, struct got_object_id *);
83 int got_object_get_type(struct got_object *);
84 const struct got_error *got_object_open(struct got_object **,
85 struct got_repository *, struct got_object_id *);
86 void got_object_close(struct got_object *);
87 const struct got_error *got_object_commit_open(struct got_commit_object **,
88 struct got_repository *, struct got_object *);
89 void got_object_commit_close(struct got_commit_object *);
90 const struct got_error *got_object_tree_open(struct got_tree_object **,
91 struct got_repository *, struct got_object *);
92 void got_object_tree_close(struct got_tree_object *);
93 const struct got_error *got_object_blob_open(struct got_blob_object **,
94 struct got_repository *, struct got_object *, size_t);
95 void got_object_blob_close(struct got_blob_object *);
96 const struct got_error *got_object_blob_read_block(size_t *,
97 struct got_blob_object *);