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