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.revwalk;
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/revwalk.h
19  * @brief Git revision traversal routines
20  * @defgroup git_revwalk Git revision traversal routines
21  * @ingroup Git
22  * @{
23  */
24 extern (C):
25 nothrow @nogc:
26 public:
27 
28 /**
29  * Flags to specify the sorting which a revwalk should perform.
30  */
31 enum git_sort_t
32 {
33 	/**
34 	 * Sort the output with the same default method from `git`: reverse
35 	 * chronological order. This is the default sorting for new walkers.
36 	 */
37 	GIT_SORT_NONE = 0,
38 
39 	/**
40 	 * Sort the repository contents in topological order (no parents before
41 	 * all of its children are shown); this sorting mode can be combined
42 	 * with time sorting to produce `git`'s `--date-order``.
43 	 */
44 	GIT_SORT_TOPOLOGICAL = 1 << 0,
45 
46 	/**
47 	 * Sort the repository contents by commit time;
48 	 * this sorting mode can be combined with
49 	 * topological sorting.
50 	 */
51 	GIT_SORT_TIME = 1 << 1,
52 
53 	/**
54 	 * Iterate through the repository contents in reverse
55 	 * order; this sorting mode can be combined with
56 	 * any of the above.
57 	 */
58 	GIT_SORT_REVERSE = 1 << 2,
59 }
60 
61 //Declaration name in C language
62 enum
63 {
64 	GIT_SORT_NONE = .git_sort_t.GIT_SORT_NONE,
65 	GIT_SORT_TOPOLOGICAL = .git_sort_t.GIT_SORT_TOPOLOGICAL,
66 	GIT_SORT_TIME = .git_sort_t.GIT_SORT_TIME,
67 	GIT_SORT_REVERSE = .git_sort_t.GIT_SORT_REVERSE,
68 }
69 
70 /**
71  * Allocate a new revision walker to iterate through a repo.
72  *
73  * This revision walker uses a custom memory pool and an internal
74  * commit cache, so it is relatively expensive to allocate.
75  *
76  * For maximum performance, this revision walker should be
77  * reused for different walks.
78  *
79  * This revision walker is *not* thread safe: it may only be
80  * used to walk a repository on a single thread; however,
81  * it is possible to have several revision walkers in
82  * several different threads walking the same repository.
83  *
84  * Params:
85  *      out_ = pointer to the new revision walker
86  *      repo = the repo to walk through
87  *
88  * Returns: 0 or an error code
89  */
90 @GIT_EXTERN
91 int git_revwalk_new(libgit2.types.git_revwalk** out_, libgit2.types.git_repository* repo);
92 
93 /**
94  * Reset the revision walker for reuse.
95  *
96  * This will clear all the pushed and hidden commits, and
97  * leave the walker in a blank state (just like at
98  * creation) ready to receive new commit pushes and
99  * start a new walk.
100  *
101  * The revision walk is automatically reset when a walk
102  * is over.
103  *
104  * Params:
105  *      walker = handle to reset.
106  *
107  * Returns: 0 or an error code
108  */
109 @GIT_EXTERN
110 int git_revwalk_reset(libgit2.types.git_revwalk* walker);
111 
112 /**
113  * Add a new root for the traversal
114  *
115  * The pushed commit will be marked as one of the roots from which to
116  * start the walk. This commit may not be walked if it or a child is
117  * hidden.
118  *
119  * At least one commit must be pushed onto the walker before a walk
120  * can be started.
121  *
122  * The given id must belong to a committish on the walked
123  * repository.
124  *
125  * Params:
126  *      walk = the walker being used for the traversal.
127  *      id = the oid of the commit to start from.
128  *
129  * Returns: 0 or an error code
130  */
131 @GIT_EXTERN
132 int git_revwalk_push(libgit2.types.git_revwalk* walk, const (libgit2.oid.git_oid)* id);
133 
134 /**
135  * Push matching references
136  *
137  * The OIDs pointed to by the references that match the given glob
138  * pattern will be pushed to the revision walker.
139  *
140  * A leading 'refs/' is implied if not present as well as a trailing
141  * '/\*' if the glob lacks '?', '\*' or '['.
142  *
143  * Any references matching this glob which do not point to a
144  * committish will be ignored.
145  *
146  * Params:
147  *      walk = the walker being used for the traversal
148  *      glob = the glob pattern references should match
149  *
150  * Returns: 0 or an error code
151  */
152 @GIT_EXTERN
153 int git_revwalk_push_glob(libgit2.types.git_revwalk* walk, const (char)* glob);
154 
155 /**
156  * Push the repository's HEAD
157  *
158  * Params:
159  *      walk = the walker being used for the traversal
160  *
161  * Returns: 0 or an error code
162  */
163 @GIT_EXTERN
164 int git_revwalk_push_head(libgit2.types.git_revwalk* walk);
165 
166 /**
167  * Mark a commit (and its ancestors) uninteresting for the output.
168  *
169  * The given id must belong to a committish on the walked
170  * repository.
171  *
172  * The resolved commit and all its parents will be hidden from the
173  * output on the revision walk.
174  *
175  * Params:
176  *      walk = the walker being used for the traversal.
177  *      commit_id = the oid of commit that will be ignored during the traversal
178  *
179  * Returns: 0 or an error code
180  */
181 @GIT_EXTERN
182 int git_revwalk_hide(libgit2.types.git_revwalk* walk, const (libgit2.oid.git_oid)* commit_id);
183 
184 /**
185  * Hide matching references.
186  *
187  * The OIDs pointed to by the references that match the given glob
188  * pattern and their ancestors will be hidden from the output on the
189  * revision walk.
190  *
191  * A leading 'refs/' is implied if not present as well as a trailing
192  * '/\*' if the glob lacks '?', '\*' or '['.
193  *
194  * Any references matching this glob which do not point to a
195  * committish will be ignored.
196  *
197  * Params:
198  *      walk = the walker being used for the traversal
199  *      glob = the glob pattern references should match
200  *
201  * Returns: 0 or an error code
202  */
203 @GIT_EXTERN
204 int git_revwalk_hide_glob(libgit2.types.git_revwalk* walk, const (char)* glob);
205 
206 /**
207  * Hide the repository's HEAD
208  *
209  * Params:
210  *      walk = the walker being used for the traversal
211  *
212  * Returns: 0 or an error code
213  */
214 @GIT_EXTERN
215 int git_revwalk_hide_head(libgit2.types.git_revwalk* walk);
216 
217 /**
218  * Push the OID pointed to by a reference
219  *
220  * The reference must point to a committish.
221  *
222  * Params:
223  *      walk = the walker being used for the traversal
224  *      refname = the reference to push
225  *
226  * Returns: 0 or an error code
227  */
228 @GIT_EXTERN
229 int git_revwalk_push_ref(libgit2.types.git_revwalk* walk, const (char)* refname);
230 
231 /**
232  * Hide the OID pointed to by a reference
233  *
234  * The reference must point to a committish.
235  *
236  * Params:
237  *      walk = the walker being used for the traversal
238  *      refname = the reference to hide
239  *
240  * Returns: 0 or an error code
241  */
242 @GIT_EXTERN
243 int git_revwalk_hide_ref(libgit2.types.git_revwalk* walk, const (char)* refname);
244 
245 /**
246  * Get the next commit from the revision walk.
247  *
248  * The initial call to this method is *not* blocking when
249  * iterating through a repo with a time-sorting mode.
250  *
251  * Iterating with Topological or inverted modes makes the initial
252  * call blocking to preprocess the commit list, but this block should be
253  * mostly unnoticeable on most repositories (topological preprocessing
254  * times at 0.3s on the git.git repo).
255  *
256  * The revision walker is reset when the walk is over.
257  *
258  * Params:
259  *      out_ = Pointer where to store the oid of the next commit
260  *      walk = the walker to pop the commit from.
261  *
262  * Returns: 0 if the next commit was found; git_error_code.GIT_ITEROVER if there are no commits left to iterate
263  */
264 @GIT_EXTERN
265 int git_revwalk_next(libgit2.oid.git_oid* out_, libgit2.types.git_revwalk* walk);
266 
267 /**
268  * Change the sorting mode when iterating through the
269  * repository's contents.
270  *
271  * Changing the sorting mode resets the walker.
272  *
273  * Params:
274  *      walk = the walker being used for the traversal.
275  *      sort_mode = combination of GIT_SORT_XXX flags
276  *
277  * Returns: 0 or an error code
278  */
279 @GIT_EXTERN
280 int git_revwalk_sorting(libgit2.types.git_revwalk* walk, uint sort_mode);
281 
282 /**
283  * Push and hide the respective endpoints of the given range.
284  *
285  * The range should be of the form
286  *   <commit>..<commit>
287  * where each <commit> is in the form accepted by 'git_revparse_single'.
288  * The left-hand commit will be hidden and the right-hand commit pushed.
289  *
290  * Params:
291  *      walk = the walker being used for the traversal
292  *      range = the range
293  *
294  * Returns: 0 or an error code
295  *
296  */
297 @GIT_EXTERN
298 int git_revwalk_push_range(libgit2.types.git_revwalk* walk, const (char)* range);
299 
300 /**
301  * Simplify the history by first-parent
302  *
303  * No parents other than the first for each commit will be enqueued.
304  *
305  * Params:
306  *      walk = The revision walker.
307  *
308  * Returns: 0 or an error code
309  */
310 @GIT_EXTERN
311 int git_revwalk_simplify_first_parent(libgit2.types.git_revwalk* walk);
312 
313 /**
314  * Free a revision walker previously allocated.
315  *
316  * Params:
317  *      walk = traversal handle to close. If null nothing occurs.
318  */
319 @GIT_EXTERN
320 void git_revwalk_free(libgit2.types.git_revwalk* walk);
321 
322 /**
323  * Return the repository on which this walker
324  * is operating.
325  *
326  * Params:
327  *      walk = the revision walker
328  *
329  * Returns: the repository being walked
330  */
331 @GIT_EXTERN
332 libgit2.types.git_repository* git_revwalk_repository(libgit2.types.git_revwalk* walk);
333 
334 /**
335  * This is a callback function that user can provide to hide a
336  * commit and its parents. If the callback function returns non-zero value,
337  * then this commit and its parents will be hidden.
338  *
339  * Returns: non-zero to hide the commmit and it parent.
340  */
341 /*
342  * Params:
343  *      commit_id = oid of Commit
344  *      payload = User-specified pointer to data to be passed as data payload
345  */
346 alias git_revwalk_hide_cb = int function(const (libgit2.oid.git_oid)* commit_id, void* payload);
347 
348 /**
349  * Adds, changes or removes a callback function to hide a commit and its parents
350  *
351  * Params:
352  *      walk = the revision walker
353  *      hide_cb = callback function to hide a commit and its parents
354  *      payload = data payload to be passed to callback function
355  *
356  * Returns: 0 or an error code.
357  */
358 @GIT_EXTERN
359 int git_revwalk_add_hide_cb(libgit2.types.git_revwalk* walk, .git_revwalk_hide_cb hide_cb, void* payload);
360 
361 /* @} */