]>
git.proxmox.com Git - libgit2.git/blob - include/git2/sys/refdb_backend.h
5bbd4ba4c021614ac214b0b7372541f98c32cf15
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.
43 git_reference_iterator
*iter
);
46 * Return the name of the current reference and advance the iterator
49 const char **ref_name
,
50 git_reference_iterator
*iter
);
56 git_reference_iterator
*iter
);
59 /** An instance for a custom backend */
60 struct git_refdb_backend
{
64 * Queries the refdb backend to determine if the given ref_name
65 * exists. A refdb implementation must provide this function.
69 git_refdb_backend
*backend
,
70 const char *ref_name
);
73 * Queries the refdb backend for a given reference. A refdb
74 * implementation must provide this function.
78 git_refdb_backend
*backend
,
79 const char *ref_name
);
82 * Allocate an iterator object for the backend.
84 * A refdb implementation must provide this function.
87 git_reference_iterator
**iter
,
88 struct git_refdb_backend
*backend
,
92 * Writes the given reference to the refdb. A refdb implementation
93 * must provide this function.
95 int (*write
)(git_refdb_backend
*backend
,
96 const git_reference
*ref
, int force
,
97 const git_signature
*who
, const char *message
);
100 git_reference
**out
, git_refdb_backend
*backend
,
101 const char *old_name
, const char *new_name
, int force
,
102 const git_signature
*who
, const char *message
);
105 * Deletes the given reference from the refdb. A refdb implementation
106 * must provide this function.
108 int (*del
)(git_refdb_backend
*backend
, const char *ref_name
);
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.
117 int (*compress
)(git_refdb_backend
*backend
);
120 * Query whether a particular reference has a log (may be empty)
122 int (*has_log
)(git_refdb_backend
*backend
, const char *refname
);
125 * Make sure a particular reference will have a reflog which
126 * will be appended to on writes.
128 int (*ensure_log
)(git_refdb_backend
*backend
, const char *refname
);
131 * Frees any resources held by the refdb. A refdb implementation may
132 * provide this function; if it is not provided, nothing will be done.
134 void (*free
)(git_refdb_backend
*backend
);
137 * Read the reflog for the given reference name.
139 int (*reflog_read
)(git_reflog
**out
, git_refdb_backend
*backend
, const char *name
);
142 * Write a reflog to disk.
144 int (*reflog_write
)(git_refdb_backend
*backend
, git_reflog
*reflog
);
149 int (*reflog_rename
)(git_refdb_backend
*_backend
, const char *old_name
, const char *new_name
);
154 int (*reflog_delete
)(git_refdb_backend
*backend
, const char *name
);
157 #define GIT_REFDB_BACKEND_VERSION 1
158 #define GIT_REFDB_BACKEND_INIT {GIT_REFDB_BACKEND_VERSION}
161 * Constructors for default filesystem-based refdb backend
163 * Under normal usage, this is called for you when the repository is
164 * opened / created, but you can use this to explicitly construct a
165 * filesystem refdb backend for a repository.
167 * @param backend_out Output pointer to the git_refdb_backend object
168 * @param repo Git repository to access
169 * @return 0 on success, <0 error code on failure
171 GIT_EXTERN(int) git_refdb_backend_fs(
172 git_refdb_backend
**backend_out
,
173 git_repository
*repo
);
176 * Sets the custom backend to an existing reference DB
178 * The `git_refdb` will take ownership of the `git_refdb_backend` so you
179 * should NOT free it after calling this function.
181 * @param refdb database to add the backend to
182 * @param backend pointer to a git_refdb_backend instance
183 * @return 0 on success; error code otherwise
185 GIT_EXTERN(int) git_refdb_set_backend(
187 git_refdb_backend
*backend
);