Blame include/git2/revwalk.h

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