]> git.proxmox.com Git - libgit2.git/blob - include/git2/refdb.h
Merge pull request #1453 from ethomson/refdb_export
[libgit2.git] / include / git2 / refdb.h
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 */
7 #ifndef INCLUDE_git_refdb_h__
8 #define INCLUDE_git_refdb_h__
9
10 #include "common.h"
11 #include "types.h"
12 #include "oid.h"
13 #include "refs.h"
14
15 /**
16 * @file git2/refdb.h
17 * @brief Git custom refs backend functions
18 * @defgroup git_refdb Git custom refs backend API
19 * @ingroup Git
20 * @{
21 */
22 GIT_BEGIN_DECL
23
24 /**
25 * Create a new reference. Either an oid or a symbolic target must be
26 * specified.
27 *
28 * @param refdb the reference database to associate with this reference
29 * @param name the reference name
30 * @param oid the object id for a direct reference
31 * @param symbolic the target for a symbolic reference
32 * @return the created git_reference or NULL on error
33 */
34 GIT_EXTERN(git_reference *) git_reference__alloc(
35 git_refdb *refdb,
36 const char *name,
37 const git_oid *oid,
38 const char *symbolic);
39
40 /**
41 * Create a new reference database with no backends.
42 *
43 * Before the Ref DB can be used for read/writing, a custom database
44 * backend must be manually set using `git_refdb_set_backend()`
45 *
46 * @param out location to store the database pointer, if opened.
47 * Set to NULL if the open failed.
48 * @param repo the repository
49 * @return 0 or an error code
50 */
51 GIT_EXTERN(int) git_refdb_new(git_refdb **out, git_repository *repo);
52
53 /**
54 * Create a new reference database and automatically add
55 * the default backends:
56 *
57 * - git_refdb_dir: read and write loose and packed refs
58 * from disk, assuming the repository dir as the folder
59 *
60 * @param out location to store the database pointer, if opened.
61 * Set to NULL if the open failed.
62 * @param repo the repository
63 * @return 0 or an error code
64 */
65 GIT_EXTERN(int) git_refdb_open(git_refdb **out, git_repository *repo);
66
67 /**
68 * Suggests that the given refdb compress or optimize its references.
69 * This mechanism is implementation specific. For on-disk reference
70 * databases, for example, this may pack all loose references.
71 */
72 GIT_EXTERN(int) git_refdb_compress(git_refdb *refdb);
73
74 /**
75 * Close an open reference database.
76 *
77 * @param refdb reference database pointer or NULL
78 */
79 GIT_EXTERN(void) git_refdb_free(git_refdb *refdb);
80
81 /**
82 * Sets the custom backend to an existing reference DB
83 *
84 * Read <refdb_backends.h> for more information.
85 *
86 * @param refdb database to add the backend to
87 * @param backend pointer to a git_refdb_backend instance
88 * @param priority Value for ordering the backends queue
89 * @return 0 on success; error code otherwise
90 */
91 GIT_EXTERN(int) git_refdb_set_backend(
92 git_refdb *refdb,
93 git_refdb_backend *backend);
94
95 /** @} */
96 GIT_END_DECL
97
98 #endif