Blob


1 /*
2 * Copyright (c) 2018, 2019, 2020 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_object {
18 int type;
20 int flags;
21 #define GOT_OBJ_FLAG_PACKED 0x01
22 #define GOT_OBJ_FLAG_DELTIFIED 0x02
24 size_t hdrlen;
25 size_t size;
26 struct got_object_id id;
28 int pack_idx; /* if packed */
29 off_t pack_offset; /* if packed */
30 struct got_delta_chain deltas; /* if deltified */
31 int refcnt; /* > 0 if open and/or cached */
32 };
35 /* A callback function which is invoked when a raw object is closed. */
36 struct got_raw_object;
37 typedef void (got_object_raw_close_cb)(struct got_raw_object *);
39 struct got_raw_object {
40 FILE *f; /* NULL if data buffer is being used */
41 int fd; /* -1 unless data buffer is memory-mapped */
42 int tempfile_idx; /* -1 unless using a repository-tempfile */
43 uint8_t *data;
44 off_t size;
45 size_t hdrlen;
46 int refcnt; /* > 0 if open and/or cached */
48 got_object_raw_close_cb *close_cb;
49 void *close_arg;
50 };
52 struct got_commit_object {
53 struct got_object_id *tree_id;
54 unsigned int nparents;
55 struct got_object_id_queue parent_ids;
56 char *author;
57 time_t author_time; /* UTC */
58 time_t author_gmtoff;
59 char *committer;
60 time_t committer_time; /* UTC */
61 time_t committer_gmtoff;
62 char *logmsg;
63 int refcnt; /* > 0 if open and/or cached */
65 int flags;
66 #define GOT_COMMIT_FLAG_PACKED 0x01
67 };
69 struct got_tree_entry {
70 mode_t mode;
71 char name[NAME_MAX + 1 /* NUL */];
72 struct got_object_id id;
73 int idx;
74 };
76 struct got_tree_object {
77 int nentries;
78 struct got_tree_entry *entries;
79 int refcnt;
80 };
82 struct got_blob_object {
83 FILE *f;
84 uint8_t *data;
85 size_t hdrlen;
86 size_t blocksize;
87 uint8_t *read_buf;
88 struct got_object_id id;
89 };
91 struct got_tag_object {
92 struct got_object_id id;
93 int obj_type;
94 char *tag;
95 time_t tagger_time;
96 time_t tagger_gmtoff;
97 char *tagger;
98 char *tagmsg;
99 int refcnt; /* > 0 if open and/or cached */
100 };
102 struct got_object_id *got_object_get_id(struct got_object *);
103 const struct got_error *got_object_get_id_str(char **, struct got_object *);
104 const struct got_error *got_object_get_path(char **, struct got_object_id *,
105 struct got_repository *);
106 const struct got_error *got_object_open_loose_fd(int *, struct got_object_id *,
107 struct got_repository *);
108 const struct got_error *got_object_open_packed(struct got_object **,
109 struct got_object_id *, struct got_repository *);
110 struct got_pack;
111 struct got_packidx;
112 const struct got_error *got_object_open_from_packfile(struct got_object **,
113 struct got_object_id *, struct got_pack *, struct got_packidx *, int,
114 struct got_repository *);
115 const struct got_error *got_object_read_raw_delta(uint64_t *, uint64_t *,
116 off_t *, off_t *, off_t *, off_t *, struct got_object_id **, int,
117 struct got_packidx *, int, struct got_object_id *, struct got_repository *);
118 const struct got_error *got_object_prepare_delta_reuse(struct got_pack **,
119 struct got_packidx *, int, struct got_repository *);
120 const struct got_error *got_object_read_header_privsep(struct got_object **,
121 struct got_object_id *, struct got_repository *, int);
122 const struct got_error *got_object_open(struct got_object **,
123 struct got_repository *, struct got_object_id *);
124 const struct got_error *got_object_raw_open(struct got_raw_object **, int *,
125 struct got_repository *, struct got_object_id *);
126 const struct got_error *got_object_raw_close(struct got_raw_object *);
127 const struct got_error *got_object_open_by_id_str(struct got_object **,
128 struct got_repository *, const char *);
129 void got_object_close(struct got_object *);
130 const struct got_error *got_object_commit_open(struct got_commit_object **,
131 struct got_repository *, struct got_object *);
132 const struct got_error *got_object_tree_open(struct got_tree_object **,
133 struct got_repository *, struct got_object *);
134 const struct got_error *got_object_blob_open(struct got_blob_object **,
135 struct got_repository *, struct got_object *, size_t, int);
136 char *got_object_blob_id_str(struct got_blob_object*, char *, size_t);
137 const struct got_error *got_object_tag_open(struct got_tag_object **,
138 struct got_repository *, struct got_object *);
139 const struct got_error *got_object_tree_entry_dup(struct got_tree_entry **,
140 struct got_tree_entry *);
142 const struct got_error *got_traverse_packed_commits(
143 struct got_object_id_queue *, struct got_object_id *, const char *,
144 struct got_repository *);
146 typedef const struct got_error *(*got_object_enumerate_commit_cb)(void *,
147 time_t, struct got_object_id *, struct got_repository *);
148 typedef const struct got_error *(*got_object_enumerate_tree_cb)(void *,
149 struct got_tree_object *, time_t, struct got_object_id *, const char *,
150 struct got_repository *);
152 const struct got_error *got_object_enumerate(int *,
153 got_object_enumerate_commit_cb, got_object_enumerate_tree_cb, void *,
154 struct got_object_id **, int, struct got_object_id **, int,
155 struct got_packidx *, struct got_repository *);
157 const struct got_error *got_object_raw_alloc(struct got_raw_object **,
158 uint8_t *, int *, size_t, size_t, off_t);