Blame include/git2/revwalk.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
#ifndef INCLUDE_git_revwalk_h__
Packit Service 20376f
#define INCLUDE_git_revwalk_h__
Packit Service 20376f
Packit Service 20376f
#include "common.h"
Packit Service 20376f
#include "types.h"
Packit Service 20376f
#include "oid.h"
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * @file git2/revwalk.h
Packit Service 20376f
 * @brief Git revision traversal routines
Packit Service 20376f
 * @defgroup git_revwalk Git revision traversal routines
Packit Service 20376f
 * @ingroup Git
Packit Service 20376f
 * @{
Packit Service 20376f
 */
Packit Service 20376f
GIT_BEGIN_DECL
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Flags to specify the sorting which a revwalk should perform.
Packit Service 20376f
 */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	/**
Packit Service 20376f
	 * Sort the output with the same default time-order method from git.
Packit Service 20376f
	 * This is the default sorting for new walkers.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_SORT_NONE = 0,
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Sort the repository contents in topological order (parents before
Packit Service 20376f
	 * children); this sorting mode can be combined with time sorting to
Packit Service 20376f
	 * produce git's "time-order".
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_SORT_TOPOLOGICAL = 1 << 0,
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Sort the repository contents by commit time;
Packit Service 20376f
	 * this sorting mode can be combined with
Packit Service 20376f
	 * topological sorting.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_SORT_TIME = 1 << 1,
Packit Service 20376f
Packit Service 20376f
	/**
Packit Service 20376f
	 * Iterate through the repository contents in reverse
Packit Service 20376f
	 * order; this sorting mode can be combined with
Packit Service 20376f
	 * any of the above.
Packit Service 20376f
	 */
Packit Service 20376f
	GIT_SORT_REVERSE = 1 << 2,
Packit Service 20376f
} git_sort_t;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Allocate a new revision walker to iterate through a repo.
Packit Service 20376f
 *
Packit Service 20376f
 * This revision walker uses a custom memory pool and an internal
Packit Service 20376f
 * commit cache, so it is relatively expensive to allocate.
Packit Service 20376f
 *
Packit Service 20376f
 * For maximum performance, this revision walker should be
Packit Service 20376f
 * reused for different walks.
Packit Service 20376f
 *
Packit Service 20376f
 * This revision walker is *not* thread safe: it may only be
Packit Service 20376f
 * used to walk a repository on a single thread; however,
Packit Service 20376f
 * it is possible to have several revision walkers in
Packit Service 20376f
 * several different threads walking the same repository.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out pointer to the new revision walker
Packit Service 20376f
 * @param repo the repo to walk through
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_revwalk_new(git_revwalk **out, git_repository *repo);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Reset the revision walker for reuse.
Packit Service 20376f
 *
Packit Service 20376f
 * This will clear all the pushed and hidden commits, and
Packit Service 20376f
 * leave the walker in a blank state (just like at
Packit Service 20376f
 * creation) ready to receive new commit pushes and
Packit Service 20376f
 * start a new walk.
Packit Service 20376f
 *
Packit Service 20376f
 * The revision walk is automatically reset when a walk
Packit Service 20376f
 * is over.
Packit Service 20376f
 *
Packit Service 20376f
 * @param walker handle to reset.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_revwalk_reset(git_revwalk *walker);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Add a new root for the traversal
Packit Service 20376f
 *
Packit Service 20376f
 * The pushed commit will be marked as one of the roots from which to
Packit Service 20376f
 * start the walk. This commit may not be walked if it or a child is
Packit Service 20376f
 * hidden.
Packit Service 20376f
 *
Packit Service 20376f
 * At least one commit must be pushed onto the walker before a walk
Packit Service 20376f
 * can be started.
Packit Service 20376f
 *
Packit Service 20376f
 * The given id must belong to a committish on the walked
Packit Service 20376f
 * repository.
Packit Service 20376f
 *
Packit Service 20376f
 * @param walk the walker being used for the traversal.
Packit Service 20376f
 * @param id the oid of the commit to start from.
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, const git_oid *id);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Push matching references
Packit Service 20376f
 *
Packit Service 20376f
 * The OIDs pointed to by the references that match the given glob
Packit Service 20376f
 * pattern will be pushed to the revision walker.
Packit Service 20376f
 *
Packit Service 20376f
 * A leading 'refs/' is implied if not present as well as a trailing
Packit Service 20376f
 * '/\*' if the glob lacks '?', '\*' or '['.
Packit Service 20376f
 *
Packit Service 20376f
 * Any references matching this glob which do not point to a
Packit Service 20376f
 * committish will be ignored.
Packit Service 20376f
 *
Packit Service 20376f
 * @param walk the walker being used for the traversal
Packit Service 20376f
 * @param glob the glob pattern references should match
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_revwalk_push_glob(git_revwalk *walk, const char *glob);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Push the repository's HEAD
Packit Service 20376f
 *
Packit Service 20376f
 * @param walk the walker being used for the traversal
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_revwalk_push_head(git_revwalk *walk);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Mark a commit (and its ancestors) uninteresting for the output.
Packit Service 20376f
 *
Packit Service 20376f
 * The given id must belong to a committish on the walked
Packit Service 20376f
 * repository.
Packit Service 20376f
 *
Packit Service 20376f
 * The resolved commit and all its parents will be hidden from the
Packit Service 20376f
 * output on the revision walk.
Packit Service 20376f
 *
Packit Service 20376f
 * @param walk the walker being used for the traversal.
Packit Service 20376f
 * @param commit_id the oid of commit that will be ignored during the traversal
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, const git_oid *commit_id);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Hide matching references.
Packit Service 20376f
 *
