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