]> git.proxmox.com Git - libgit2.git/blame - include/git2/reflog.h
reflog: prevent git_reflog_read() from chocking when no log exists yet
[libgit2.git] / include / git2 / reflog.h
CommitLineData
27df4275 1/*
5e0de328 2 * Copyright (C) 2009-2012 the libgit2 contributors
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 */
21GIT_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 *
33 * @param reflog pointer to reflog
34 * @param ref reference to read the reflog for
e172cf08 35 * @return 0 or an error code
27df4275
MS
36 */
37GIT_EXTERN(int) git_reflog_read(git_reflog **reflog, git_reference *ref);
38
bd72425d 39/**
40 * Write an existing in-memory reflog object back to disk
41 * using an atomic file lock.
42 *
43 * @param reflog an existing reflog object
44 * @return 0 or an error code
45 */
46GIT_EXTERN(int) git_reflog_write(git_reflog *reflog);
47
27df4275 48/**
d284b3de 49 * Add a new entry to the reflog for the given reference
27df4275
MS
50 *
51 * If there is no reflog file for the given
52 * reference yet, it will be created.
53 *
54 * `oid_old` may be NULL in case it's a new reference.
55 *
56 * `msg` is optional and can be NULL.
57 *
58 * @param ref the changed reference
59 * @param oid_old the OID the reference was pointing to
60 * @param committer the signature of the committer
61 * @param msg the reflog message
e172cf08 62 * @return 0 or an error code
27df4275 63 */
d284b3de 64GIT_EXTERN(int) git_reflog_append(git_reference *ref, const git_oid *oid_old, const git_signature *committer, const char *msg);
27df4275 65
b7c93a66
MS
66/**
67 * Rename the reflog for the given reference
68 *
33c33707 69 * The reflog to be renamed is expected to already exist
70 *
b7c93a66
MS
71 * @param ref the reference
72 * @param new_name the new name of the reference
e172cf08 73 * @return 0 or an error code
b7c93a66
MS
74 */
75GIT_EXTERN(int) git_reflog_rename(git_reference *ref, const char *new_name);
76
77/**
78 * Delete the reflog for the given reference
79 *
80 * @param ref the reference
e172cf08 81 * @return 0 or an error code
b7c93a66
MS
82 */
83GIT_EXTERN(int) git_reflog_delete(git_reference *ref);
84
27df4275
MS
85/**
86 * Get the number of log entries in a reflog
87 *
88 * @param reflog the previously loaded reflog
89 * @return the number of log entries
90 */
91GIT_EXTERN(unsigned int) git_reflog_entrycount(git_reflog *reflog);
92
93/**
94 * Lookup an entry by its index
95 *
96 * @param reflog a previously loaded reflog
97 * @param idx the position to lookup
f27f29b1 98 * @return the entry; NULL if not found
27df4275
MS
99 */
100GIT_EXTERN(const git_reflog_entry *) git_reflog_entry_byindex(git_reflog *reflog, unsigned int idx);
101
59341a5d 102/**
103 * Remove an entry from the reflog by its index
104 *
105 * To ensure there's no gap in the log history, set the `rewrite_previosu_entry` to 1.
106 * When deleting entry `n`, member old_oid of entry `n-1` (if any) will be updated with
107 * the value of memeber new_oid of entry `n+1`.
108 *
109 * @param reflog a previously loaded reflog.
110 *
111 * @param idx the position of the entry to remove.
112 *
113 * @param rewrite_previous_entry 1 to rewrite the history; 0 otherwise.
114 *
115 * @return 0 on success or an error code.
116 */
117GIT_EXTERN(int) git_reflog_entry_drop(
118 git_reflog *reflog,
119 unsigned int idx,
120 int rewrite_previous_entry);
121
27df4275
MS
122/**
123 * Get the old oid
124 *
125 * @param entry a reflog entry
126 * @return the old oid
127 */
e7be57a9 128GIT_EXTERN(const git_oid *) git_reflog_entry_oidold(const git_reflog_entry *entry);
27df4275
MS
129
130/**
131 * Get the new oid
132 *
133 * @param entry a reflog entry
134 * @return the new oid at this time
135 */
e7be57a9 136GIT_EXTERN(const git_oid *) git_reflog_entry_oidnew(const git_reflog_entry *entry);
27df4275
MS
137
138/**
139 * Get the committer of this entry
140 *
141 * @param entry a reflog entry
142 * @return the committer
143 */
144GIT_EXTERN(git_signature *) git_reflog_entry_committer(const git_reflog_entry *entry);
145
146/**
147 * Get the log msg
148 *
149 * @param entry a reflog entry
150 * @return the log msg
151 */
152GIT_EXTERN(char *) git_reflog_entry_msg(const git_reflog_entry *entry);
153
154/**
155 * Free the reflog
156 *
157 * @param reflog reflog to free
158 */
159GIT_EXTERN(void) git_reflog_free(git_reflog *reflog);
160
161/** @} */
162GIT_END_DECL
163#endif