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