Blame


1 7b19e0f1 2017-11-05 stsp /*
2 5d56da81 2019-01-13 stsp * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
3 7b19e0f1 2017-11-05 stsp *
4 7b19e0f1 2017-11-05 stsp * Permission to use, copy, modify, and distribute this software for any
5 7b19e0f1 2017-11-05 stsp * purpose with or without fee is hereby granted, provided that the above
6 7b19e0f1 2017-11-05 stsp * copyright notice and this permission notice appear in all copies.
7 7b19e0f1 2017-11-05 stsp *
8 7b19e0f1 2017-11-05 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 7b19e0f1 2017-11-05 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 7b19e0f1 2017-11-05 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 7b19e0f1 2017-11-05 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 7b19e0f1 2017-11-05 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 7b19e0f1 2017-11-05 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 7b19e0f1 2017-11-05 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 7b19e0f1 2017-11-05 stsp */
16 7b19e0f1 2017-11-05 stsp
17 3b339b2f 2018-02-12 stsp struct got_repository;
18 3ce1b845 2019-07-15 stsp struct got_pathlist_head;
19 303e2782 2019-08-09 stsp struct got_tag_object;
20 4027f31a 2017-11-04 stsp
21 0c60ce5a 2018-04-02 stsp /* Open and close repositories. */
22 c9956ddf 2019-09-08 stsp const struct got_error *got_repo_open(struct got_repository**, const char *,
23 0ae84acc 2022-06-15 tracey const char *, int *);
24 ad242220 2018-09-08 stsp const struct got_error *got_repo_close(struct got_repository*);
25 4027f31a 2017-11-04 stsp
26 4b0bb327 2019-01-06 stsp /* Obtain the on-disk path to the repository. */
27 7839bc15 2019-01-06 stsp const char *got_repo_get_path(struct got_repository *);
28 4b0bb327 2019-01-06 stsp
29 4b0bb327 2019-01-06 stsp /*
30 4b0bb327 2019-01-06 stsp * Obtain the path to a non-bare repository's .git directory.
31 4b0bb327 2019-01-06 stsp * For bare repositories, this returns the same result as got_repo_get_path().
32 4b0bb327 2019-01-06 stsp */
33 6e9da951 2019-01-06 stsp const char *got_repo_get_path_git_dir(struct got_repository *);
34 7839bc15 2019-01-06 stsp
35 6d5a9006 2020-12-16 yzhong /* Obtain the file descriptor of the repository's .git directory. */
36 6d5a9006 2020-12-16 yzhong int got_repo_get_fd(struct got_repository *);
37 6d5a9006 2020-12-16 yzhong
38 b54930d5 2023-02-28 op /* Obtain the object format */
39 b54930d5 2023-02-28 op enum got_hash_algorithm got_repo_get_object_format(struct got_repository *);
40 b54930d5 2023-02-28 op
41 aba9c984 2019-09-08 stsp /* Obtain the commit author name if parsed from gitconfig, else NULL. */
42 aba9c984 2019-09-08 stsp const char *got_repo_get_gitconfig_author_name(struct got_repository *);
43 aba9c984 2019-09-08 stsp
44 aba9c984 2019-09-08 stsp /* Obtain the commit author email if parsed from gitconfig, else NULL. */
45 aba9c984 2019-09-08 stsp const char *got_repo_get_gitconfig_author_email(struct got_repository *);
46 aba9c984 2019-09-08 stsp
47 c9956ddf 2019-09-08 stsp /* Obtain global commit author name parsed ~/.gitconfig, else NULL. */
48 c9956ddf 2019-09-08 stsp const char *got_repo_get_global_gitconfig_author_name(struct got_repository *);
49 c9956ddf 2019-09-08 stsp
50 c9956ddf 2019-09-08 stsp /* Obtain global commit author email parsed ~/.gitconfig, else NULL. */
51 c9956ddf 2019-09-08 stsp const char *got_repo_get_global_gitconfig_author_email(struct got_repository *);
52 c9956ddf 2019-09-08 stsp
53 9a1cc63f 2020-02-03 stsp /* Obtain repository owner name if parsed from gitconfig, else NULL. */
54 9a1cc63f 2020-02-03 stsp const char *got_repo_get_gitconfig_owner(struct got_repository *);
55 9a1cc63f 2020-02-03 stsp
56 798586ca 2023-02-05 op /* Query if a given Git extension is enabled in gitconfig. */
57 798586ca 2023-02-05 op int got_repo_has_extension(struct got_repository *, const char *);
58 9188bd78 2021-07-03 stsp
59 cd95becd 2019-11-29 stsp /* Information about one remote repository. */
60 cd95becd 2019-11-29 stsp struct got_remote_repo {
61 cd95becd 2019-11-29 stsp char *name;
62 6480c871 2021-08-30 stsp char *fetch_url;
63 6480c871 2021-08-30 stsp char *send_url;
64 b8adfa55 2020-09-25 stsp
65 469dd726 2020-03-20 stsp /*
66 6480c871 2021-08-30 stsp * If set, fetched references are mirrored 1:1 into our repository.
67 469dd726 2020-03-20 stsp * If not set, references are mapped into "refs/remotes/$name/".
68 469dd726 2020-03-20 stsp */
69 469dd726 2020-03-20 stsp int mirror_references;
70 b8adfa55 2020-09-25 stsp
71 0c8b29c5 2021-01-05 stsp /*
72 0c8b29c5 2021-01-05 stsp * If set, fetch all branches by default and ignore the list of
73 0c8b29c5 2021-01-05 stsp * branches below.
74 0c8b29c5 2021-01-05 stsp */
75 0c8b29c5 2021-01-05 stsp int fetch_all_branches;
76 0c8b29c5 2021-01-05 stsp
77 b8adfa55 2020-09-25 stsp /* Branches to fetch by default. */
78 6480c871 2021-08-30 stsp int nfetch_branches;
79 6480c871 2021-08-30 stsp char **fetch_branches;
80 99495ddb 2021-01-10 stsp
81 6480c871 2021-08-30 stsp /* Branches to send by default. */
82 6480c871 2021-08-30 stsp int nsend_branches;
83 6480c871 2021-08-30 stsp char **send_branches;
84 6480c871 2021-08-30 stsp
85 99495ddb 2021-01-10 stsp /* Other arbitrary references to fetch by default. */
86 6480c871 2021-08-30 stsp int nfetch_refs;
87 6480c871 2021-08-30 stsp char **fetch_refs;
88 cd95becd 2019-11-29 stsp };
89 cd95becd 2019-11-29 stsp
90 b8adfa55 2020-09-25 stsp /*
91 db82695e 2023-09-05 stsp * Return a deep copy of a given remote_repo. The result should be
92 db82695e 2023-09-05 stsp * freed with got_repo_free_remote_repo_data() and then free(3).
93 db82695e 2023-09-05 stsp * Return NULL on failure.
94 db82695e 2023-09-05 stsp */
95 db82695e 2023-09-05 stsp const struct got_error *got_repo_remote_repo_dup(struct got_remote_repo **,
96 db82695e 2023-09-05 stsp const struct got_remote_repo *);
97 db82695e 2023-09-05 stsp
98 db82695e 2023-09-05 stsp /*
99 b8adfa55 2020-09-25 stsp * Free data allocated for the specified remote repository.
100 b8adfa55 2020-09-25 stsp * Do not free the remote_repo pointer itself.
101 b8adfa55 2020-09-25 stsp */
102 b8adfa55 2020-09-25 stsp void got_repo_free_remote_repo_data(struct got_remote_repo *);
103 b8adfa55 2020-09-25 stsp
104 b8adfa55 2020-09-25 stsp /* Obtain the list of remote repositories parsed from gitconfig. */
105 50b0790e 2020-09-11 stsp void got_repo_get_gitconfig_remotes(int *, const struct got_remote_repo **,
106 cd95becd 2019-11-29 stsp struct got_repository *);
107 cd95becd 2019-11-29 stsp
108 50b0790e 2020-09-11 stsp /*
109 50b0790e 2020-09-11 stsp * Obtain a parsed representation of this repository's got.conf file.
110 50b0790e 2020-09-11 stsp * Return NULL if this configuration file could not be read.
111 50b0790e 2020-09-11 stsp */
112 50b0790e 2020-09-11 stsp const struct got_gotconfig *got_repo_get_gotconfig(struct got_repository *);
113 257add31 2020-09-09 stsp
114 0c60ce5a 2018-04-02 stsp /*
115 0c60ce5a 2018-04-02 stsp * Obtain paths to various directories within a repository.
116 0c60ce5a 2018-04-02 stsp * The caller must dispose of a path with free(3).
117 0c60ce5a 2018-04-02 stsp */
118 11995603 2017-11-05 stsp char *got_repo_get_path_objects(struct got_repository *);
119 a1fd68d8 2018-01-12 stsp char *got_repo_get_path_objects_pack(struct got_repository *);
120 11995603 2017-11-05 stsp char *got_repo_get_path_refs(struct got_repository *);
121 fb79db15 2019-02-01 stsp char *got_repo_get_path_packed_refs(struct got_repository *);
122 b46f3e71 2020-03-18 stsp char *got_repo_get_path_gitconfig(struct got_repository *);
123 257add31 2020-09-09 stsp char *got_repo_get_path_gotconfig(struct got_repository *);
124 11995603 2017-11-05 stsp
125 11995603 2017-11-05 stsp struct got_reference;
126 84de9106 2020-12-26 stsp struct got_reflist_head;
127 11995603 2017-11-05 stsp
128 0c60ce5a 2018-04-02 stsp /*
129 0c60ce5a 2018-04-02 stsp * Obtain a reference, by name, from a repository.
130 0c60ce5a 2018-04-02 stsp * The caller must dispose of it with got_ref_close().
131 0c60ce5a 2018-04-02 stsp */
132 4027f31a 2017-11-04 stsp const struct got_error *got_repo_get_reference(struct got_reference **,
133 4027f31a 2017-11-04 stsp struct got_repository *, const char *);
134 04ca23f4 2018-07-16 stsp
135 04ca23f4 2018-07-16 stsp
136 04ca23f4 2018-07-16 stsp /* Indicate whether this is a bare repositiry (contains no git working tree). */
137 04ca23f4 2018-07-16 stsp int got_repo_is_bare(struct got_repository *);
138 04ca23f4 2018-07-16 stsp
139 04ca23f4 2018-07-16 stsp /* Attempt to map an arbitrary path to a path within the repository. */
140 04ca23f4 2018-07-16 stsp const struct got_error *got_repo_map_path(char **, struct got_repository *,
141 8fa913ec 2020-11-14 stsp const char *);
142 2c7829a4 2019-06-17 stsp
143 6f04a73d 2022-09-20 mark /*
144 6f04a73d 2022-09-20 mark * Create a new repository with optional specified
145 6f04a73d 2022-09-20 mark * HEAD ref in an empty directory at a specified path.
146 6f04a73d 2022-09-20 mark */
147 6f04a73d 2022-09-20 mark const struct got_error *got_repo_init(const char *, const char *);
148 e09a504c 2019-06-28 stsp
149 e09a504c 2019-06-28 stsp /* Attempt to find a unique object ID for a given ID string prefix. */
150 e09a504c 2019-06-28 stsp const struct got_error *got_repo_match_object_id_prefix(struct got_object_id **,
151 dd88155e 2019-06-29 stsp const char *, int, struct got_repository *);
152 3ce1b845 2019-07-15 stsp
153 303e2782 2019-08-09 stsp /*
154 71a27632 2020-01-15 stsp * Given an object ID string or reference name, attempt to find a corresponding
155 4be911ed 2022-03-10 stsp * object.
156 71a27632 2020-01-15 stsp * The object type may be restricted to commit, tree, blob, or tag.
157 84de9106 2020-12-26 stsp * Tags will only be matched if a list of references is provided.
158 71a27632 2020-01-15 stsp * GOT_OBJ_TYPE_ANY will match any type of object.
159 71a27632 2020-01-15 stsp * A human-readable label can optionally be returned, which the caller should
160 71a27632 2020-01-15 stsp * dispose of with free(3).
161 71a27632 2020-01-15 stsp * Return GOT_ERR_NO_OBJ if no matching commit can be found.
162 71a27632 2020-01-15 stsp */
163 71a27632 2020-01-15 stsp const struct got_error *got_repo_match_object_id(struct got_object_id **,
164 84de9106 2020-12-26 stsp char **, const char *, int, struct got_reflist_head *,
165 84de9106 2020-12-26 stsp struct got_repository *);
166 71a27632 2020-01-15 stsp
167 71a27632 2020-01-15 stsp /*
168 84de9106 2020-12-26 stsp * Search the provided list of references for a tag with a given name
169 84de9106 2020-12-26 stsp * and target object type.
170 303e2782 2019-08-09 stsp * Return GOT_ERR_NO_OBJ if no matching tag can be found.
171 303e2782 2019-08-09 stsp */
172 303e2782 2019-08-09 stsp const struct got_error *got_repo_object_match_tag(struct got_tag_object **,
173 84de9106 2020-12-26 stsp const char *, int, struct got_reflist_head *, struct got_repository *);
174 303e2782 2019-08-09 stsp
175 3ce1b845 2019-07-15 stsp /* A callback function which is invoked when a path is imported. */
176 3ce1b845 2019-07-15 stsp typedef const struct got_error *(*got_repo_import_cb)(void *, const char *);
177 3ce1b845 2019-07-15 stsp
178 3ce1b845 2019-07-15 stsp /*
179 3ce1b845 2019-07-15 stsp * Import an unversioned directory tree into the repository.
180 3ce1b845 2019-07-15 stsp * Creates a root commit, i.e. a commit with zero parents.
181 3ce1b845 2019-07-15 stsp */
182 3ce1b845 2019-07-15 stsp const struct got_error *got_repo_import(struct got_object_id **, const char *,
183 3ce1b845 2019-07-15 stsp const char *, const char *, struct got_pathlist_head *,
184 3ce1b845 2019-07-15 stsp struct got_repository *, got_repo_import_cb, void *);
185 20662ea0 2021-04-10 stsp
186 20662ea0 2021-04-10 stsp /* Obtain the number and size of loose objects in the repository. */
187 20662ea0 2021-04-10 stsp const struct got_error *got_repo_get_loose_object_info(int *nobjects,
188 20662ea0 2021-04-10 stsp off_t *ondisk_size, struct got_repository *);
189 20662ea0 2021-04-10 stsp
190 20662ea0 2021-04-10 stsp /* Obtain the number and size of packed objects in the repository. */
191 20662ea0 2021-04-10 stsp const struct got_error *got_repo_get_packfile_info(int *npackfiles,
192 20662ea0 2021-04-10 stsp int *nobjects, off_t *total_packsize, struct got_repository *);
193 0ae84acc 2022-06-15 tracey
194 0ae84acc 2022-06-15 tracey /* Create an array of file descriptors to hand over to got_repo_open for pack */
195 0ae84acc 2022-06-15 tracey const struct got_error *got_repo_pack_fds_open(int **);
196 0ae84acc 2022-06-15 tracey
197 0ae84acc 2022-06-15 tracey /* Close the array of file descriptors handed over to got_repo_open for pack */
198 0ae84acc 2022-06-15 tracey const struct got_error *got_repo_pack_fds_close(int *);
199 13b2bc37 2022-10-23 stsp
200 13b2bc37 2022-10-23 stsp /* Open/set/close temporary files for internal use. Needed by gotd(8). */
201 13b2bc37 2022-10-23 stsp const struct got_error *got_repo_temp_fds_open(int **);
202 13b2bc37 2022-10-23 stsp void got_repo_temp_fds_set(struct got_repository *, int *);
203 13b2bc37 2022-10-23 stsp const struct got_error *got_repo_temp_fds_close(int *);