]>
git.proxmox.com Git - libgit2.git/blob - include/git2/sys/refdb_backend.h
8e22c4f02a36b948259f04c20e3a2f3a61027e65
2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
7 #ifndef INCLUDE_sys_git_refdb_backend_h__
8 #define INCLUDE_sys_git_refdb_backend_h__
10 #include "git2/common.h"
11 #include "git2/types.h"
15 * @file git2/refdb_backend.h
16 * @brief Git custom refs backend functions
17 * @defgroup git_refdb_backend Git custom refs backend API
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
28 * struct my_iterator {
29 * git_reference_iterator parent;
33 * and assign `iter->parent.backend` to your `git_refdb_backend`.
35 struct git_reference_iterator
{
39 * Return the current reference and advance the iterator.
41 int GIT_CALLBACK(next
)(
43 git_reference_iterator
*iter
);
46 * Return the name of the current reference and advance the iterator
48 int GIT_CALLBACK(next_name
)(
49 const char **ref_name
,
50 git_reference_iterator
*iter
);
55 void GIT_CALLBACK(free
)(
56 git_reference_iterator
*iter
);
59 /** An instance for a custom backend */
60 struct git_refdb_backend
{
61 unsigned int version
; /**< The backend API version */
64 * Queries the refdb backend for the existence of a reference.
66 * A refdb implementation must provide this function.
68 int GIT_CALLBACK(exists
)(
70 git_refdb_backend
*backend
,
71 const char *ref_name
);
74 * Queries the refdb backend for a given reference.
76 * A refdb implementation must provide this function.
78 int GIT_CALLBACK(lookup
)(
80 git_refdb_backend
*backend
,
81 const char *ref_name
);
84 * Allocate an iterator object for the backend.
86 * A refdb implementation must provide this function.
88 int GIT_CALLBACK(iterator
)(
89 git_reference_iterator
**iter
,
90 struct git_refdb_backend
*backend
,
94 * Writes the given reference to the refdb.
96 * A refdb implementation must provide this function.
98 int GIT_CALLBACK(write
)(git_refdb_backend
*backend
,
99 const git_reference
*ref
, int force
,
100 const git_signature
*who
, const char *message
,
101 const git_oid
*old
, const char *old_target
);
104 * Rename a reference in the refdb.
106 * A refdb implementation must provide this function.
108 int GIT_CALLBACK(rename
)(
109 git_reference
**out
, git_refdb_backend
*backend
,
110 const char *old_name
, const char *new_name
, int force
,
111 const git_signature
*who
, const char *message
);
114 * Deletes the given reference from the refdb.
116 * If it exists, its reflog should be deleted as well.
118 * A refdb implementation must provide this function.
120 int GIT_CALLBACK(del
)(git_refdb_backend
*backend
, const char *ref_name
, const git_oid
*old_id
, const char *old_target
);
123 * Suggests that the given refdb compress or optimize its references.
125 * This mechanism is implementation specific. For on-disk reference
126 * databases, this may pack all loose references.
128 * A refdb implementation may provide this function; if it is not
129 * provided, nothing will be done.
131 int GIT_CALLBACK(compress
)(git_refdb_backend
*backend
);
134 * Query whether a particular reference has a log (may be empty)
136 * A refdb implementation must provide this function.
138 int GIT_CALLBACK(has_log
)(git_refdb_backend
*backend
, const char *refname
);
141 * Make sure a particular reference will have a reflog which
142 * will be appended to on writes.
144 * A refdb implementation must provide this function.
146 int GIT_CALLBACK(ensure_log
)(git_refdb_backend
*backend
, const char *refname
);
149 * Frees any resources held by the refdb (including the `git_refdb_backend`
152 * A refdb backend implementation must provide this function.
154 void GIT_CALLBACK(free
)(git_refdb_backend
*backend
);
157 * Read the reflog for the given reference name.
159 * A refdb implementation must provide this function.
161 int GIT_CALLBACK(reflog_read
)(git_reflog
**out
, git_refdb_backend
*backend
, const char *name
);
164 * Write a reflog to disk.
166 * A refdb implementation must provide this function.
168 int GIT_CALLBACK(reflog_write
)(git_refdb_backend
*backend
, git_reflog
*reflog
);
173 * A refdb implementation must provide this function.
175 int GIT_CALLBACK(reflog_rename
)(git_refdb_backend
*_backend
, const char *old_name
, const char *new_name
);
180 * A refdb implementation must provide this function.
182 int GIT_CALLBACK(reflog_delete
)(git_refdb_backend
*backend
, const char *name
);
187 * The opaque parameter will be passed to the unlock function.
189 * A refdb implementation may provide this function; if it is not
190 * provided, the transaction API will fail to work.
192 int GIT_CALLBACK(lock
)(void **payload_out
, git_refdb_backend
*backend
, const char *refname
);
195 * Unlock a reference.
197 * Only one of target or symbolic_target will be set.
198 * `success` will be true if the reference should be update, false if
199 * the lock must be discarded.
201 * A refdb implementation must provide this function if a `lock`
202 * implementation is provided.
204 int GIT_CALLBACK(unlock
)(git_refdb_backend
*backend
, void *payload
, int success
, int update_reflog
,
205 const git_reference
*ref
, const git_signature
*sig
, const char *message
);
208 #define GIT_REFDB_BACKEND_VERSION 1
209 #define GIT_REFDB_BACKEND_INIT {GIT_REFDB_BACKEND_VERSION}
212 * Initializes a `git_refdb_backend` with default values. Equivalent to
213 * creating an instance with GIT_REFDB_BACKEND_INIT.
215 * @param backend the `git_refdb_backend` struct to initialize
216 * @param version Version of struct; pass `GIT_REFDB_BACKEND_VERSION`
217 * @return Zero on success; -1 on failure.
219 GIT_EXTERN(int) git_refdb_init_backend(
220 git_refdb_backend
*backend
,
221 unsigned int version
);
224 * Constructors for default filesystem-based refdb backend
226 * Under normal usage, this is called for you when the repository is
227 * opened / created, but you can use this to explicitly construct a
228 * filesystem refdb backend for a repository.
230 * @param backend_out Output pointer to the git_refdb_backend object
231 * @param repo Git repository to access
232 * @return 0 on success, <0 error code on failure
234 GIT_EXTERN(int) git_refdb_backend_fs(
235 git_refdb_backend
**backend_out
,
236 git_repository
*repo
);
239 * Sets the custom backend to an existing reference DB
241 * The `git_refdb` will take ownership of the `git_refdb_backend` so you
242 * should NOT free it after calling this function.
244 * @param refdb database to add the backend to
245 * @param backend pointer to a git_refdb_backend instance
246 * @return 0 on success; error code otherwise
248 GIT_EXTERN(int) git_refdb_set_backend(
250 git_refdb_backend
*backend
);