]>
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 { | |
36 | git_refdb_backend *backend; | |
c58cac12 | 37 | char *glob; |
4def7035 CMN |
38 | }; |
39 | ||
d00d5464 ET |
40 | /** An instance for a custom backend */ |
41 | struct git_refdb_backend { | |
0cb16fe9 | 42 | unsigned int version; |
d00d5464 ET |
43 | |
44 | /** | |
45 | * Queries the refdb backend to determine if the given ref_name | |
46 | * exists. A refdb implementation must provide this function. | |
47 | */ | |
48 | int (*exists)( | |
49 | int *exists, | |
21ca0451 | 50 | git_refdb_backend *backend, |
d00d5464 ET |
51 | const char *ref_name); |
52 | ||
53 | /** | |
54 | * Queries the refdb backend for a given reference. A refdb | |
55 | * implementation must provide this function. | |
56 | */ | |
57 | int (*lookup)( | |
58 | git_reference **out, | |
21ca0451 | 59 | git_refdb_backend *backend, |
d00d5464 ET |
60 | const char *ref_name); |
61 | ||
62 | /** | |
2b562c3a CMN |
63 | * Allocate an iterator object for the backend. |
64 | * | |
65 | * A refdb implementation must provide this function. | |
4def7035 CMN |
66 | */ |
67 | int (*iterator)( | |
68 | git_reference_iterator **iter, | |
69 | struct git_refdb_backend *backend); | |
70 | ||
c58cac12 CMN |
71 | /** |
72 | * Allocate a glob-filtering iterator object for the backend. | |
73 | * | |
74 | * A refdb implementation may provide this function. If it's | |
75 | * not available, the glob matching will be done by the frontend. | |
76 | */ | |
77 | int (*iterator_glob)( | |
78 | git_reference_iterator **iter, | |
79 | struct git_refdb_backend *backend, | |
80 | const char *glob); | |
81 | ||
4def7035 CMN |
82 | /** |
83 | * Return the current value and advance the iterator. | |
2b562c3a CMN |
84 | * |
85 | * A refdb implementation must provide this function. | |
4def7035 CMN |
86 | */ |
87 | int (*next)( | |
56960b83 | 88 | git_reference **ref, |
4def7035 CMN |
89 | git_reference_iterator *iter); |
90 | ||
91 | /** | |
92 | * Free the iterator | |
2b562c3a CMN |
93 | * |
94 | * A refdb implementation must provide this function. | |
4def7035 CMN |
95 | */ |
96 | void (*iterator_free)( | |
97 | git_reference_iterator *iter); | |
98 | /* | |
d00d5464 ET |
99 | * Writes the given reference to the refdb. A refdb implementation |
100 | * must provide this function. | |
101 | */ | |
21ca0451 | 102 | int (*write)(git_refdb_backend *backend, const git_reference *ref); |
d00d5464 ET |
103 | |
104 | /** | |
105 | * Deletes the given reference from the refdb. A refdb implementation | |
106 | * must provide this function. | |
107 | */ | |
21ca0451 | 108 | int (*delete)(git_refdb_backend *backend, const git_reference *ref); |
d00d5464 ET |
109 | |
110 | /** | |
111 | * Suggests that the given refdb compress or optimize its references. | |
112 | * This mechanism is implementation specific. (For on-disk reference | |
113 | * databases, this may pack all loose references.) A refdb | |
114 | * implementation may provide this function; if it is not provided, | |
115 | * nothing will be done. | |
116 | */ | |
21ca0451 | 117 | int (*compress)(git_refdb_backend *backend); |
d00d5464 ET |
118 | |
119 | /** | |
120 | * Frees any resources held by the refdb. A refdb implementation may | |
121 | * provide this function; if it is not provided, nothing will be done. | |
122 | */ | |
21ca0451 | 123 | void (*free)(git_refdb_backend *backend); |
d00d5464 ET |
124 | }; |
125 | ||
126 | #define GIT_ODB_BACKEND_VERSION 1 | |
127 | #define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION} | |
128 | ||
129 | /** | |
21ca0451 RB |
130 | * Constructors for default filesystem-based refdb backend |
131 | * | |
132 | * Under normal usage, this is called for you when the repository is | |
133 | * opened / created, but you can use this to explicitly construct a | |
134 | * filesystem refdb backend for a repository. | |
135 | * | |
136 | * @param backend_out Output pointer to the git_refdb_backend object | |
137 | * @param repo Git repository to access | |
138 | * @return 0 on success, <0 error code on failure | |
d00d5464 ET |
139 | */ |
140 | GIT_EXTERN(int) git_refdb_backend_fs( | |
21ca0451 | 141 | git_refdb_backend **backend_out, |
4e4eab52 | 142 | git_repository *repo); |
d00d5464 | 143 | |
4dcd8780 RB |
144 | /** |
145 | * Sets the custom backend to an existing reference DB | |
146 | * | |
21ca0451 RB |
147 | * The `git_refdb` will take ownership of the `git_refdb_backend` so you |
148 | * should NOT free it after calling this function. | |
149 | * | |
4dcd8780 RB |
150 | * @param refdb database to add the backend to |
151 | * @param backend pointer to a git_refdb_backend instance | |
4dcd8780 RB |
152 | * @return 0 on success; error code otherwise |
153 | */ | |
154 | GIT_EXTERN(int) git_refdb_set_backend( | |
155 | git_refdb *refdb, | |
156 | git_refdb_backend *backend); | |
157 | ||
d00d5464 ET |
158 | GIT_END_DECL |
159 | ||
160 | #endif |