Blob


1 /*
2 * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
3 *
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.
7 *
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.
15 */
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 *);
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 *);
29 /*
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().
32 */
33 const char *got_repo_get_path_git_dir(struct got_repository *);
35 /* Obtain the commit author name if parsed from gitconfig, else NULL. */
36 const char *got_repo_get_gitconfig_author_name(struct got_repository *);
38 /* Obtain the commit author email if parsed from gitconfig, else NULL. */
39 const char *got_repo_get_gitconfig_author_email(struct got_repository *);
41 /* Obtain global commit author name parsed ~/.gitconfig, else NULL. */
42 const char *got_repo_get_global_gitconfig_author_name(struct got_repository *);
44 /* Obtain global commit author email parsed ~/.gitconfig, else NULL. */
45 const char *got_repo_get_global_gitconfig_author_email(struct got_repository *);
47 /* Obtain repository owner name if parsed from gitconfig, else NULL. */
48 const char *got_repo_get_gitconfig_owner(struct got_repository *);
50 /* Information about one remote repository. */
51 struct got_remote_repo {
52 char *name;
53 char *url;
54 };
56 /* Obtain the list of remote repositories parsed from gitconfig. */
57 void got_repo_get_gitconfig_remotes(int *, struct got_remote_repo **,
58 struct got_repository *);
60 /*
61 * Obtain paths to various directories within a repository.
62 * The caller must dispose of a path with free(3).
63 */
64 char *got_repo_get_path_objects(struct got_repository *);
65 char *got_repo_get_path_objects_pack(struct got_repository *);
66 char *got_repo_get_path_refs(struct got_repository *);
67 char *got_repo_get_path_packed_refs(struct got_repository *);
68 char *got_repo_get_path_gitconfig(struct got_repository *);
70 struct got_reference;
72 /*
73 * Obtain a reference, by name, from a repository.
74 * The caller must dispose of it with got_ref_close().
75 */
76 const struct got_error *got_repo_get_reference(struct got_reference **,
77 struct got_repository *, const char *);
80 /* Indicate whether this is a bare repositiry (contains no git working tree). */
81 int got_repo_is_bare(struct got_repository *);
83 /* Attempt to map an arbitrary path to a path within the repository. */
84 const struct got_error *got_repo_map_path(char **, struct got_repository *,
85 const char *, int);
87 /* Create a new repository in an empty directory at a specified path. */
88 const struct got_error *got_repo_init(const char *);
90 /* Attempt to find a unique object ID for a given ID string prefix. */
91 const struct got_error *got_repo_match_object_id_prefix(struct got_object_id **,
92 const char *, int, struct got_repository *);
94 /*
95 * Given an object ID string or reference name, attempt to find a corresponding
96 * commit object. Tags can optionally be ignored during matching.
97 * The object type may be restricted to commit, tree, blob, or tag.
98 * GOT_OBJ_TYPE_ANY will match any type of object.
99 * A human-readable label can optionally be returned, which the caller should
100 * dispose of with free(3).
101 * Return GOT_ERR_NO_OBJ if no matching commit can be found.
102 */
103 const struct got_error *got_repo_match_object_id(struct got_object_id **,
104 char **, const char *, int, int, struct got_repository *);
106 /*
107 * Attempt to find a tag object with a given name and target object type.
108 * Return GOT_ERR_NO_OBJ if no matching tag can be found.
109 */
110 const struct got_error *got_repo_object_match_tag(struct got_tag_object **,
111 const char *, int, struct got_repository *);
113 /* A callback function which is invoked when a path is imported. */
114 typedef const struct got_error *(*got_repo_import_cb)(void *, const char *);
116 /*
117 * Import an unversioned directory tree into the repository.
118 * Creates a root commit, i.e. a commit with zero parents.
119 */
120 const struct got_error *got_repo_import(struct got_object_id **, const char *,
121 const char *, const char *, struct got_pathlist_head *,
122 struct got_repository *, got_repo_import_cb, void *);