Blame


1 5261c201 2018-04-01 stsp /*
2 5261c201 2018-04-01 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 5261c201 2018-04-01 stsp *
4 5261c201 2018-04-01 stsp * Permission to use, copy, modify, and distribute this software for any
5 5261c201 2018-04-01 stsp * purpose with or without fee is hereby granted, provided that the above
6 5261c201 2018-04-01 stsp * copyright notice and this permission notice appear in all copies.
7 5261c201 2018-04-01 stsp *
8 5261c201 2018-04-01 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 5261c201 2018-04-01 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 5261c201 2018-04-01 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 5261c201 2018-04-01 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 5261c201 2018-04-01 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 5261c201 2018-04-01 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 5261c201 2018-04-01 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 5261c201 2018-04-01 stsp */
16 5261c201 2018-04-01 stsp
17 5261c201 2018-04-01 stsp /* A reference which points to an arbitrary object. */
18 5261c201 2018-04-01 stsp struct got_reference;
19 5261c201 2018-04-01 stsp
20 5261c201 2018-04-01 stsp /* Well-known reference names. */
21 5261c201 2018-04-01 stsp #define GOT_REF_HEAD "HEAD"
22 5261c201 2018-04-01 stsp #define GOT_REF_ORIG_HEAD "ORIG_HEAD"
23 5261c201 2018-04-01 stsp #define GOT_REF_MERGE_HEAD "MERGE_HEAD"
24 5261c201 2018-04-01 stsp #define GOT_REF_FETCH_HEAD "FETCH_HEAD"
25 5261c201 2018-04-01 stsp
26 5261c201 2018-04-01 stsp struct got_repository;
27 5261c201 2018-04-01 stsp struct got_object_id;
28 5261c201 2018-04-01 stsp
29 63e5aa5c 2021-08-23 stsp /* Determine whether a given reference name is valid. */
30 63e5aa5c 2021-08-23 stsp int got_ref_name_is_valid(const char *);
31 63e5aa5c 2021-08-23 stsp
32 0c60ce5a 2018-04-02 stsp /*
33 0c60ce5a 2018-04-02 stsp * Attempt to open the reference with the provided name in a repository.
34 2f17228e 2019-05-12 stsp * The caller must dispose of the reference with got_ref_close().
35 2f17228e 2019-05-12 stsp * Optionally, the underlying reference file can be locked before it is opened
36 2f17228e 2019-05-12 stsp * to prevent concurrent modification of the reference, in which case the file
37 2f17228e 2019-05-12 stsp * must be unlocked with got_ref_unlock() before got_ref_close() is called.
38 0c60ce5a 2018-04-02 stsp */
39 6c34b1aa 2019-03-18 stsp const struct got_error *got_ref_open(struct got_reference **,
40 2f17228e 2019-05-12 stsp struct got_repository *, const char *, int);
41 0c60ce5a 2018-04-02 stsp
42 5892cdd6 2019-03-10 stsp /*
43 5892cdd6 2019-03-10 stsp * Allocate a new reference for a given object ID.
44 5892cdd6 2019-03-10 stsp * The caller must dispose of it with got_ref_close().
45 5892cdd6 2019-03-10 stsp */
46 5892cdd6 2019-03-10 stsp const struct got_error *got_ref_alloc(struct got_reference **, const char *,
47 5892cdd6 2019-03-10 stsp struct got_object_id *);
48 5892cdd6 2019-03-10 stsp
49 aaf88317 2019-07-10 stsp /*
50 aaf88317 2019-07-10 stsp * Allocate a new symbolic reference which points at a given reference.
51 aaf88317 2019-07-10 stsp * The caller must dispose of it with got_ref_close().
52 aaf88317 2019-07-10 stsp */
53 aaf88317 2019-07-10 stsp const struct got_error *got_ref_alloc_symref(struct got_reference **,
54 aaf88317 2019-07-10 stsp const char *, struct got_reference *);
55 aaf88317 2019-07-10 stsp
56 0c60ce5a 2018-04-02 stsp /* Dispose of a reference. */
57 5261c201 2018-04-01 stsp void got_ref_close(struct got_reference *);
58 0c60ce5a 2018-04-02 stsp
59 0bd18d37 2019-02-01 stsp /* Get the name of the reference. */
60 0bd18d37 2019-02-01 stsp const char *got_ref_get_name(struct got_reference *);
61 0bd18d37 2019-02-01 stsp
62 aaf88317 2019-07-10 stsp /* Get the name of the reference which a symoblic reference points at. */
63 aaf88317 2019-07-10 stsp const char *got_ref_get_symref_target(struct got_reference *);
64 aaf88317 2019-07-10 stsp
65 3f338f0a 2021-07-27 stsp /* Get the last modification timestamp of the reference. */
66 3f338f0a 2021-07-27 stsp time_t got_ref_get_mtime(struct got_reference *);
67 3f338f0a 2021-07-27 stsp
68 0c60ce5a 2018-04-02 stsp /*
69 0c60ce5a 2018-04-02 stsp * Create a duplicate copy of a reference.
70 0c60ce5a 2018-04-02 stsp * The caller must dispose of this copy with got_ref_close().
71 0c60ce5a 2018-04-02 stsp */
72 5261c201 2018-04-01 stsp struct got_reference *got_ref_dup(struct got_reference *);
73 0c60ce5a 2018-04-02 stsp
74 cce2f485 2021-08-22 stsp /* Attempt to resolve a symbolic reference to a non-symbolic one. */
75 cce2f485 2021-08-22 stsp const struct got_error *got_ref_resolve_symbolic(struct got_reference **,
76 cce2f485 2021-08-22 stsp struct got_repository *, struct got_reference *);
77 cce2f485 2021-08-22 stsp
78 cce2f485 2021-08-22 stsp /* Attempt to resolve a reference (symbolic or not) to an object ID. */
79 5261c201 2018-04-01 stsp const struct got_error *got_ref_resolve(struct got_object_id **,
80 5261c201 2018-04-01 stsp struct got_repository *, struct got_reference *);
81 0c60ce5a 2018-04-02 stsp
82 271d2a38 2018-12-25 stsp /*
83 271d2a38 2018-12-25 stsp * Return a string representation of a reference.
84 271d2a38 2018-12-25 stsp * The caller must dispose of it with free(3).
85 271d2a38 2018-12-25 stsp */
86 5261c201 2018-04-01 stsp char *got_ref_to_str(struct got_reference *);
87 199a4027 2019-02-02 stsp
88 48cae60d 2020-09-22 stsp /* List of references. */
89 199a4027 2019-02-02 stsp struct got_reflist_entry {
90 d9dff0e5 2020-12-26 stsp TAILQ_ENTRY(got_reflist_entry) entry;
91 199a4027 2019-02-02 stsp struct got_reference *ref;
92 199a4027 2019-02-02 stsp };
93 d9dff0e5 2020-12-26 stsp TAILQ_HEAD(got_reflist_head, got_reflist_entry);
94 199a4027 2019-02-02 stsp
95 b8bad2ba 2019-08-23 stsp /* Duplicate a reference list entry. Caller must dispose of it with free(3). */
96 b8bad2ba 2019-08-23 stsp const struct got_error *got_reflist_entry_dup(struct got_reflist_entry **,
97 b8bad2ba 2019-08-23 stsp struct got_reflist_entry *);
98 b8bad2ba 2019-08-23 stsp
99 b8bad2ba 2019-08-23 stsp /* A function which compares two references. Used with got_ref_list(). */
100 b8bad2ba 2019-08-23 stsp typedef const struct got_error *(*got_ref_cmp_cb)(void *, int *,
101 b8bad2ba 2019-08-23 stsp struct got_reference *, struct got_reference *);
102 b8bad2ba 2019-08-23 stsp
103 b8bad2ba 2019-08-23 stsp /* An implementation of got_ref_cmp_cb which compares two references by name. */
104 b8bad2ba 2019-08-23 stsp const struct got_error *got_ref_cmp_by_name(void *, int *,
105 b8bad2ba 2019-08-23 stsp struct got_reference *, struct got_reference *);
106 b8bad2ba 2019-08-23 stsp
107 d1f16636 2020-01-15 stsp /* An implementation of got_ref_cmp_cb which compares two tags. */
108 d1f16636 2020-01-15 stsp const struct got_error *got_ref_cmp_tags(void *, int *,
109 d1f16636 2020-01-15 stsp struct got_reference *, struct got_reference *);
110 d1f16636 2020-01-15 stsp
111 29606af7 2019-08-23 stsp /*
112 e600f124 2021-03-21 stsp * An implementation of got_ref_cmp_cb which compares commit timestamps.
113 e600f124 2021-03-21 stsp * Requires a struct got_repository * as the void * argument.
114 e600f124 2021-03-21 stsp */
115 e600f124 2021-03-21 stsp const struct got_error *got_ref_cmp_by_commit_timestamp_descending(void *,
116 e600f124 2021-03-21 stsp int *, struct got_reference *, struct got_reference *);
117 e600f124 2021-03-21 stsp
118 e600f124 2021-03-21 stsp /*
119 29606af7 2019-08-23 stsp * Append all known references to a caller-provided ref list head.
120 29606af7 2019-08-23 stsp * Optionally limit references returned to those within a given
121 b8bad2ba 2019-08-23 stsp * reference namespace. Sort the list with the provided reference comparison
122 b8bad2ba 2019-08-23 stsp * function, usually got_ref_cmp_by_name().
123 29606af7 2019-08-23 stsp */
124 199a4027 2019-02-02 stsp const struct got_error *got_ref_list(struct got_reflist_head *,
125 b8bad2ba 2019-08-23 stsp struct got_repository *, const char *, got_ref_cmp_cb, void *);
126 9e672c74 2019-03-11 stsp
127 e2e879a0 2019-03-11 stsp /* Free all references on a ref list. */
128 e2e879a0 2019-03-11 stsp void got_ref_list_free(struct got_reflist_head *);
129 e2e879a0 2019-03-11 stsp
130 779e1159 2021-06-18 stsp /*
131 779e1159 2021-06-18 stsp * Insert a reference into a reference list.
132 779e1159 2021-06-18 stsp * Return a pointer to the newly allocated list entry in *newp.
133 779e1159 2021-06-18 stsp * If *newp is NULL and no error occured then the specified reference was
134 779e1159 2021-06-18 stsp * already an element of the list. If *newp is not NULL then the reference
135 779e1159 2021-06-18 stsp * was shallow-copied onto the list and should no longer be closed with
136 779e1159 2021-06-18 stsp * got_ref_close(). Instead it will be closed along with other list
137 779e1159 2021-06-18 stsp * elements by got_ref_list_free().
138 779e1159 2021-06-18 stsp */
139 779e1159 2021-06-18 stsp const struct got_error *
140 779e1159 2021-06-18 stsp got_reflist_insert(struct got_reflist_entry **newp, struct got_reflist_head *refs,
141 72acb3d8 2021-08-06 stsp struct got_reference *ref, got_ref_cmp_cb cmp_cb, void *cmp_arg);
142 779e1159 2021-06-18 stsp
143 fb95e70d 2021-11-20 thomas /* Sort a list of references with the provided comparison callback. */
144 fb95e70d 2021-11-20 thomas const struct got_error *
145 fb95e70d 2021-11-20 thomas got_reflist_sort(struct got_reflist_head *refs, got_ref_cmp_cb cmp_cb,
146 fb95e70d 2021-11-20 thomas void *cmp_arg);
147 fb95e70d 2021-11-20 thomas
148 b249b824 2019-05-09 stsp /* Indicate whether the provided reference is symbolic (points at another
149 b249b824 2019-05-09 stsp * refernce) or not (points at an object ID). */
150 b249b824 2019-05-09 stsp int got_ref_is_symbolic(struct got_reference *);
151 b249b824 2019-05-09 stsp
152 b249b824 2019-05-09 stsp /* Change the object ID a reference points to. */
153 b249b824 2019-05-09 stsp const struct got_error *
154 b249b824 2019-05-09 stsp got_ref_change_ref(struct got_reference *, struct got_object_id *);
155 b249b824 2019-05-09 stsp
156 b249b824 2019-05-09 stsp /* Change the reference name a symbolic reference points to. */
157 b249b824 2019-05-09 stsp const struct got_error *got_ref_change_symref(struct got_reference *,
158 d7b899ab 2020-03-25 stsp const char *);
159 b249b824 2019-05-09 stsp
160 e8a967e0 2020-03-21 stsp /*
161 e8a967e0 2020-03-21 stsp * Change a symbolic reference into a regular reference which points to
162 e8a967e0 2020-03-21 stsp * the provided object ID.
163 e8a967e0 2020-03-21 stsp */
164 e8a967e0 2020-03-21 stsp const struct got_error *got_ref_change_symref_to_ref(struct got_reference *,
165 e8a967e0 2020-03-21 stsp struct got_object_id *);
166 e8a967e0 2020-03-21 stsp
167 9e672c74 2019-03-11 stsp /* Write a reference to its on-disk path in the repository. */
168 9e672c74 2019-03-11 stsp const struct got_error *got_ref_write(struct got_reference *,
169 9e672c74 2019-03-11 stsp struct got_repository *);
170 2d2e1378 2019-03-11 stsp
171 2d2e1378 2019-03-11 stsp /* Delete a reference from its on-disk path in the repository. */
172 2d2e1378 2019-03-11 stsp const struct got_error *got_ref_delete(struct got_reference *,
173 2d2e1378 2019-03-11 stsp struct got_repository *);
174 2f17228e 2019-05-12 stsp
175 2f17228e 2019-05-12 stsp /* Unlock a reference which was opened in locked state. */
176 2f17228e 2019-05-12 stsp const struct got_error *got_ref_unlock(struct got_reference *);
177 7b5b670e 2020-12-25 stsp
178 7b5b670e 2020-12-25 stsp /* Map object IDs to references. */
179 7b5b670e 2020-12-25 stsp struct got_reflist_object_id_map;
180 7b5b670e 2020-12-25 stsp
181 7b5b670e 2020-12-25 stsp /*
182 7b5b670e 2020-12-25 stsp * Create and populate an object ID map for a given list of references.
183 7b5b670e 2020-12-25 stsp * Map entries will contain deep-copies of elements of the reflist.
184 f193b038 2020-12-26 stsp * The caller must dispose of the map with got_reflist_object_id_map_free().
185 7b5b670e 2020-12-25 stsp */
186 7b5b670e 2020-12-25 stsp const struct got_error *got_reflist_object_id_map_create(
187 7b5b670e 2020-12-25 stsp struct got_reflist_object_id_map **, struct got_reflist_head *,
188 7b5b670e 2020-12-25 stsp struct got_repository *);
189 7b5b670e 2020-12-25 stsp
190 7b5b670e 2020-12-25 stsp /*
191 7b5b670e 2020-12-25 stsp * Return a list of references which correspond to a given object ID.
192 7b5b670e 2020-12-25 stsp * The returned list must be considered read-only.
193 7b5b670e 2020-12-25 stsp * The caller must _not_ call free(3) on the returned pointer!
194 7b5b670e 2020-12-25 stsp * If no references are associated with the ID, return NULL.
195 7b5b670e 2020-12-25 stsp */
196 7b5b670e 2020-12-25 stsp struct got_reflist_head *
197 7b5b670e 2020-12-25 stsp got_reflist_object_id_map_lookup(struct got_reflist_object_id_map *,
198 7b5b670e 2020-12-25 stsp struct got_object_id *);
199 7b5b670e 2020-12-25 stsp
200 7b5b670e 2020-12-25 stsp /* Free the specified object ID map. */
201 f193b038 2020-12-26 stsp void got_reflist_object_id_map_free(struct got_reflist_object_id_map *);