2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
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.
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.
17 #define GOT_GIT_DIR ".git"
19 /* Mandatory files and directories inside the git directory. */
20 #define GOT_OBJECTS_DIR "objects"
21 #define GOT_REFS_DIR "refs"
22 #define GOT_HEAD_FILE "HEAD"
23 #define GOT_GITCONFIG "config"
25 /* Other files and directories inside the git directory. */
26 #define GOT_FETCH_HEAD_FILE "FETCH_HEAD"
27 #define GOT_ORIG_HEAD_FILE "ORIG_HEAD"
28 #define GOT_OBJECTS_PACK_DIR "objects/pack"
29 #define GOT_PACKED_REFS_FILE "packed-refs"
31 #define GOT_PACK_CACHE_SIZE 64
33 struct got_repository
{
38 /* The pack index cache speeds up search for packed objects. */
39 struct got_packidx
*packidx_cache
[GOT_PACK_CACHE_SIZE
];
41 /* Open file handles for pack files. */
42 struct got_pack packs
[GOT_PACK_CACHE_SIZE
];
45 * The cache size limit may be lower than GOT_PACK_CACHE_SIZE,
46 * depending on resource limits.
50 /* Handles to child processes for reading loose objects. */
51 struct got_privsep_child privsep_children
[5];
52 #define GOT_REPO_PRIVSEP_CHILD_OBJECT 0
53 #define GOT_REPO_PRIVSEP_CHILD_COMMIT 1
54 #define GOT_REPO_PRIVSEP_CHILD_TREE 2
55 #define GOT_REPO_PRIVSEP_CHILD_BLOB 3
56 #define GOT_REPO_PRIVSEP_CHILD_TAG 4
58 /* Caches for open objects. */
59 struct got_object_cache objcache
;
60 struct got_object_cache treecache
;
61 struct got_object_cache commitcache
;
62 struct got_object_cache tagcache
;
64 /* Settings read from Git configuration files. */
65 int gitconfig_repository_format_version
;
66 char *gitconfig_author_name
;
67 char *gitconfig_author_email
;
68 char *global_gitconfig_author_name
;
69 char *global_gitconfig_author_email
;
70 int ngitconfig_remotes
;
71 struct got_remote_repo
*gitconfig_remotes
;
72 char *gitconfig_owner
;
76 /* Settings read from got.conf. */
77 struct got_gotconfig
*gotconfig
;
80 const struct got_error
*got_repo_cache_object(struct got_repository
*,
81 struct got_object_id
*, struct got_object
*);
82 struct got_object
*got_repo_get_cached_object(struct got_repository
*,
83 struct got_object_id
*);
84 const struct got_error
*got_repo_cache_tree(struct got_repository
*,
85 struct got_object_id
*, struct got_tree_object
*);
86 struct got_tree_object
*got_repo_get_cached_tree(struct got_repository
*,
87 struct got_object_id
*);
88 const struct got_error
*got_repo_cache_commit(struct got_repository
*,
89 struct got_object_id
*, struct got_commit_object
*);
90 struct got_commit_object
*got_repo_get_cached_commit(struct got_repository
*,
91 struct got_object_id
*);
92 const struct got_error
*got_repo_cache_tag(struct got_repository
*,
93 struct got_object_id
*, struct got_tag_object
*);
94 struct got_tag_object
*got_repo_get_cached_tag(struct got_repository
*,
95 struct got_object_id
*);
96 int got_repo_is_packidx_filename(const char *, size_t);
97 const struct got_error
*got_repo_search_packidx(struct got_packidx
**, int *,
98 struct got_repository
*, struct got_object_id
*);
99 const struct got_error
*got_repo_cache_pack(struct got_pack
**,
100 struct got_repository
*, const char *, struct got_packidx
*);