]> git.proxmox.com Git - libgit2.git/blob - src/libgit2/refdb.h
New upstream version 1.5.0+ds
[libgit2.git] / src / libgit2 / 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_refdb_h__
8 #define INCLUDE_refdb_h__
9
10 #include "common.h"
11
12 #include "git2/refdb.h"
13 #include "repository.h"
14
15 struct git_refdb {
16 git_refcount rc;
17 git_repository *repo;
18 git_refdb_backend *backend;
19 };
20
21 void git_refdb__free(git_refdb *db);
22
23 int git_refdb_exists(
24 int *exists,
25 git_refdb *refdb,
26 const char *ref_name);
27
28 int git_refdb_lookup(
29 git_reference **out,
30 git_refdb *refdb,
31 const char *ref_name);
32
33 /**
34 * Resolve the reference by following symbolic references.
35 *
36 * Given a reference name, this function will follow any symbolic references up
37 * to `max_nesting` deep and return the resolved direct reference. If any of
38 * the intermediate symbolic references points to a non-existing reference,
39 * then that symbolic reference is returned instead with an error code of `0`.
40 * If the given reference is a direct reference already, it is returned
41 * directly.
42 *
43 * If `max_nesting` is `0`, the reference will not be resolved. If it's
44 * negative, it will be set to the default resolve depth which is `5`.
45 *
46 * @param out Pointer to store the result in.
47 * @param db The refdb to use for resolving the reference.
48 * @param ref_name The reference name to lookup and resolve.
49 * @param max_nesting The maximum nesting depth.
50 * @return `0` on success, a negative error code otherwise.
51 */
52 int git_refdb_resolve(
53 git_reference **out,
54 git_refdb *db,
55 const char *ref_name,
56 int max_nesting);
57
58 int git_refdb_rename(
59 git_reference **out,
60 git_refdb *db,
61 const char *old_name,
62 const char *new_name,
63 int force,
64 const git_signature *who,
65 const char *message);
66
67 int git_refdb_iterator(git_reference_iterator **out, git_refdb *db, const char *glob);
68 int git_refdb_iterator_next(git_reference **out, git_reference_iterator *iter);
69 int git_refdb_iterator_next_name(const char **out, git_reference_iterator *iter);
70 void git_refdb_iterator_free(git_reference_iterator *iter);
71
72 int git_refdb_write(git_refdb *refdb, git_reference *ref, int force, const git_signature *who, const char *message, const git_oid *old_id, const char *old_target);
73 int git_refdb_delete(git_refdb *refdb, const char *ref_name, const git_oid *old_id, const char *old_target);
74
75 int git_refdb_reflog_read(git_reflog **out, git_refdb *db, const char *name);
76 int git_refdb_reflog_write(git_reflog *reflog);
77
78 /**
79 * Determine whether a reflog entry should be created for the given reference.
80 *
81 * Whether or not writing to a reference should create a reflog entry is
82 * dependent on a number of things. Most importantly, there's the
83 * "core.logAllRefUpdates" setting that controls in which situations a
84 * reference should get a corresponding reflog entry. The following values for
85 * it are understood:
86 *
87 * - "false": Do not log reference updates.
88 *
89 * - "true": Log normal reference updates. This will write entries for
90 * references in "refs/heads", "refs/remotes", "refs/notes" and
91 * "HEAD" or if the reference already has a log entry.
92 *
93 * - "always": Always create a reflog entry.
94 *
95 * If unset, the value will default to "true" for non-bare repositories and
96 * "false" for bare ones.
97 *
98 * @param out pointer to which the result will be written, `1` means a reflog
99 * entry should be written, `0` means none should be written.
100 * @param db The refdb to decide this for.
101 * @param ref The reference one wants to check.
102 * @return `0` on success, a negative error code otherwise.
103 */
104 int git_refdb_should_write_reflog(int *out, git_refdb *db, const git_reference *ref);
105
106 /**
107 * Determine whether a reflog entry should be created for HEAD if creating one
108 * for the given reference
109 *
110 * In case the given reference is being pointed to by HEAD, then creating a
111 * reflog entry for this reference also requires us to create a corresponding
112 * reflog entry for HEAD. This function can be used to determine that scenario.
113 *
114 * @param out pointer to which the result will be written, `1` means a reflog
115 * entry should be written, `0` means none should be written.
116 * @param db The refdb to decide this for.
117 * @param ref The reference one wants to check.
118 * @return `0` on success, a negative error code otherwise.
119 */
120 int git_refdb_should_write_head_reflog(int *out, git_refdb *db, const git_reference *ref);
121
122 int git_refdb_has_log(git_refdb *db, const char *refname);
123 int git_refdb_ensure_log(git_refdb *refdb, const char *refname);
124
125 int git_refdb_lock(void **payload, git_refdb *db, const char *refname);
126 int git_refdb_unlock(git_refdb *db, void *payload, int success, int update_reflog, const git_reference *ref, const git_signature *sig, const char *message);
127
128 #endif