Packit Service 20376f
 * The OIDs pointed to by the references that match the given glob
Packit Service 20376f
 * pattern and their ancestors will be hidden from the output on the
Packit Service 20376f
 * revision walk.
Packit Service 20376f
 *
Packit Service 20376f
 * A leading 'refs/' is implied if not present as well as a trailing
Packit Service 20376f
 * '/\*' if the glob lacks '?', '\*' or '['.
Packit Service 20376f
 *
Packit Service 20376f
 * Any references matching this glob which do not point to a
Packit Service 20376f
 * committish will be ignored.
Packit Service 20376f
 *
Packit Service 20376f
 * @param walk the walker being used for the traversal
Packit Service 20376f
 * @param glob the glob pattern references should match
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_revwalk_hide_glob(git_revwalk *walk, const char *glob);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Hide the repository's HEAD
Packit Service 20376f
 *
Packit Service 20376f
 * @param walk the walker being used for the traversal
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_revwalk_hide_head(git_revwalk *walk);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Push the OID pointed to by a reference
Packit Service 20376f
 *
Packit Service 20376f
 * The reference must point to a committish.
Packit Service 20376f
 *
Packit Service 20376f
 * @param walk the walker being used for the traversal
Packit Service 20376f
 * @param refname the reference to push
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_revwalk_push_ref(git_revwalk *walk, const char *refname);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Hide the OID pointed to by a reference
Packit Service 20376f
 *
Packit Service 20376f
 * The reference must point to a committish.
Packit Service 20376f
 *
Packit Service 20376f
 * @param walk the walker being used for the traversal
Packit Service 20376f
 * @param refname the reference to hide
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_revwalk_hide_ref(git_revwalk *walk, const char *refname);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the next commit from the revision walk.
Packit Service 20376f
 *
Packit Service 20376f
 * The initial call to this method is *not* blocking when
Packit Service 20376f
 * iterating through a repo with a time-sorting mode.
Packit Service 20376f
 *
Packit Service 20376f
 * Iterating with Topological or inverted modes makes the initial
Packit Service 20376f
 * call blocking to preprocess the commit list, but this block should be
Packit Service 20376f
 * mostly unnoticeable on most repositories (topological preprocessing
Packit Service 20376f
 * times at 0.3s on the git.git repo).
Packit Service 20376f
 *
Packit Service 20376f
 * The revision walker is reset when the walk is over.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Pointer where to store the oid of the next commit
Packit Service 20376f
 * @param walk the walker to pop the commit from.
Packit Service 20376f
 * @return 0 if the next commit was found;
Packit Service 20376f
 *	GIT_ITEROVER if there are no commits left to iterate
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_revwalk_next(git_oid *out, git_revwalk *walk);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Change the sorting mode when iterating through the
Packit Service 20376f
 * repository's contents.
Packit Service 20376f
 *
Packit Service 20376f
 * Changing the sorting mode resets the walker.
Packit Service 20376f
 *
Packit Service 20376f
 * @param walk the walker being used for the traversal.
Packit Service 20376f
 * @param sort_mode combination of GIT_SORT_XXX flags
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Push and hide the respective endpoints of the given range.
Packit Service 20376f
 *
Packit Service 20376f
 * The range should be of the form
Packit Service 20376f
 *   <commit>..<commit>
Packit Service 20376f
 * where each <commit> is in the form accepted by 'git_revparse_single'.
Packit Service 20376f
 * The left-hand commit will be hidden and the right-hand commit pushed.
Packit Service 20376f
 *
Packit Service 20376f
 * @param walk the walker being used for the traversal
Packit Service 20376f
 * @param range the range
Packit Service 20376f
 * @return 0 or an error code
Packit Service 20376f
 *
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_revwalk_push_range(git_revwalk *walk, const char *range);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Simplify the history by first-parent
Packit Service 20376f
 *
Packit Service 20376f
 * No parents other than the first for each commit will be enqueued.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_revwalk_simplify_first_parent(git_revwalk *walk);
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Free a revision walker previously allocated.
Packit Service 20376f
 *
Packit Service 20376f
 * @param walk traversal handle to close. If NULL nothing occurs.
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Return the repository on which this walker
Packit Service 20376f
 * is operating.
Packit Service 20376f
 *
Packit Service 20376f
 * @param walk the revision walker
Packit Service 20376f
 * @return the repository being walked
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(git_repository *) git_revwalk_repository(git_revwalk *walk);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * This is a callback function that user can provide to hide a
Packit Service 20376f
 * commit and its parents. If the callback function returns non-zero value,
Packit Service 20376f
 * then this commit and its parents will be hidden.
Packit Service 20376f
 *
Packit Service 20376f
 * @param commit_id oid of Commit
Packit Service 20376f
 * @param payload User-specified pointer to data to be passed as data payload
Packit Service 20376f
 */
Packit Service 20376f
typedef int(*git_revwalk_hide_cb)(
Packit Service 20376f
	const git_oid *commit_id,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Adds a callback function to hide a commit and its parents
Packit Service 20376f
 *
Packit Service 20376f
 * @param walk the revision walker
Packit Service 20376f
 * @param hide_cb  callback function to hide a commit and its parents
Packit Service 20376f
 * @param payload  data payload to be passed to callback function
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_revwalk_add_hide_cb(
Packit Service 20376f
	git_revwalk *walk,
Packit Service 20376f
	git_revwalk_hide_cb hide_cb,
Packit Service 20376f
	void *payload);
Packit Service 20376f
Packit Service 20376f
/** @} */
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
#endif