]>
Commit | Line | Data |
---|---|---|
27df4275 | 1 | /* |
359fc2d2 | 2 | * Copyright (C) the libgit2 contributors. All rights reserved. |
27df4275 | 3 | * |
bb742ede VM |
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. | |
27df4275 MS |
6 | */ |
7 | #ifndef INCLUDE_git_reflog_h__ | |
8 | #define INCLUDE_git_reflog_h__ | |
9 | ||
10 | #include "common.h" | |
11 | #include "types.h" | |
12 | #include "oid.h" | |
13 | ||
14 | /** | |
15 | * @file git2/reflog.h | |
16 | * @brief Git reflog management routines | |
17 | * @defgroup git_reflog Git reflog management routines | |
18 | * @ingroup Git | |
19 | * @{ | |
20 | */ | |
21 | GIT_BEGIN_DECL | |
22 | ||
23 | /** | |
24 | * Read the reflog for the given reference | |
25 | * | |
ae833178 | 26 | * If there is no reflog file for the given |
27 | * reference yet, an empty reflog object will | |
28 | * be returned. | |
29 | * | |
27df4275 MS |
30 | * The reflog must be freed manually by using |
31 | * git_reflog_free(). | |
32 | * | |
2508cc66 | 33 | * @param out pointer to reflog |
e579e0f7 | 34 | * @param repo the repository |
b976f3c2 | 35 | * @param name reference to look up |
e172cf08 | 36 | * @return 0 or an error code |
27df4275 | 37 | */ |
b976f3c2 | 38 | GIT_EXTERN(int) git_reflog_read(git_reflog **out, git_repository *repo, const char *name); |
27df4275 | 39 | |
bd72425d | 40 | /** |
41 | * Write an existing in-memory reflog object back to disk | |
42 | * using an atomic file lock. | |
43 | * | |
44 | * @param reflog an existing reflog object | |
45 | * @return 0 or an error code | |
46 | */ | |
47 | GIT_EXTERN(int) git_reflog_write(git_reflog *reflog); | |
48 | ||
27df4275 | 49 | /** |
13c9e44a | 50 | * Add a new entry to the in-memory reflog. |
27df4275 MS |
51 | * |
52 | * `msg` is optional and can be NULL. | |
53 | * | |
40c75652 | 54 | * @param reflog an existing reflog object |
2508cc66 | 55 | * @param id the OID the reference is now pointing to |
27df4275 MS |
56 | * @param committer the signature of the committer |
57 | * @param msg the reflog message | |
e172cf08 | 58 | * @return 0 or an error code |
27df4275 | 59 | */ |
2508cc66 | 60 | GIT_EXTERN(int) git_reflog_append(git_reflog *reflog, const git_oid *id, const git_signature *committer, const char *msg); |
27df4275 | 61 | |
b7c93a66 | 62 | /** |
b976f3c2 | 63 | * Rename a reflog |
b7c93a66 | 64 | * |
33c33707 | 65 | * The reflog to be renamed is expected to already exist |
66 | * | |
80212ecb | 67 | * The new name will be checked for validity. |
68 | * See `git_reference_create_symbolic()` for rules about valid names. | |
69 | * | |
b976f3c2 CMN |
70 | * @param repo the repository |
71 | * @param old_name the old name of the reference | |
31b0cb51 | 72 | * @param name the new name of the reference |
80212ecb | 73 | * @return 0 on success, GIT_EINVALIDSPEC or an error code |
b7c93a66 | 74 | */ |
b976f3c2 | 75 | GIT_EXTERN(int) git_reflog_rename(git_repository *repo, const char *old_name, const char *name); |
b7c93a66 MS |
76 | |
77 | /** | |
78 | * Delete the reflog for the given reference | |
79 | * | |
b976f3c2 CMN |
80 | * @param repo the repository |
81 | * @param name the reflog to delete | |
e172cf08 | 82 | * @return 0 or an error code |
b7c93a66 | 83 | */ |
b976f3c2 | 84 | GIT_EXTERN(int) git_reflog_delete(git_repository *repo, const char *name); |
b7c93a66 | 85 | |
27df4275 MS |
86 | /** |
87 | * Get the number of log entries in a reflog | |
88 | * | |
89 | * @param reflog the previously loaded reflog | |
90 | * @return the number of log entries | |
91 | */ | |
2508cc66 | 92 | GIT_EXTERN(size_t) git_reflog_entrycount(git_reflog *reflog); |
27df4275 MS |
93 | |
94 | /** | |
95 | * Lookup an entry by its index | |
96 | * | |
b15df1d9 | 97 | * Requesting the reflog entry with an index of 0 (zero) will |
98 | * return the most recently created entry. | |
99 | * | |
27df4275 | 100 | * @param reflog a previously loaded reflog |
b15df1d9 | 101 | * @param idx the position of the entry to lookup. Should be greater than or |
102 | * equal to 0 (zero) and less than `git_reflog_entrycount()`. | |
f27f29b1 | 103 | * @return the entry; NULL if not found |
27df4275 | 104 | */ |
20363d58 | 105 | GIT_EXTERN(const git_reflog_entry *) git_reflog_entry_byindex(const git_reflog *reflog, size_t idx); |
27df4275 | 106 | |
59341a5d | 107 | /** |
108 | * Remove an entry from the reflog by its index | |
109 | * | |
f7ae3f75 | 110 | * To ensure there's no gap in the log history, set `rewrite_previous_entry` |
111 | * param value to 1. When deleting entry `n`, member old_oid of entry `n-1` | |
112 | * (if any) will be updated with the value of member new_oid of entry `n+1`. | |
59341a5d | 113 | * |
114 | * @param reflog a previously loaded reflog. | |
115 | * | |
b15df1d9 | 116 | * @param idx the position of the entry to remove. Should be greater than or |
117 | * equal to 0 (zero) and less than `git_reflog_entrycount()`. | |
59341a5d | 118 | * |
119 | * @param rewrite_previous_entry 1 to rewrite the history; 0 otherwise. | |
120 | * | |
1a764476 | 121 | * @return 0 on success, GIT_ENOTFOUND if the entry doesn't exist |
122 | * or an error code. | |
59341a5d | 123 | */ |
b84f75c3 | 124 | GIT_EXTERN(int) git_reflog_drop( |
59341a5d | 125 | git_reflog *reflog, |
b15df1d9 | 126 | size_t idx, |
59341a5d | 127 | int rewrite_previous_entry); |
128 | ||
27df4275 MS |
129 | /** |
130 | * Get the old oid | |
131 | * | |
132 | * @param entry a reflog entry | |
133 | * @return the old oid | |
134 | */ | |
2508cc66 | 135 | GIT_EXTERN(const git_oid *) git_reflog_entry_id_old(const git_reflog_entry *entry); |
27df4275 MS |
136 | |
137 | /** | |
138 | * Get the new oid | |
139 | * | |
140 | * @param entry a reflog entry | |
141 | * @return the new oid at this time | |
142 | */ | |
2508cc66 | 143 | GIT_EXTERN(const git_oid *) git_reflog_entry_id_new(const git_reflog_entry *entry); |
27df4275 MS |
144 | |
145 | /** | |
146 | * Get the committer of this entry | |
147 | * | |
148 | * @param entry a reflog entry | |
149 | * @return the committer | |
150 | */ | |
2508cc66 | 151 | GIT_EXTERN(const git_signature *) git_reflog_entry_committer(const git_reflog_entry *entry); |
27df4275 MS |
152 | |
153 | /** | |
2508cc66 | 154 | * Get the log message |
27df4275 MS |
155 | * |
156 | * @param entry a reflog entry | |
157 | * @return the log msg | |
158 | */ | |
2508cc66 | 159 | GIT_EXTERN(const char *) git_reflog_entry_message(const git_reflog_entry *entry); |
27df4275 MS |
160 | |
161 | /** | |
162 | * Free the reflog | |
163 | * | |
164 | * @param reflog reflog to free | |
165 | */ | |
166 | GIT_EXTERN(void) git_reflog_free(git_reflog *reflog); | |
167 | ||
168 | /** @} */ | |
169 | GIT_END_DECL | |
170 | #endif |