Blob


1 /*
2 * Copyright (c) 2018 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 /* A reference which points to an arbitrary object. */
18 struct got_reference;
20 /* Well-known reference names. */
21 #define GOT_REF_HEAD "HEAD"
22 #define GOT_REF_ORIG_HEAD "ORIG_HEAD"
23 #define GOT_REF_MERGE_HEAD "MERGE_HEAD"
24 #define GOT_REF_FETCH_HEAD "FETCH_HEAD"
26 struct got_repository;
27 struct got_object_id;
29 /*
30 * Attempt to open the reference with the provided name in a repository.
31 * The caller must dispose of it with got_ref_close().
32 */
33 const struct got_error *got_ref_open(struct got_reference **,
34 struct got_repository *, const char *);
36 /*
37 * Allocate a new reference for a given object ID.
38 * The caller must dispose of it with got_ref_close().
39 */
40 const struct got_error *got_ref_alloc(struct got_reference **, const char *,
41 struct got_object_id *);
43 /* Dispose of a reference. */
44 void got_ref_close(struct got_reference *);
46 /* Get the name of the reference. */
47 const char *got_ref_get_name(struct got_reference *);
49 /*
50 * Create a duplicate copy of a reference.
51 * The caller must dispose of this copy with got_ref_close().
52 */
53 struct got_reference *got_ref_dup(struct got_reference *);
55 /* Attempt to resolve a reference to an object ID. */
56 const struct got_error *got_ref_resolve(struct got_object_id **,
57 struct got_repository *, struct got_reference *);
59 /*
60 * Return a string representation of a reference.
61 * The caller must dispose of it with free(3).
62 */
63 char *got_ref_to_str(struct got_reference *);
65 /* A list of references and the object ID which they resolve to. */
66 struct got_reflist_entry {
67 SIMPLEQ_ENTRY(got_reflist_entry) entry;
68 struct got_reference *ref;
69 struct got_object_id *id;
70 };
71 SIMPLEQ_HEAD(got_reflist_head, got_reflist_entry);
73 /* Append all known references to a caller-provided ref list head. */
74 const struct got_error *got_ref_list(struct got_reflist_head *,
75 struct got_repository *);
77 /* Free all references on a ref list. */
78 void got_ref_list_free(struct got_reflist_head *);
80 /* Indicate whether the provided reference is symbolic (points at another
81 * refernce) or not (points at an object ID). */
82 int got_ref_is_symbolic(struct got_reference *);
84 /* Change the object ID a reference points to. */
85 const struct got_error *
86 got_ref_change_ref(struct got_reference *, struct got_object_id *);
88 /* Change the reference name a symbolic reference points to. */
89 const struct got_error *got_ref_change_symref(struct got_reference *,
90 char *);
92 /* Write a reference to its on-disk path in the repository. */
93 const struct got_error *got_ref_write(struct got_reference *,
94 struct got_repository *);
96 /* Delete a reference from its on-disk path in the repository. */
97 const struct got_error *got_ref_delete(struct got_reference *,
98 struct got_repository *);