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 cfcf1cbc 2022-05-31 stsp #define GOT_PACK_CACHE_SIZE 32
32 718b3ab0 2018-03-17 stsp
33 b343c297 2021-10-11 stsp struct got_packidx_bloom_filter {
34 f8b19efd 2021-10-13 stsp RB_ENTRY(got_packidx_bloom_filter) entry;
35 f8b19efd 2021-10-13 stsp char path[PATH_MAX]; /* on-disk path */
36 f8b19efd 2021-10-13 stsp size_t path_len;
37 b343c297 2021-10-11 stsp struct bloom *bloom;
38 b343c297 2021-10-11 stsp };
39 b343c297 2021-10-11 stsp
40 f8b19efd 2021-10-13 stsp RB_HEAD(got_packidx_bloom_filter_tree, got_packidx_bloom_filter);
41 b343c297 2021-10-11 stsp
42 f8b19efd 2021-10-13 stsp static inline int
43 f8b19efd 2021-10-13 stsp got_packidx_bloom_filter_cmp(const struct got_packidx_bloom_filter *f1,
44 f8b19efd 2021-10-13 stsp const struct got_packidx_bloom_filter *f2)
45 f8b19efd 2021-10-13 stsp {
46 f8b19efd 2021-10-13 stsp return got_path_cmp(f1->path, f2->path, f1->path_len, f2->path_len);
47 f8b19efd 2021-10-13 stsp }
48 f8b19efd 2021-10-13 stsp
49 718b3ab0 2018-03-17 stsp struct got_repository {
50 718b3ab0 2018-03-17 stsp char *path;
51 718b3ab0 2018-03-17 stsp char *path_git_dir;
52 6d5a9006 2020-12-16 yzhong int gitdir_fd;
53 718b3ab0 2018-03-17 stsp
54 9b576444 2022-03-14 stsp struct got_pathlist_head packidx_paths;
55 b8a4401b 2022-09-01 stsp time_t pack_path_mtime;
56 9b576444 2022-03-14 stsp
57 718b3ab0 2018-03-17 stsp /* The pack index cache speeds up search for packed objects. */
58 6c414261 2021-03-30 stsp struct got_packidx *packidx_cache[GOT_PACK_CACHE_SIZE];
59 718b3ab0 2018-03-17 stsp
60 b343c297 2021-10-11 stsp /*
61 b343c297 2021-10-11 stsp * List of bloom filters for pack index files.
62 b343c297 2021-10-11 stsp * Used to avoid opening a pack index in search of an
63 b343c297 2021-10-11 stsp * object ID which is not contained in this pack index.
64 b343c297 2021-10-11 stsp */
65 f8b19efd 2021-10-13 stsp struct got_packidx_bloom_filter_tree packidx_bloom_filters;
66 b343c297 2021-10-11 stsp
67 6c6d3ed3 2018-04-02 stsp /* Open file handles for pack files. */
68 718b3ab0 2018-03-17 stsp struct got_pack packs[GOT_PACK_CACHE_SIZE];
69 7bb0daa1 2018-06-21 stsp
70 6c414261 2021-03-30 stsp /*
71 6c414261 2021-03-30 stsp * The cache size limit may be lower than GOT_PACK_CACHE_SIZE,
72 6c414261 2021-03-30 stsp * depending on resource limits.
73 6c414261 2021-03-30 stsp */
74 6c414261 2021-03-30 stsp int pack_cache_size;
75 6c414261 2021-03-30 stsp
76 61af9b21 2022-06-28 stsp /*
77 61af9b21 2022-06-28 stsp * Index to cache entries which are pinned to avoid eviction.
78 61af9b21 2022-06-28 stsp * This may be used to keep one got-index-pack process alive
79 61af9b21 2022-06-28 stsp * across searches for arbitrary objects which may be stored
80 61af9b21 2022-06-28 stsp * in other pack files.
81 61af9b21 2022-06-28 stsp */
82 61af9b21 2022-06-28 stsp int pinned_pack;
83 61af9b21 2022-06-28 stsp pid_t pinned_pid;
84 61af9b21 2022-06-28 stsp int pinned_packidx;
85 61af9b21 2022-06-28 stsp
86 ad242220 2018-09-08 stsp /* Handles to child processes for reading loose objects. */
87 abc59930 2021-09-05 naddy struct got_privsep_child privsep_children[5];
88 ad242220 2018-09-08 stsp #define GOT_REPO_PRIVSEP_CHILD_OBJECT 0
89 ad242220 2018-09-08 stsp #define GOT_REPO_PRIVSEP_CHILD_COMMIT 1
90 ad242220 2018-09-08 stsp #define GOT_REPO_PRIVSEP_CHILD_TREE 2
91 ad242220 2018-09-08 stsp #define GOT_REPO_PRIVSEP_CHILD_BLOB 3
92 f4a881ce 2018-11-17 stsp #define GOT_REPO_PRIVSEP_CHILD_TAG 4
93 ad242220 2018-09-08 stsp
94 ad242220 2018-09-08 stsp /* Caches for open objects. */
95 54f20211 2018-06-22 stsp struct got_object_cache objcache;
96 f6be5c30 2018-06-22 stsp struct got_object_cache treecache;
97 1943de01 2018-06-22 stsp struct got_object_cache commitcache;
98 f4a881ce 2018-11-17 stsp struct got_object_cache tagcache;
99 d3c116bf 2021-10-15 stsp struct got_object_cache rawcache;
100 1d126e2d 2019-08-24 stsp
101 1d126e2d 2019-08-24 stsp /* Settings read from Git configuration files. */
102 aba9c984 2019-09-08 stsp int gitconfig_repository_format_version;
103 aba9c984 2019-09-08 stsp char *gitconfig_author_name;
104 aba9c984 2019-09-08 stsp char *gitconfig_author_email;
105 c9956ddf 2019-09-08 stsp char *global_gitconfig_author_name;
106 c9956ddf 2019-09-08 stsp char *global_gitconfig_author_email;
107 cd95becd 2019-11-29 stsp int ngitconfig_remotes;
108 cd95becd 2019-11-29 stsp struct got_remote_repo *gitconfig_remotes;
109 9a1cc63f 2020-02-03 stsp char *gitconfig_owner;
110 20b7abb3 2020-10-22 stsp char **extensions;
111 20b7abb3 2020-10-22 stsp int nextensions;
112 257add31 2020-09-09 stsp
113 257add31 2020-09-09 stsp /* Settings read from got.conf. */
114 50b0790e 2020-09-11 stsp struct got_gotconfig *gotconfig;
115 718b3ab0 2018-03-17 stsp };
116 7bb0daa1 2018-06-21 stsp
117 f6be5c30 2018-06-22 stsp const struct got_error*got_repo_cache_object(struct got_repository *,
118 f6be5c30 2018-06-22 stsp struct got_object_id *, struct got_object *);
119 7bb0daa1 2018-06-21 stsp struct got_object *got_repo_get_cached_object(struct got_repository *,
120 7bb0daa1 2018-06-21 stsp struct got_object_id *);
121 f6be5c30 2018-06-22 stsp const struct got_error*got_repo_cache_tree(struct got_repository *,
122 f6be5c30 2018-06-22 stsp struct got_object_id *, struct got_tree_object *);
123 f6be5c30 2018-06-22 stsp struct got_tree_object *got_repo_get_cached_tree(struct got_repository *,
124 f6be5c30 2018-06-22 stsp struct got_object_id *);
125 1943de01 2018-06-22 stsp const struct got_error*got_repo_cache_commit(struct got_repository *,
126 1943de01 2018-06-22 stsp struct got_object_id *, struct got_commit_object *);
127 1943de01 2018-06-22 stsp struct got_commit_object *got_repo_get_cached_commit(struct got_repository *,
128 1943de01 2018-06-22 stsp struct got_object_id *);
129 f4a881ce 2018-11-17 stsp const struct got_error*got_repo_cache_tag(struct got_repository *,
130 f4a881ce 2018-11-17 stsp struct got_object_id *, struct got_tag_object *);
131 f4a881ce 2018-11-17 stsp struct got_tag_object *got_repo_get_cached_tag(struct got_repository *,
132 f4a881ce 2018-11-17 stsp struct got_object_id *);
133 d3c116bf 2021-10-15 stsp const struct got_error*got_repo_cache_raw_object(struct got_repository *,
134 d3c116bf 2021-10-15 stsp struct got_object_id *, struct got_raw_object *);
135 d3c116bf 2021-10-15 stsp struct got_raw_object *got_repo_get_cached_raw_object(struct got_repository *,
136 d3c116bf 2021-10-15 stsp struct got_object_id *);
137 1124fe40 2021-07-07 stsp int got_repo_is_packidx_filename(const char *, size_t);
138 67fd6849 2022-02-13 stsp int got_repo_check_packidx_bloom_filter(struct got_repository *,
139 67fd6849 2022-02-13 stsp const char *, struct got_object_id *);
140 1510f469 2018-09-09 stsp const struct got_error *got_repo_search_packidx(struct got_packidx **, int *,
141 1510f469 2018-09-09 stsp struct got_repository *, struct got_object_id *);
142 67fd6849 2022-02-13 stsp const struct got_error *got_repo_list_packidx(struct got_pathlist_head *,
143 67fd6849 2022-02-13 stsp struct got_repository *);
144 67fd6849 2022-02-13 stsp const struct got_error *got_repo_get_packidx(struct got_packidx **, const char *,
145 67fd6849 2022-02-13 stsp struct got_repository *);
146 1510f469 2018-09-09 stsp const struct got_error *got_repo_cache_pack(struct got_pack **,
147 1510f469 2018-09-09 stsp struct got_repository *, const char *, struct got_packidx *);
148 61af9b21 2022-06-28 stsp struct got_pack *got_repo_get_cached_pack(struct got_repository *,
149 61af9b21 2022-06-28 stsp const char *);
150 61af9b21 2022-06-28 stsp const struct got_error *got_repo_pin_pack(struct got_repository *,
151 61af9b21 2022-06-28 stsp struct got_packidx *, struct got_pack *);
152 61af9b21 2022-06-28 stsp struct got_pack *got_repo_get_pinned_pack(struct got_repository *);
153 61af9b21 2022-06-28 stsp void got_repo_unpin_pack(struct got_repository *);
154 61af9b21 2022-06-28 stsp