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 718b3ab0 2018-03-17 stsp #define GOT_PACKIDX_CACHE_SIZE 64
18 718b3ab0 2018-03-17 stsp #define GOT_PACK_CACHE_SIZE GOT_PACKIDX_CACHE_SIZE
19 718b3ab0 2018-03-17 stsp
20 0a554478 2018-06-22 stsp #define GOT_OBJECT_CACHE_SIZE_OBJ 1024
21 0a554478 2018-06-22 stsp #define GOT_OBJECT_CACHE_SIZE_TREE 128
22 0a554478 2018-06-22 stsp #define GOT_OBJECT_CACHE_SIZE_COMMIT 512
23 7bb0daa1 2018-06-21 stsp
24 f6be5c30 2018-06-22 stsp enum got_object_chache_type {
25 f6be5c30 2018-06-22 stsp GOT_OBJECT_CACHE_TYPE_OBJ,
26 1943de01 2018-06-22 stsp GOT_OBJECT_CACHE_TYPE_TREE,
27 1943de01 2018-06-22 stsp GOT_OBJECT_CACHE_TYPE_COMMIT,
28 f6be5c30 2018-06-22 stsp };
29 f6be5c30 2018-06-22 stsp
30 54f20211 2018-06-22 stsp struct got_object_cache_entry {
31 7bb0daa1 2018-06-21 stsp struct got_object_id id;
32 f6be5c30 2018-06-22 stsp union {
33 f6be5c30 2018-06-22 stsp struct got_object *obj;
34 f6be5c30 2018-06-22 stsp struct got_tree_object *tree;
35 1943de01 2018-06-22 stsp struct got_commit_object *commit;
36 f6be5c30 2018-06-22 stsp } data;
37 7bb0daa1 2018-06-21 stsp };
38 7bb0daa1 2018-06-21 stsp
39 54f20211 2018-06-22 stsp struct got_object_cache {
40 f6be5c30 2018-06-22 stsp enum got_object_chache_type type;
41 eb77ee11 2018-07-08 stsp struct got_object_idcache *idcache;
42 4307e577 2018-06-22 stsp size_t size;
43 54f20211 2018-06-22 stsp int cache_hit;
44 54f20211 2018-06-22 stsp int cache_miss;
45 54f20211 2018-06-22 stsp };
46 54f20211 2018-06-22 stsp
47 718b3ab0 2018-03-17 stsp struct got_repository {
48 718b3ab0 2018-03-17 stsp char *path;
49 718b3ab0 2018-03-17 stsp char *path_git_dir;
50 718b3ab0 2018-03-17 stsp
51 718b3ab0 2018-03-17 stsp /* The pack index cache speeds up search for packed objects. */
52 6fd11751 2018-06-04 stsp struct got_packidx *packidx_cache[GOT_PACKIDX_CACHE_SIZE];
53 718b3ab0 2018-03-17 stsp
54 6c6d3ed3 2018-04-02 stsp /* Open file handles for pack files. */
55 718b3ab0 2018-03-17 stsp struct got_pack packs[GOT_PACK_CACHE_SIZE];
56 7bb0daa1 2018-06-21 stsp
57 ad242220 2018-09-08 stsp /* Handles to child processes for reading loose objects. */
58 ad242220 2018-09-08 stsp struct got_privsep_child privsep_children[4];
59 ad242220 2018-09-08 stsp #define GOT_REPO_PRIVSEP_CHILD_OBJECT 0
60 ad242220 2018-09-08 stsp #define GOT_REPO_PRIVSEP_CHILD_COMMIT 1
61 ad242220 2018-09-08 stsp #define GOT_REPO_PRIVSEP_CHILD_TREE 2
62 ad242220 2018-09-08 stsp #define GOT_REPO_PRIVSEP_CHILD_BLOB 3
63 ad242220 2018-09-08 stsp
64 ad242220 2018-09-08 stsp /* Caches for open objects. */
65 54f20211 2018-06-22 stsp struct got_object_cache objcache;
66 f6be5c30 2018-06-22 stsp struct got_object_cache treecache;
67 1943de01 2018-06-22 stsp struct got_object_cache commitcache;
68 718b3ab0 2018-03-17 stsp };
69 7bb0daa1 2018-06-21 stsp
70 f6be5c30 2018-06-22 stsp const struct got_error*got_repo_cache_object(struct got_repository *,
71 f6be5c30 2018-06-22 stsp struct got_object_id *, struct got_object *);
72 7bb0daa1 2018-06-21 stsp struct got_object *got_repo_get_cached_object(struct got_repository *,
73 7bb0daa1 2018-06-21 stsp struct got_object_id *);
74 f6be5c30 2018-06-22 stsp const struct got_error*got_repo_cache_tree(struct got_repository *,
75 f6be5c30 2018-06-22 stsp struct got_object_id *, struct got_tree_object *);
76 f6be5c30 2018-06-22 stsp struct got_tree_object *got_repo_get_cached_tree(struct got_repository *,
77 f6be5c30 2018-06-22 stsp struct got_object_id *);
78 1943de01 2018-06-22 stsp const struct got_error*got_repo_cache_commit(struct got_repository *,
79 1943de01 2018-06-22 stsp struct got_object_id *, struct got_commit_object *);
80 1943de01 2018-06-22 stsp struct got_commit_object *got_repo_get_cached_commit(struct got_repository *,
81 1943de01 2018-06-22 stsp struct got_object_id *);
82 1510f469 2018-09-09 stsp const struct got_error *got_repo_cache_packidx(struct got_repository *,
83 1510f469 2018-09-09 stsp struct got_packidx *);
84 1510f469 2018-09-09 stsp const struct got_error *got_repo_search_packidx(struct got_packidx **, int *,
85 1510f469 2018-09-09 stsp struct got_repository *, struct got_object_id *);
86 1510f469 2018-09-09 stsp const struct got_error *got_repo_cache_pack(struct got_pack **,
87 1510f469 2018-09-09 stsp struct got_repository *, const char *, struct got_packidx *);