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 /**
8  * License: GPL-2.0(Linking Exception)
9  */
10 module libgit2.reflog;
11 
12 
13 private static import libgit2.oid;
14 private static import libgit2.types;
15 private import libgit2.common: GIT_EXTERN;
16 
17 /*
18  * @file git2/reflog.h
19  * @brief Git reflog management routines
20  * @defgroup git_reflog Git reflog management routines
21  * @ingroup Git
22  * @{
23  */
24 extern (C):
25 nothrow @nogc:
26 public:
27 
28 /**
29  * Read the reflog for the given reference
30  *
31  * If there is no reflog file for the given
32  * reference yet, an empty reflog object will
33  * be returned.
34  *
35  * The reflog must be freed manually by using
36  * git_reflog_free().
37  *
38  * Params:
39  *      out_ = pointer to reflog
40  *      repo = the repository
41  *      name = reference to look up
42  *
43  * Returns: 0 or an error code
44  */
45 @GIT_EXTERN
46 int git_reflog_read(libgit2.types.git_reflog** out_, libgit2.types.git_repository* repo, const (char)* name);
47 
48 /**
49  * Write an existing in-memory reflog object back to disk
50  * using an atomic file lock.
51  *
52  * Params:
53  *      reflog = an existing reflog object
54  *
55  * Returns: 0 or an error code
56  */
57 @GIT_EXTERN
58 int git_reflog_write(libgit2.types.git_reflog* reflog);
59 
60 /**
61  * Add a new entry to the in-memory reflog.
62  *
63  * `msg` is optional and can be null.
64  *
65  * Params:
66  *      reflog = an existing reflog object
67  *      id = the OID the reference is now pointing to
68  *      committer = the signature of the committer
69  *      msg = the reflog message
70  *
71  * Returns: 0 or an error code
72  */
73 @GIT_EXTERN
74 int git_reflog_append(libgit2.types.git_reflog* reflog, const (libgit2.oid.git_oid)* id, const (libgit2.types.git_signature)* committer, const (char)* msg);
75 
76 /**
77  * Rename a reflog
78  *
79  * The reflog to be renamed is expected to already exist
80  *
81  * The new name will be checked for validity.
82  * See `git_reference_create_symbolic()` for rules about valid names.
83  *
84  * Params:
85  *      repo = the repository
86  *      old_name = the old name of the reference
87  *      name = the new name of the reference
88  *
89  * Returns: 0 on success, git_error_code.GIT_EINVALIDSPEC or an error code
90  */
91 @GIT_EXTERN
92 int git_reflog_rename(libgit2.types.git_repository* repo, const (char)* old_name, const (char)* name);
93 
94 /**
95  * Delete the reflog for the given reference
96  *
97  * Params:
98  *      repo = the repository
99  *      name = the reflog to delete
100  *
101  * Returns: 0 or an error code
102  */
103 @GIT_EXTERN
104 int git_reflog_delete(libgit2.types.git_repository* repo, const (char)* name);
105 
106 /**
107  * Get the number of log entries in a reflog
108  *
109  * Params:
110  *      reflog = the previously loaded reflog
111  *
112  * Returns: the number of log entries
113  */
114 @GIT_EXTERN
115 size_t git_reflog_entrycount(libgit2.types.git_reflog* reflog);
116 
117 /**
118  * Lookup an entry by its index
119  *
120  * Requesting the reflog entry with an index of 0 (zero) will
121  * return the most recently created entry.
122  *
123  * Params:
124  *      reflog = a previously loaded reflog
125  *      idx = the position of the entry to lookup. Should be greater than or equal to 0 (zero) and less than `git_reflog_entrycount()`.
126  *
127  * Returns: the entry; null if not found
128  */
129 @GIT_EXTERN
130 const (libgit2.types.git_reflog_entry)* git_reflog_entry_byindex(const (libgit2.types.git_reflog)* reflog, size_t idx);
131 
132 /**
133  * Remove an entry from the reflog by its index
134  *
135  * To ensure there's no gap in the log history, set `rewrite_previous_entry`
136  * param value to 1. When deleting entry `n`, member old_oid of entry `n-1`
137  * (if any) will be updated with the value of member new_oid of entry `n+1`.
138  *
139  * Params:
140  *      reflog = a previously loaded reflog.
141  *      idx = the position of the entry to remove. Should be greater than or equal to 0 (zero) and less than `git_reflog_entrycount()`.
142  *      rewrite_previous_entry = 1 to rewrite the history; 0 otherwise.
143  *
144  * Returns: 0 on success, git_error_code.GIT_ENOTFOUND if the entry doesn't exist or an error code.
145  */
146 @GIT_EXTERN
147 int git_reflog_drop(libgit2.types.git_reflog* reflog, size_t idx, int rewrite_previous_entry);
148 
149 /**
150  * Get the old oid
151  *
152  * Params:
153  *      entry = a reflog entry
154  *
155  * Returns: the old oid
156  */
157 @GIT_EXTERN
158 const (libgit2.oid.git_oid)* git_reflog_entry_id_old(const (libgit2.types.git_reflog_entry)* entry);
159 
160 /**
161  * Get the new oid
162  *
163  * Params:
164  *      entry = a reflog entry
165  *
166  * Returns: the new oid at this time
167  */
168 @GIT_EXTERN
169 const (libgit2.oid.git_oid)* git_reflog_entry_id_new(const (libgit2.types.git_reflog_entry)* entry);
170 
171 /**
172  * Get the committer of this entry
173  *
174  * Params:
175  *      entry = a reflog entry
176  *
177  * Returns: the committer
178  */
179 @GIT_EXTERN
180 const (libgit2.types.git_signature)* git_reflog_entry_committer(const (libgit2.types.git_reflog_entry)* entry);
181 
182 /**
183  * Get the log message
184  *
185  * Params:
186  *      entry = a reflog entry
187  *
188  * Returns: the log msg
189  */
190 @GIT_EXTERN
191 const (char)* git_reflog_entry_message(const (libgit2.types.git_reflog_entry)* entry);
192 
193 /**
194  * Free the reflog
195  *
196  * Params:
197  *      reflog = reflog to free
198  */
199 @GIT_EXTERN
200 void git_reflog_free(libgit2.types.git_reflog* reflog);
201 
202 /* @} */