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
23 /** An instance for a custom backend */
24 struct git_refdb_backend
{
28 * Queries the refdb backend to determine if the given ref_name
29 * exists. A refdb implementation must provide this function.
33 git_refdb_backend
*backend
,
34 const char *ref_name
);
37 * Queries the refdb backend for a given reference. A refdb
38 * implementation must provide this function.
42 git_refdb_backend
*backend
,
43 const char *ref_name
);
46 * Enumerates each reference in the refdb. A refdb implementation must
47 * provide this function.
50 git_refdb_backend
*backend
,
51 unsigned int list_flags
,
52 git_reference_foreach_cb callback
,
56 * Enumerates each reference in the refdb that matches the given
57 * glob string. A refdb implementation may provide this function;
58 * if it is not provided, foreach will be used and the results filtered
62 git_refdb_backend
*backend
,
64 unsigned int list_flags
,
65 git_reference_foreach_cb callback
,
69 * Writes the given reference to the refdb. A refdb implementation
70 * must provide this function.
72 int (*write
)(git_refdb_backend
*backend
, const git_reference
*ref
);
75 * Deletes the given reference from the refdb. A refdb implementation
76 * must provide this function.
78 int (*delete)(git_refdb_backend
*backend
, const git_reference
*ref
);
81 * Suggests that the given refdb compress or optimize its references.
82 * This mechanism is implementation specific. (For on-disk reference
83 * databases, this may pack all loose references.) A refdb
84 * implementation may provide this function; if it is not provided,
85 * nothing will be done.
87 int (*compress
)(git_refdb_backend
*backend
);
90 * Frees any resources held by the refdb. A refdb implementation may
91 * provide this function; if it is not provided, nothing will be done.
93 void (*free
)(git_refdb_backend
*backend
);
96 #define GIT_ODB_BACKEND_VERSION 1
97 #define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION}
100 * Constructors for default filesystem-based refdb backend
102 * Under normal usage, this is called for you when the repository is
103 * opened / created, but you can use this to explicitly construct a
104 * filesystem refdb backend for a repository.
106 * @param backend_out Output pointer to the git_refdb_backend object
107 * @param repo Git repository to access
108 * @return 0 on success, <0 error code on failure
110 GIT_EXTERN(int) git_refdb_backend_fs(
111 git_refdb_backend
**backend_out
,
112 git_repository
*repo
);
115 * Sets the custom backend to an existing reference DB
117 * The `git_refdb` will take ownership of the `git_refdb_backend` so you
118 * should NOT free it after calling this function.
120 * @param refdb database to add the backend to
121 * @param backend pointer to a git_refdb_backend instance
122 * @return 0 on success; error code otherwise
124 GIT_EXTERN(int) git_refdb_set_backend(
126 git_refdb_backend
*backend
);