portable: release 0.93
[got-portable.git] / include / got_repository.h
blobc53bf9434590b858c1ce59018954e81ff934dfc1
1 /*
2 * Copyright (c) 2018, 2019 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 struct got_repository;
18 struct got_pathlist_head;
19 struct got_tag_object;
21 /* Open and close repositories. */
22 const struct got_error *got_repo_open(struct got_repository**, const char *,
23 const char *, int *);
24 const struct got_error *got_repo_close(struct got_repository*);
26 /* Obtain the on-disk path to the repository. */
27 const char *got_repo_get_path(struct got_repository *);
30 * Obtain the path to a non-bare repository's .git directory.
31 * For bare repositories, this returns the same result as got_repo_get_path().
33 const char *got_repo_get_path_git_dir(struct got_repository *);
35 /* Obtain the file descriptor of the repository's .git directory. */
36 int got_repo_get_fd(struct got_repository *);
38 /* Obtain the object format */
39 enum got_hash_algorithm got_repo_get_object_format(struct got_repository *);
41 /* Obtain the commit author name if parsed from gitconfig, else NULL. */
42 const char *got_repo_get_gitconfig_author_name(struct got_repository *);
44 /* Obtain the commit author email if parsed from gitconfig, else NULL. */
45 const char *got_repo_get_gitconfig_author_email(struct got_repository *);
47 /* Obtain global commit author name parsed ~/.gitconfig, else NULL. */
48 const char *got_repo_get_global_gitconfig_author_name(struct got_repository *);
50 /* Obtain global commit author email parsed ~/.gitconfig, else NULL. */
51 const char *got_repo_get_global_gitconfig_author_email(struct got_repository *);
53 /* Obtain repository owner name if parsed from gitconfig, else NULL. */
54 const char *got_repo_get_gitconfig_owner(struct got_repository *);
56 /* Query if a given Git extension is enabled in gitconfig. */
57 int got_repo_has_extension(struct got_repository *, const char *);
59 /* Information about one remote repository. */
60 struct got_remote_repo {
61 char *name;
62 char *fetch_url;
63 char *send_url;
66 * If set, fetched references are mirrored 1:1 into our repository.
67 * If not set, references are mapped into "refs/remotes/$name/".
69 int mirror_references;
72 * If set, fetch all branches by default and ignore the list of
73 * branches below.
75 int fetch_all_branches;
77 /* Branches to fetch by default. */
78 int nfetch_branches;
79 char **fetch_branches;
81 /* Branches to send by default. */
82 int nsend_branches;
83 char **send_branches;
85 /* Other arbitrary references to fetch by default. */
86 int nfetch_refs;
87 char **fetch_refs;
91 * Return a deep copy of a given remote_repo. The result should be
92 * freed with got_repo_free_remote_repo_data() and then free(3).
93 * Return NULL on failure.
95 const struct got_error *got_repo_remote_repo_dup(struct got_remote_repo **,
96 const struct got_remote_repo *);
99 * Free data allocated for the specified remote repository.
100 * Do not free the remote_repo pointer itself.
102 void got_repo_free_remote_repo_data(struct got_remote_repo *);
104 /* Obtain the list of remote repositories parsed from gitconfig. */
105 void got_repo_get_gitconfig_remotes(int *, const struct got_remote_repo **,
106 struct got_repository *);
109 * Obtain a parsed representation of this repository's got.conf file.
110 * Return NULL if this configuration file could not be read.
112 const struct got_gotconfig *got_repo_get_gotconfig(struct got_repository *);
115 * Obtain paths to various directories within a repository.
116 * The caller must dispose of a path with free(3).
118 char *got_repo_get_path_objects(struct got_repository *);
119 char *got_repo_get_path_objects_pack(struct got_repository *);
120 char *got_repo_get_path_refs(struct got_repository *);
121 char *got_repo_get_path_packed_refs(struct got_repository *);
122 char *got_repo_get_path_gitconfig(struct got_repository *);
123 char *got_repo_get_path_gotconfig(struct got_repository *);
125 struct got_reference;
126 struct got_reflist_head;
129 * Obtain a reference, by name, from a repository.
130 * The caller must dispose of it with got_ref_close().
132 const struct got_error *got_repo_get_reference(struct got_reference **,
133 struct got_repository *, const char *);
136 /* Indicate whether this is a bare repositiry (contains no git working tree). */
137 int got_repo_is_bare(struct got_repository *);
139 /* Attempt to map an arbitrary path to a path within the repository. */
140 const struct got_error *got_repo_map_path(char **, struct got_repository *,
141 const char *);
144 * Create a new repository with optional specified
145 * HEAD ref in an empty directory at a specified path.
147 const struct got_error *got_repo_init(const char *, const char *);
149 /* Attempt to find a unique object ID for a given ID string prefix. */
150 const struct got_error *got_repo_match_object_id_prefix(struct got_object_id **,
151 const char *, int, struct got_repository *);
154 * Given an object ID string or reference name, attempt to find a corresponding
155 * object.
156 * The object type may be restricted to commit, tree, blob, or tag.
157 * Tags will only be matched if a list of references is provided.
158 * GOT_OBJ_TYPE_ANY will match any type of object.
159 * A human-readable label can optionally be returned, which the caller should
160 * dispose of with free(3).
161 * Return GOT_ERR_NO_OBJ if no matching commit can be found.
163 const struct got_error *got_repo_match_object_id(struct got_object_id **,
164 char **, const char *, int, struct got_reflist_head *,
165 struct got_repository *);
168 * Search the provided list of references for a tag with a given name
169 * and target object type.
170 * Return GOT_ERR_NO_OBJ if no matching tag can be found.
172 const struct got_error *got_repo_object_match_tag(struct got_tag_object **,
173 const char *, int, struct got_reflist_head *, struct got_repository *);
175 /* A callback function which is invoked when a path is imported. */
176 typedef const struct got_error *(*got_repo_import_cb)(void *, const char *);
179 * Import an unversioned directory tree into the repository.
180 * Creates a root commit, i.e. a commit with zero parents.
182 const struct got_error *got_repo_import(struct got_object_id **, const char *,
183 const char *, const char *, struct got_pathlist_head *,
184 struct got_repository *, got_repo_import_cb, void *);
186 /* Obtain the number and size of loose objects in the repository. */
187 const struct got_error *got_repo_get_loose_object_info(int *nobjects,
188 off_t *ondisk_size, struct got_repository *);
190 /* Obtain the number and size of packed objects in the repository. */
191 const struct got_error *got_repo_get_packfile_info(int *npackfiles,
192 int *nobjects, off_t *total_packsize, struct got_repository *);
194 /* Create an array of file descriptors to hand over to got_repo_open for pack */
195 const struct got_error *got_repo_pack_fds_open(int **);
197 /* Close the array of file descriptors handed over to got_repo_open for pack */
198 const struct got_error *got_repo_pack_fds_close(int *);
200 /* Open/set/close temporary files for internal use. Needed by gotd(8). */
201 const struct got_error *got_repo_temp_fds_open(int **);
202 void got_repo_temp_fds_set(struct got_repository *, int *);
203 const struct got_error *got_repo_temp_fds_close(int *);