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 the reference with got_ref_close().
32 * Optionally, the underlying reference file can be locked before it is opened
33 * to prevent concurrent modification of the reference, in which case the file
34 * must be unlocked with got_ref_unlock() before got_ref_close() is called.
35 */
36 const struct got_error *got_ref_open(struct got_reference **,
37 struct got_repository *, const char *, int);
39 /*
40 * Allocate a new reference for a given object ID.
41 * The caller must dispose of it with got_ref_close().
42 */
43 const struct got_error *got_ref_alloc(struct got_reference **, const char *,
44 struct got_object_id *);
46 /*
47 * Allocate a new symbolic reference which points at a given reference.
48 * The caller must dispose of it with got_ref_close().
49 */
50 const struct got_error *got_ref_alloc_symref(struct got_reference **,
51 const char *, struct got_reference *);
53 /* Dispose of a reference. */
54 void got_ref_close(struct got_reference *);
56 /* Get the name of the reference. */
57 const char *got_ref_get_name(struct got_reference *);
59 /* Get the name of the reference which a symoblic reference points at. */
60 const char *got_ref_get_symref_target(struct got_reference *);
62 /*
63 * Create a duplicate copy of a reference.
64 * The caller must dispose of this copy with got_ref_close().
65 */
66 struct got_reference *got_ref_dup(struct got_reference *);
68 /* Attempt to resolve a reference to an object ID. */
69 const struct got_error *got_ref_resolve(struct got_object_id **,
70 struct got_repository *, struct got_reference *);
72 /*
73 * Return a string representation of a reference.
74 * The caller must dispose of it with free(3).
75 */
76 char *got_ref_to_str(struct got_reference *);
78 /* List of references. */
79 struct got_reflist_entry {
80 SIMPLEQ_ENTRY(got_reflist_entry) entry;
81 struct got_reference *ref;
82 };
83 SIMPLEQ_HEAD(got_reflist_head, got_reflist_entry);
85 /* Duplicate a reference list entry. Caller must dispose of it with free(3). */
86 const struct got_error *got_reflist_entry_dup(struct got_reflist_entry **,
87 struct got_reflist_entry *);
89 /* A function which compares two references. Used with got_ref_list(). */
90 typedef const struct got_error *(*got_ref_cmp_cb)(void *, int *,
91 struct got_reference *, struct got_reference *);
93 /* An implementation of got_ref_cmp_cb which compares two references by name. */
94 const struct got_error *got_ref_cmp_by_name(void *, int *,
95 struct got_reference *, struct got_reference *);
97 /* An implementation of got_ref_cmp_cb which compares two tags. */
98 const struct got_error *got_ref_cmp_tags(void *, int *,
99 struct got_reference *, struct got_reference *);
101 /*
102 * Append all known references to a caller-provided ref list head.
103 * Optionally limit references returned to those within a given
104 * reference namespace. Sort the list with the provided reference comparison
105 * function, usually got_ref_cmp_by_name().
106 */
107 const struct got_error *got_ref_list(struct got_reflist_head *,
108 struct got_repository *, const char *, got_ref_cmp_cb, void *);
110 /* Free all references on a ref list. */
111 void got_ref_list_free(struct got_reflist_head *);
113 /* Indicate whether the provided reference is symbolic (points at another
114 * refernce) or not (points at an object ID). */
115 int got_ref_is_symbolic(struct got_reference *);
117 /* Change the object ID a reference points to. */
118 const struct got_error *
119 got_ref_change_ref(struct got_reference *, struct got_object_id *);
121 /* Change the reference name a symbolic reference points to. */
122 const struct got_error *got_ref_change_symref(struct got_reference *,
123 const char *);
125 /*
126 * Change a symbolic reference into a regular reference which points to
127 * the provided object ID.
128 */
129 const struct got_error *got_ref_change_symref_to_ref(struct got_reference *,
130 struct got_object_id *);
132 /* Write a reference to its on-disk path in the repository. */
133 const struct got_error *got_ref_write(struct got_reference *,
134 struct got_repository *);
136 /* Delete a reference from its on-disk path in the repository. */
137 const struct got_error *got_ref_delete(struct got_reference *,
138 struct got_repository *);
140 /* Unlock a reference which was opened in locked state. */
141 const struct got_error *got_ref_unlock(struct got_reference *);