Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:38

0001 /*
0002  * Copyright (C) the libgit2 contributors. All rights reserved.
0003  *
0004  * This file is part of libgit2, distributed under the GNU GPL v2 with
0005  * a Linking Exception. For full terms see the included COPYING file.
0006  */
0007 #ifndef INCLUDE_git_revwalk_h__
0008 #define INCLUDE_git_revwalk_h__
0009 
0010 #include "common.h"
0011 #include "types.h"
0012 #include "oid.h"
0013 
0014 /**
0015  * @file git2/revwalk.h
0016  * @brief Git revision traversal routines
0017  * @defgroup git_revwalk Git revision traversal routines
0018  * @ingroup Git
0019  * @{
0020  */
0021 GIT_BEGIN_DECL
0022 
0023 /**
0024  * Flags to specify the sorting which a revwalk should perform.
0025  */
0026 typedef enum {
0027     /**
0028      * Sort the output with the same default method from `git`: reverse
0029      * chronological order. This is the default sorting for new walkers.
0030      */
0031     GIT_SORT_NONE = 0,
0032 
0033     /**
0034      * Sort the repository contents in topological order (no parents before
0035      * all of its children are shown); this sorting mode can be combined
0036      * with time sorting to produce `git`'s `--date-order``.
0037      */
0038     GIT_SORT_TOPOLOGICAL = 1 << 0,
0039 
0040     /**
0041      * Sort the repository contents by commit time;
0042      * this sorting mode can be combined with
0043      * topological sorting.
0044      */
0045     GIT_SORT_TIME = 1 << 1,
0046 
0047     /**
0048      * Iterate through the repository contents in reverse
0049      * order; this sorting mode can be combined with
0050      * any of the above.
0051      */
0052     GIT_SORT_REVERSE = 1 << 2
0053 } git_sort_t;
0054 
0055 /**
0056  * Allocate a new revision walker to iterate through a repo.
0057  *
0058  * This revision walker uses a custom memory pool and an internal
0059  * commit cache, so it is relatively expensive to allocate.
0060  *
0061  * For maximum performance, this revision walker should be
0062  * reused for different walks.
0063  *
0064  * This revision walker is *not* thread safe: it may only be
0065  * used to walk a repository on a single thread; however,
0066  * it is possible to have several revision walkers in
0067  * several different threads walking the same repository.
0068  *
0069  * @param out pointer to the new revision walker
0070  * @param repo the repo to walk through
0071  * @return 0 or an error code
0072  */
0073 GIT_EXTERN(int) git_revwalk_new(git_revwalk **out, git_repository *repo);
0074 
0075 /**
0076  * Reset the revision walker for reuse.
0077  *
0078  * This will clear all the pushed and hidden commits, and
0079  * leave the walker in a blank state (just like at
0080  * creation) ready to receive new commit pushes and
0081  * start a new walk.
0082  *
0083  * The revision walk is automatically reset when a walk
0084  * is over.
0085  *
0086  * @param walker handle to reset.
0087  * @return 0 or an error code
0088  */
0089 GIT_EXTERN(int) git_revwalk_reset(git_revwalk *walker);
0090 
0091 /**
0092  * Add a new root for the traversal
0093  *
0094  * The pushed commit will be marked as one of the roots from which to
0095  * start the walk. This commit may not be walked if it or a child is
0096  * hidden.
0097  *
0098  * At least one commit must be pushed onto the walker before a walk
0099  * can be started.
0100  *
0101  * The given id must belong to a committish on the walked
0102  * repository.
0103  *
0104  * @param walk the walker being used for the traversal.
0105  * @param id the oid of the commit to start from.
0106  * @return 0 or an error code
0107  */
0108 GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, const git_oid *id);
0109 
0110 /**
0111  * Push matching references
0112  *
0113  * The OIDs pointed to by the references that match the given glob
0114  * pattern will be pushed to the revision walker.
0115  *
0116  * A leading 'refs/' is implied if not present as well as a trailing
0117  * '/\*' if the glob lacks '?', '\*' or '['.
0118  *
0119  * Any references matching this glob which do not point to a
0120  * committish will be ignored.
0121  *
0122  * @param walk the walker being used for the traversal
0123  * @param glob the glob pattern references should match
0124  * @return 0 or an error code
0125  */
0126 GIT_EXTERN(int) git_revwalk_push_glob(git_revwalk *walk, const char *glob);
0127 
0128 /**
0129  * Push the repository's HEAD
0130  *
0131  * @param walk the walker being used for the traversal
0132  * @return 0 or an error code
0133  */
0134 GIT_EXTERN(int) git_revwalk_push_head(git_revwalk *walk);
0135 
0136 /**
0137  * Mark a commit (and its ancestors) uninteresting for the output.
0138  *
0139  * The given id must belong to a committish on the walked
0140  * repository.
0141  *
0142  * The resolved commit and all its parents will be hidden from the
0143  * output on the revision walk.
0144  *
0145  * @param walk the walker being used for the traversal.
0146  * @param commit_id the oid of commit that will be ignored during the traversal
0147  * @return 0 or an error code
0148  */
0149 GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, const git_oid *commit_id);
0150 
0151 /**
0152  * Hide matching references.
0153  *
0154  * The OIDs pointed to by the references that match the given glob
0155  * pattern and their ancestors will be hidden from the output on the
0156  * revision walk.
0157  *
0158  * A leading 'refs/' is implied if not present as well as a trailing
0159  * '/\*' if the glob lacks '?', '\*' or '['.
0160  *
0161  * Any references matching this glob which do not point to a
0162  * committish will be ignored.
0163  *
0164  * @param walk the walker being used for the traversal
0165  * @param glob the glob pattern references should match
0166  * @return 0 or an error code
0167  */
0168 GIT_EXTERN(int) git_revwalk_hide_glob(git_revwalk *walk, const char *glob);
0169 
0170 /**
0171  * Hide the repository's HEAD
0172  *
0173  * @param walk the walker being used for the traversal
0174  * @return 0 or an error code
0175  */
0176 GIT_EXTERN(int) git_revwalk_hide_head(git_revwalk *walk);
0177 
0178 /**
0179  * Push the OID pointed to by a reference
0180  *
0181  * The reference must point to a committish.
0182  *
0183  * @param walk the walker being used for the traversal
0184  * @param refname the reference to push
0185  * @return 0 or an error code
0186  */
0187 GIT_EXTERN(int) git_revwalk_push_ref(git_revwalk *walk, const char *refname);
0188 
0189 /**
0190  * Hide the OID pointed to by a reference
0191  *
0192  * The reference must point to a committish.
0193  *
0194  * @param walk the walker being used for the traversal
0195  * @param refname the reference to hide
0196  * @return 0 or an error code
0197  */
0198 GIT_EXTERN(int) git_revwalk_hide_ref(git_revwalk *walk, const char *refname);
0199 
0200 /**
0201  * Get the next commit from the revision walk.
0202  *
0203  * The initial call to this method is *not* blocking when
0204  * iterating through a repo with a time-sorting mode.
0205  *
0206  * Iterating with Topological or inverted modes makes the initial
0207  * call blocking to preprocess the commit list, but this block should be
0208  * mostly unnoticeable on most repositories (topological preprocessing
0209  * times at 0.3s on the git.git repo).
0210  *
0211  * The revision walker is reset when the walk is over.
0212  *
0213  * @param out Pointer where to store the oid of the next commit
0214  * @param walk the walker to pop the commit from.
0215  * @return 0 if the next commit was found;
0216  *  GIT_ITEROVER if there are no commits left to iterate
0217  */
0218 GIT_EXTERN(int) git_revwalk_next(git_oid *out, git_revwalk *walk);
0219 
0220 /**
0221  * Change the sorting mode when iterating through the
0222  * repository's contents.
0223  *
0224  * Changing the sorting mode resets the walker.
0225  *
0226  * @param walk the walker being used for the traversal.
0227  * @param sort_mode combination of GIT_SORT_XXX flags
0228  * @return 0 or an error code
0229  */
0230 GIT_EXTERN(int) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode);
0231 
0232 /**
0233  * Push and hide the respective endpoints of the given range.
0234  *
0235  * The range should be of the form
0236  *   <commit>..<commit>
0237  * where each <commit> is in the form accepted by 'git_revparse_single'.
0238  * The left-hand commit will be hidden and the right-hand commit pushed.
0239  *
0240  * @param walk the walker being used for the traversal
0241  * @param range the range
0242  * @return 0 or an error code
0243  *
0244  */
0245 GIT_EXTERN(int) git_revwalk_push_range(git_revwalk *walk, const char *range);
0246 
0247 /**
0248  * Simplify the history by first-parent
0249  *
0250  * No parents other than the first for each commit will be enqueued.
0251  *
0252  * @param walk The revision walker.
0253  * @return 0 or an error code
0254  */
0255 GIT_EXTERN(int) git_revwalk_simplify_first_parent(git_revwalk *walk);
0256 
0257 
0258 /**
0259  * Free a revision walker previously allocated.
0260  *
0261  * @param walk traversal handle to close. If NULL nothing occurs.
0262  */
0263 GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk);
0264 
0265 /**
0266  * Return the repository on which this walker
0267  * is operating.
0268  *
0269  * @param walk the revision walker
0270  * @return the repository being walked
0271  */
0272 GIT_EXTERN(git_repository *) git_revwalk_repository(git_revwalk *walk);
0273 
0274 /**
0275  * This is a callback function that user can provide to hide a
0276  * commit and its parents. If the callback function returns non-zero value,
0277  * then this commit and its parents will be hidden.
0278  *
0279  * @param commit_id oid of Commit
0280  * @param payload User-specified pointer to data to be passed as data payload
0281  * @return non-zero to hide the commmit and it parent.
0282  */
0283 typedef int GIT_CALLBACK(git_revwalk_hide_cb)(
0284     const git_oid *commit_id,
0285     void *payload);
0286 
0287 /**
0288  * Adds, changes or removes a callback function to hide a commit and its parents
0289  *
0290  * @param walk the revision walker
0291  * @param hide_cb  callback function to hide a commit and its parents
0292  * @param payload  data payload to be passed to callback function
0293  * @return 0 or an error code.
0294  */
0295 GIT_EXTERN(int) git_revwalk_add_hide_cb(
0296     git_revwalk *walk,
0297     git_revwalk_hide_cb hide_cb,
0298     void *payload);
0299 
0300 /** @} */
0301 GIT_END_DECL
0302 #endif