]>
Commit | Line | Data |
---|---|---|
d00d5464 ET |
1 | /* |
2 | * Copyright (C) the libgit2 contributors. All rights reserved. | |
3 | * | |
4 | * This file is part of libgit2, distributed under the GNU GPL v2 with | |
5 | * a Linking Exception. For full terms see the included COPYING file. | |
6 | */ | |
21ca0451 RB |
7 | #ifndef INCLUDE_sys_git_refdb_backend_h__ |
8 | #define INCLUDE_sys_git_refdb_backend_h__ | |
d00d5464 | 9 | |
4dcd8780 RB |
10 | #include "git2/common.h" |
11 | #include "git2/types.h" | |
12 | #include "git2/oid.h" | |
d00d5464 ET |
13 | |
14 | /** | |
15 | * @file git2/refdb_backend.h | |
16 | * @brief Git custom refs backend functions | |
17 | * @defgroup git_refdb_backend Git custom refs backend API | |
18 | * @ingroup Git | |
19 | * @{ | |
20 | */ | |
21 | GIT_BEGIN_DECL | |
22 | ||
4def7035 CMN |
23 | |
24 | /** | |
25 | * Every backend's iterator must have a pointer to itself as the first | |
26 | * element, so the API can talk to it. You'd define your iterator as | |
27 | * | |
28 | * struct my_iterator { | |
29 | * git_reference_iterator parent; | |
30 | * ... | |
31 | * } | |
32 | * | |
c58cac12 | 33 | * and assign `iter->parent.backend` to your `git_refdb_backend`. |
4def7035 CMN |
34 | */ |
35 | struct git_reference_iterator { | |
ec24e542 VM |
36 | git_refdb *db; |
37 | ||
38 | /** | |
39 | * Return the current reference and advance the iterator. | |
40 | */ | |
41 | int (*next)( | |
42 | git_reference **ref, | |
43 | git_reference_iterator *iter); | |
44 | ||
45 | /** | |
46 | * Return the name of the current reference and advance the iterator | |
47 | */ | |
48 | int (*next_name)( | |
49 | const char **ref_name, | |
50 | git_reference_iterator *iter); | |
51 | ||
52 | /** | |
53 | * Free the iterator | |
54 | */ | |
55 | void (*free)( | |
56 | git_reference_iterator *iter); | |
4def7035 CMN |
57 | }; |
58 | ||
d00d5464 ET |
59 | /** An instance for a custom backend */ |
60 | struct git_refdb_backend { | |
0cb16fe9 | 61 | unsigned int version; |
d00d5464 ET |
62 | |
63 | /** | |
64 | * Queries the refdb backend to determine if the given ref_name | |
65 | * exists. A refdb implementation must provide this function. | |
66 | */ | |
67 | int (*exists)( | |
68 | int *exists, | |
21ca0451 | 69 | git_refdb_backend *backend, |
d00d5464 ET |
70 | const char *ref_name); |
71 | ||
72 | /** | |
73 | * Queries the refdb backend for a given reference. A refdb | |
74 | * implementation must provide this function. | |
75 | */ | |
76 | int (*lookup)( | |
77 | git_reference **out, | |
21ca0451 | 78 | git_refdb_backend *backend, |
d00d5464 ET |
79 | const char *ref_name); |
80 | ||
81 | /** | |
2b562c3a CMN |
82 | * Allocate an iterator object for the backend. |
83 | * | |
84 | * A refdb implementation must provide this function. | |
4def7035 CMN |
85 | */ |
86 | int (*iterator)( | |
c58cac12 CMN |
87 | git_reference_iterator **iter, |
88 | struct git_refdb_backend *backend, | |
89 | const char *glob); | |
90 | ||
4def7035 | 91 | /* |
d00d5464 ET |
92 | * Writes the given reference to the refdb. A refdb implementation |
93 | * must provide this function. | |
94 | */ | |
4e6e2ff2 | 95 | int (*write)(git_refdb_backend *backend, |
110df893 | 96 | const git_reference *ref, int force, |
9b148098 | 97 | const git_signature *who, const char *message, |
91123661 | 98 | const git_oid *old, const char *old_target); |
4e6e2ff2 VM |
99 | |
100 | int (*rename)( | |
101 | git_reference **out, git_refdb_backend *backend, | |
110df893 | 102 | const char *old_name, const char *new_name, int force, |
a57dd3b7 | 103 | const git_signature *who, const char *message); |
d00d5464 ET |
104 | |
105 | /** | |
106 | * Deletes the given reference from the refdb. A refdb implementation | |
107 | * must provide this function. | |
108 | */ | |
7ee8c7e6 | 109 | int (*del)(git_refdb_backend *backend, const char *ref_name, const git_oid *old_id, const char *old_target); |
d00d5464 ET |
110 | |
111 | /** | |
112 | * Suggests that the given refdb compress or optimize its references. | |
113 | * This mechanism is implementation specific. (For on-disk reference | |
114 | * databases, this may pack all loose references.) A refdb | |
115 | * implementation may provide this function; if it is not provided, | |
116 | * nothing will be done. | |
117 | */ | |
21ca0451 | 118 | int (*compress)(git_refdb_backend *backend); |
d00d5464 | 119 | |
f2105129 CMN |
120 | /** |
121 | * Query whether a particular reference has a log (may be empty) | |
122 | */ | |
123 | int (*has_log)(git_refdb_backend *backend, const char *refname); | |
124 | ||
8d5ec910 CMN |
125 | /** |
126 | * Make sure a particular reference will have a reflog which | |
127 | * will be appended to on writes. | |
128 | */ | |
129 | int (*ensure_log)(git_refdb_backend *backend, const char *refname); | |
130 | ||
d00d5464 ET |
131 | /** |
132 | * Frees any resources held by the refdb. A refdb implementation may | |
133 | * provide this function; if it is not provided, nothing will be done. | |
134 | */ | |
21ca0451 | 135 | void (*free)(git_refdb_backend *backend); |
b976f3c2 CMN |
136 | |
137 | /** | |
138 | * Read the reflog for the given reference name. | |
139 | */ | |
140 | int (*reflog_read)(git_reflog **out, git_refdb_backend *backend, const char *name); | |
141 | ||
142 | /** | |
143 | * Write a reflog to disk. | |
144 | */ | |
145 | int (*reflog_write)(git_refdb_backend *backend, git_reflog *reflog); | |
146 | ||
b976f3c2 CMN |
147 | /** |
148 | * Rename a reflog | |
149 | */ | |
150 | int (*reflog_rename)(git_refdb_backend *_backend, const char *old_name, const char *new_name); | |
151 | ||
b976f3c2 CMN |
152 | /** |
153 | * Remove a reflog. | |
154 | */ | |
155 | int (*reflog_delete)(git_refdb_backend *backend, const char *name); | |
ab8d9242 CMN |
156 | |
157 | /** | |
158 | * Lock a reference. The opaque parameter will be passed to the unlock function | |
159 | */ | |
160 | int (*lock)(void **payload_out, git_refdb_backend *backend, const char *refname); | |
161 | ||
162 | /** | |
163 | * Unlock a reference. Only one of target or symbolic_target | |
164 | * will be set. success indicates whether to update the | |
165 | * reference or discard the lock (if it's false) | |
166 | */ | |
167 | int (*unlock)(git_refdb_backend *backend, void *payload, int success, int update_reflog, | |
168 | const git_reference *ref, const git_signature *sig, const char *message); | |
d00d5464 ET |
169 | }; |
170 | ||
e0b267af ET |
171 | #define GIT_REFDB_BACKEND_VERSION 1 |
172 | #define GIT_REFDB_BACKEND_INIT {GIT_REFDB_BACKEND_VERSION} | |
d00d5464 | 173 | |
b9f81997 MB |
174 | /** |
175 | * Initializes a `git_refdb_backend` with default values. Equivalent to | |
176 | * creating an instance with GIT_REFDB_BACKEND_INIT. | |
177 | * | |
bc91347b RB |
178 | * @param opts the `git_refdb_backend` struct to initialize |
179 | * @param version Version of struct; pass `GIT_REFDB_BACKEND_VERSION` | |
b9f81997 MB |
180 | * @return Zero on success; -1 on failure. |
181 | */ | |
182 | GIT_EXTERN(int) git_refdb_init_backend( | |
bc91347b RB |
183 | git_refdb_backend *backend, |
184 | unsigned int version); | |
b9f81997 | 185 | |
d00d5464 | 186 | /** |
21ca0451 RB |
187 | * Constructors for default filesystem-based refdb backend |
188 | * | |
189 | * Under normal usage, this is called for you when the repository is | |
190 | * opened / created, but you can use this to explicitly construct a | |
191 | * filesystem refdb backend for a repository. | |
192 | * | |
193 | * @param backend_out Output pointer to the git_refdb_backend object | |
194 | * @param repo Git repository to access | |
195 | * @return 0 on success, <0 error code on failure | |
d00d5464 ET |
196 | */ |
197 | GIT_EXTERN(int) git_refdb_backend_fs( | |
21ca0451 | 198 | git_refdb_backend **backend_out, |
4e4eab52 | 199 | git_repository *repo); |
d00d5464 | 200 | |
4dcd8780 RB |
201 | /** |
202 | * Sets the custom backend to an existing reference DB | |
203 | * | |
21ca0451 RB |
204 | * The `git_refdb` will take ownership of the `git_refdb_backend` so you |
205 | * should NOT free it after calling this function. | |
206 | * | |
4dcd8780 RB |
207 | * @param refdb database to add the backend to |
208 | * @param backend pointer to a git_refdb_backend instance | |
4dcd8780 RB |
209 | * @return 0 on success; error code otherwise |
210 | */ | |
211 | GIT_EXTERN(int) git_refdb_set_backend( | |
212 | git_refdb *refdb, | |
213 | git_refdb_backend *backend); | |
214 | ||
d00d5464 ET |
215 | GIT_END_DECL |
216 | ||
217 | #endif |