Blame


1 718b3ab0 2018-03-17 stsp /*
2 718b3ab0 2018-03-17 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 718b3ab0 2018-03-17 stsp *
4 718b3ab0 2018-03-17 stsp * Permission to use, copy, modify, and distribute this software for any
5 718b3ab0 2018-03-17 stsp * purpose with or without fee is hereby granted, provided that the above
6 718b3ab0 2018-03-17 stsp * copyright notice and this permission notice appear in all copies.
7 718b3ab0 2018-03-17 stsp *
8 718b3ab0 2018-03-17 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 718b3ab0 2018-03-17 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 718b3ab0 2018-03-17 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 718b3ab0 2018-03-17 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 718b3ab0 2018-03-17 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 718b3ab0 2018-03-17 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 718b3ab0 2018-03-17 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 718b3ab0 2018-03-17 stsp */
16 718b3ab0 2018-03-17 stsp
17 66cba96f 2020-03-18 stsp #define GOT_GIT_DIR ".git"
18 66cba96f 2020-03-18 stsp
19 66cba96f 2020-03-18 stsp /* Mandatory files and directories inside the git directory. */
20 66cba96f 2020-03-18 stsp #define GOT_OBJECTS_DIR "objects"
21 66cba96f 2020-03-18 stsp #define GOT_REFS_DIR "refs"
22 66cba96f 2020-03-18 stsp #define GOT_HEAD_FILE "HEAD"
23 66cba96f 2020-03-18 stsp #define GOT_GITCONFIG "config"
24 66cba96f 2020-03-18 stsp
25 66cba96f 2020-03-18 stsp /* Other files and directories inside the git directory. */
26 66cba96f 2020-03-18 stsp #define GOT_FETCH_HEAD_FILE "FETCH_HEAD"
27 66cba96f 2020-03-18 stsp #define GOT_ORIG_HEAD_FILE "ORIG_HEAD"
28 66cba96f 2020-03-18 stsp #define GOT_OBJECTS_PACK_DIR "objects/pack"
29 66cba96f 2020-03-18 stsp #define GOT_PACKED_REFS_FILE "packed-refs"
30 66cba96f 2020-03-18 stsp
31 6cb2eb6e 2022-05-31 thomas #define GOT_PACK_CACHE_SIZE 32
32 718b3ab0 2018-03-17 stsp
33 3efd8e31 2022-10-23 thomas /*
34 3efd8e31 2022-10-23 thomas * While in gotd(8) chroot, a repository needs this many temporary files.
35 3efd8e31 2022-10-23 thomas * This limit sets an upper bound on how many raw objects or blobs can
36 3efd8e31 2022-10-23 thomas * be kept open in parallel.
37 3efd8e31 2022-10-23 thomas */
38 3efd8e31 2022-10-23 thomas #define GOT_REPO_NUM_TEMPFILES 32
39 3efd8e31 2022-10-23 thomas
40 4545b700 2021-10-15 thomas struct got_packidx_bloom_filter {
41 cfe41121 2021-10-16 thomas RB_ENTRY(got_packidx_bloom_filter) entry;
42 cfe41121 2021-10-16 thomas char path[PATH_MAX]; /* on-disk path */
43 cfe41121 2021-10-16 thomas size_t path_len;
44 4545b700 2021-10-15 thomas struct bloom *bloom;
45 4545b700 2021-10-15 thomas };
46 4545b700 2021-10-15 thomas
47 cfe41121 2021-10-16 thomas RB_HEAD(got_packidx_bloom_filter_tree, got_packidx_bloom_filter);
48 4545b700 2021-10-15 thomas
49 cfe41121 2021-10-16 thomas static inline int
50 cfe41121 2021-10-16 thomas got_packidx_bloom_filter_cmp(const struct got_packidx_bloom_filter *f1,
51 cfe41121 2021-10-16 thomas const struct got_packidx_bloom_filter *f2)
52 cfe41121 2021-10-16 thomas {
53 cfe41121 2021-10-16 thomas return got_path_cmp(f1->path, f2->path, f1->path_len, f2->path_len);
54 cfe41121 2021-10-16 thomas }
55 cfe41121 2021-10-16 thomas
56 a777fdc0 2022-10-13 thomas struct got_repo_privsep_child {
57 a777fdc0 2022-10-13 thomas int imsg_fd;
58 a777fdc0 2022-10-13 thomas pid_t pid;
59 a777fdc0 2022-10-13 thomas struct imsgbuf *ibuf;
60 a777fdc0 2022-10-13 thomas };
61 a777fdc0 2022-10-13 thomas
62 718b3ab0 2018-03-17 stsp struct got_repository {
63 718b3ab0 2018-03-17 stsp char *path;
64 718b3ab0 2018-03-17 stsp char *path_git_dir;
65 6d5a9006 2020-12-16 yzhong int gitdir_fd;
66 f4204d57 2023-03-01 thomas enum got_hash_algorithm algo;
67 718b3ab0 2018-03-17 stsp
68 de47d040 2022-03-22 thomas struct got_pathlist_head packidx_paths;
69 9b251092 2022-11-08 thomas struct timespec pack_path_mtime;
70 de47d040 2022-03-22 thomas
71 718b3ab0 2018-03-17 stsp /* The pack index cache speeds up search for packed objects. */
72 6c414261 2021-03-30 stsp struct got_packidx *packidx_cache[GOT_PACK_CACHE_SIZE];
73 718b3ab0 2018-03-17 stsp
74 4545b700 2021-10-15 thomas /*
75 4545b700 2021-10-15 thomas * List of bloom filters for pack index files.
76 4545b700 2021-10-15 thomas * Used to avoid opening a pack index in search of an
77 4545b700 2021-10-15 thomas * object ID which is not contained in this pack index.
78 4545b700 2021-10-15 thomas */
79 cfe41121 2021-10-16 thomas struct got_packidx_bloom_filter_tree packidx_bloom_filters;
80 4545b700 2021-10-15 thomas
81 6c6d3ed3 2018-04-02 stsp /* Open file handles for pack files. */
82 718b3ab0 2018-03-17 stsp struct got_pack packs[GOT_PACK_CACHE_SIZE];
83 7bb0daa1 2018-06-21 stsp
84 3efd8e31 2022-10-23 thomas /* Open file handles for storing temporary data in gotd(8) chroot. */
85 3efd8e31 2022-10-23 thomas int tempfiles[GOT_REPO_NUM_TEMPFILES];
86 3efd8e31 2022-10-23 thomas uint32_t tempfile_use_mask;
87 3efd8e31 2022-10-23 thomas
88 6c414261 2021-03-30 stsp /*
89 6c414261 2021-03-30 stsp * The cache size limit may be lower than GOT_PACK_CACHE_SIZE,
90 6c414261 2021-03-30 stsp * depending on resource limits.
91 6c414261 2021-03-30 stsp */
92 6c414261 2021-03-30 stsp int pack_cache_size;
93 6c414261 2021-03-30 stsp
94 ec2b23c5 2022-07-01 thomas /*
95 ec2b23c5 2022-07-01 thomas * Index to cache entries which are pinned to avoid eviction.
96 ec2b23c5 2022-07-01 thomas * This may be used to keep one got-index-pack process alive
97 ec2b23c5 2022-07-01 thomas * across searches for arbitrary objects which may be stored
98 ec2b23c5 2022-07-01 thomas * in other pack files.
99 ec2b23c5 2022-07-01 thomas */
100 ec2b23c5 2022-07-01 thomas int pinned_pack;
101 ec2b23c5 2022-07-01 thomas pid_t pinned_pid;
102 ec2b23c5 2022-07-01 thomas int pinned_packidx;
103 ec2b23c5 2022-07-01 thomas
104 ad242220 2018-09-08 stsp /* Handles to child processes for reading loose objects. */
105 a777fdc0 2022-10-13 thomas struct got_repo_privsep_child privsep_children[5];
106 ad242220 2018-09-08 stsp #define GOT_REPO_PRIVSEP_CHILD_OBJECT 0
107 ad242220 2018-09-08 stsp #define GOT_REPO_PRIVSEP_CHILD_COMMIT 1
108 ad242220 2018-09-08 stsp #define GOT_REPO_PRIVSEP_CHILD_TREE 2
109 ad242220 2018-09-08 stsp #define GOT_REPO_PRIVSEP_CHILD_BLOB 3
110 f4a881ce 2018-11-17 stsp #define GOT_REPO_PRIVSEP_CHILD_TAG 4
111 ad242220 2018-09-08 stsp
112 ad242220 2018-09-08 stsp /* Caches for open objects. */
113 54f20211 2018-06-22 stsp struct got_object_cache objcache;
114 f6be5c30 2018-06-22 stsp struct got_object_cache treecache;
115 1943de01 2018-06-22 stsp struct got_object_cache commitcache;
116 f4a881ce 2018-11-17 stsp struct got_object_cache tagcache;
117 8ab9215c 2021-10-15 thomas struct got_object_cache rawcache;
118 1d126e2d 2019-08-24 stsp
119 1d126e2d 2019-08-24 stsp /* Settings read from Git configuration files. */
120 aba9c984 2019-09-08 stsp int gitconfig_repository_format_version;
121 aba9c984 2019-09-08 stsp char *gitconfig_author_name;
122 aba9c984 2019-09-08 stsp char *gitconfig_author_email;
123 c9956ddf 2019-09-08 stsp char *global_gitconfig_author_name;
124 c9956ddf 2019-09-08 stsp char *global_gitconfig_author_email;
125 cd95becd 2019-11-29 stsp int ngitconfig_remotes;
126 cd95becd 2019-11-29 stsp struct got_remote_repo *gitconfig_remotes;
127 9a1cc63f 2020-02-03 stsp char *gitconfig_owner;
128 b091c2cd 2023-02-07 thomas char **extnames;
129 b091c2cd 2023-02-07 thomas char **extvals;
130 20b7abb3 2020-10-22 stsp int nextensions;
131 257add31 2020-09-09 stsp
132 257add31 2020-09-09 stsp /* Settings read from got.conf. */
133 50b0790e 2020-09-11 stsp struct got_gotconfig *gotconfig;
134 718b3ab0 2018-03-17 stsp };
135 7bb0daa1 2018-06-21 stsp
136 f6be5c30 2018-06-22 stsp const struct got_error*got_repo_cache_object(struct got_repository *,
137 f6be5c30 2018-06-22 stsp struct got_object_id *, struct got_object *);
138 7bb0daa1 2018-06-21 stsp struct got_object *got_repo_get_cached_object(struct got_repository *,
139 7bb0daa1 2018-06-21 stsp struct got_object_id *);
140 f6be5c30 2018-06-22 stsp const struct got_error*got_repo_cache_tree(struct got_repository *,
141 f6be5c30 2018-06-22 stsp struct got_object_id *, struct got_tree_object *);
142 f6be5c30 2018-06-22 stsp struct got_tree_object *got_repo_get_cached_tree(struct got_repository *,
143 f6be5c30 2018-06-22 stsp struct got_object_id *);
144 1943de01 2018-06-22 stsp const struct got_error*got_repo_cache_commit(struct got_repository *,
145 1943de01 2018-06-22 stsp struct got_object_id *, struct got_commit_object *);
146 1943de01 2018-06-22 stsp struct got_commit_object *got_repo_get_cached_commit(struct got_repository *,
147 1943de01 2018-06-22 stsp struct got_object_id *);
148 f4a881ce 2018-11-17 stsp const struct got_error*got_repo_cache_tag(struct got_repository *,
149 f4a881ce 2018-11-17 stsp struct got_object_id *, struct got_tag_object *);
150 f4a881ce 2018-11-17 stsp struct got_tag_object *got_repo_get_cached_tag(struct got_repository *,
151 f4a881ce 2018-11-17 stsp struct got_object_id *);
152 8ab9215c 2021-10-15 thomas const struct got_error*got_repo_cache_raw_object(struct got_repository *,
153 8ab9215c 2021-10-15 thomas struct got_object_id *, struct got_raw_object *);
154 8ab9215c 2021-10-15 thomas struct got_raw_object *got_repo_get_cached_raw_object(struct got_repository *,
155 8ab9215c 2021-10-15 thomas struct got_object_id *);
156 1124fe40 2021-07-07 stsp int got_repo_is_packidx_filename(const char *, size_t);
157 f9c2e8e5 2022-02-13 thomas int got_repo_check_packidx_bloom_filter(struct got_repository *,
158 f9c2e8e5 2022-02-13 thomas const char *, struct got_object_id *);
159 1510f469 2018-09-09 stsp const struct got_error *got_repo_search_packidx(struct got_packidx **, int *,
160 1510f469 2018-09-09 stsp struct got_repository *, struct got_object_id *);
161 f9c2e8e5 2022-02-13 thomas const struct got_error *got_repo_list_packidx(struct got_pathlist_head *,
162 f9c2e8e5 2022-02-13 thomas struct got_repository *);
163 f9c2e8e5 2022-02-13 thomas const struct got_error *got_repo_get_packidx(struct got_packidx **, const char *,
164 f9c2e8e5 2022-02-13 thomas struct got_repository *);
165 1510f469 2018-09-09 stsp const struct got_error *got_repo_cache_pack(struct got_pack **,
166 1510f469 2018-09-09 stsp struct got_repository *, const char *, struct got_packidx *);
167 ec2b23c5 2022-07-01 thomas struct got_pack *got_repo_get_cached_pack(struct got_repository *,
168 ec2b23c5 2022-07-01 thomas const char *);
169 ec2b23c5 2022-07-01 thomas const struct got_error *got_repo_pin_pack(struct got_repository *,
170 ec2b23c5 2022-07-01 thomas struct got_packidx *, struct got_pack *);
171 ec2b23c5 2022-07-01 thomas struct got_pack *got_repo_get_pinned_pack(struct got_repository *);
172 ec2b23c5 2022-07-01 thomas void got_repo_unpin_pack(struct got_repository *);
173 ec2b23c5 2022-07-01 thomas
174 d348087d 2022-10-13 thomas const struct got_error *got_repo_read_gitconfig(int *, char **, char **,
175 b091c2cd 2023-02-07 thomas struct got_remote_repo **, int *, char **, char ***, char ***, int *,
176 d348087d 2022-10-13 thomas const char *);
177 3efd8e31 2022-10-23 thomas
178 3efd8e31 2022-10-23 thomas const struct got_error *got_repo_temp_fds_get(int *, int *,
179 3efd8e31 2022-10-23 thomas struct got_repository *);
180 3efd8e31 2022-10-23 thomas void got_repo_temp_fds_put(int, struct got_repository *);