Blame include/git2/pathspec.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_pathspec_h__
Packit Service 20376f
#define INCLUDE_git_pathspec_h__
Packit Service 20376f
Packit Service 20376f
#include "common.h"
Packit Service 20376f
#include "types.h"
Packit Service 20376f
#include "strarray.h"
Packit Service 20376f
#include "diff.h"
Packit Service 20376f
Packit Service 20376f
GIT_BEGIN_DECL
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Compiled pathspec
Packit Service 20376f
 */
Packit Service 20376f
typedef struct git_pathspec git_pathspec;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * List of filenames matching a pathspec
Packit Service 20376f
 */
Packit Service 20376f
typedef struct git_pathspec_match_list git_pathspec_match_list;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Options controlling how pathspec match should be executed
Packit Service 20376f
 *
Packit Service 20376f
 * - GIT_PATHSPEC_IGNORE_CASE forces match to ignore case; otherwise
Packit Service 20376f
 *   match will use native case sensitivity of platform filesystem
Packit Service 20376f
 * - GIT_PATHSPEC_USE_CASE forces case sensitive match; otherwise
Packit Service 20376f
 *   match will use native case sensitivity of platform filesystem
Packit Service 20376f
 * - GIT_PATHSPEC_NO_GLOB disables glob patterns and just uses simple
Packit Service 20376f
 *   string comparison for matching
Packit Service 20376f
 * - GIT_PATHSPEC_NO_MATCH_ERROR means the match functions return error
Packit Service 20376f
 *   code GIT_ENOTFOUND if no matches are found; otherwise no matches is
Packit Service 20376f
 *   still success (return 0) but `git_pathspec_match_list_entrycount`
Packit Service 20376f
 *   will indicate 0 matches.
Packit Service 20376f
 * - GIT_PATHSPEC_FIND_FAILURES means that the `git_pathspec_match_list`
Packit Service 20376f
 *   should track which patterns matched which files so that at the end of
Packit Service 20376f
 *   the match we can identify patterns that did not match any files.
Packit Service 20376f
 * - GIT_PATHSPEC_FAILURES_ONLY means that the `git_pathspec_match_list`
Packit Service 20376f
 *   does not need to keep the actual matching filenames.  Use this to
Packit Service 20376f
 *   just test if there were any matches at all or in combination with
Packit Service 20376f
 *   GIT_PATHSPEC_FIND_FAILURES to validate a pathspec.
Packit Service 20376f
 */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	GIT_PATHSPEC_DEFAULT        = 0,
Packit Service 20376f
	GIT_PATHSPEC_IGNORE_CASE    = (1u << 0),
Packit Service 20376f
	GIT_PATHSPEC_USE_CASE       = (1u << 1),
Packit Service 20376f
	GIT_PATHSPEC_NO_GLOB        = (1u << 2),
Packit Service 20376f
	GIT_PATHSPEC_NO_MATCH_ERROR = (1u << 3),
Packit Service 20376f
	GIT_PATHSPEC_FIND_FAILURES  = (1u << 4),
Packit Service 20376f
	GIT_PATHSPEC_FAILURES_ONLY  = (1u << 5),
Packit Service 20376f
} git_pathspec_flag_t;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Compile a pathspec
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Output of the compiled pathspec
Packit Service 20376f
 * @param pathspec A git_strarray of the paths to match
Packit Service 20376f
 * @return 0 on success, <0 on failure
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_pathspec_new(
Packit Service 20376f
	git_pathspec **out, const git_strarray *pathspec);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Free a pathspec
Packit Service 20376f
 *
Packit Service 20376f
 * @param ps The compiled pathspec
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_pathspec_free(git_pathspec *ps);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Try to match a path against a pathspec
Packit Service 20376f
 *
Packit Service 20376f
 * Unlike most of the other pathspec matching functions, this will not
Packit Service 20376f
 * fall back on the native case-sensitivity for your platform.  You must
Packit Service 20376f
 * explicitly pass flags to control case sensitivity or else this will
Packit Service 20376f
 * fall back on being case sensitive.
Packit Service 20376f
 *
Packit Service 20376f
 * @param ps The compiled pathspec
Packit Service 20376f
 * @param flags Combination of git_pathspec_flag_t options to control match
Packit Service 20376f
 * @param path The pathname to attempt to match
Packit Service 20376f
 * @return 1 is path matches spec, 0 if it does not
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_pathspec_matches_path(
Packit Service 20376f
	const git_pathspec *ps, uint32_t flags, const char *path);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Match a pathspec against the working directory of a repository.
Packit Service 20376f
 *
Packit Service 20376f
 * This matches the pathspec against the current files in the working
Packit Service 20376f
 * directory of the repository.  It is an error to invoke this on a bare
Packit Service 20376f
 * repo.  This handles git ignores (i.e. ignored files will not be
Packit Service 20376f
 * considered to match the `pathspec` unless the file is tracked in the
Packit Service 20376f
 * index).
Packit Service 20376f
 *
Packit Service 20376f
 * If `out` is not NULL, this returns a `git_patchspec_match_list`.  That
Packit Service 20376f
 * contains the list of all matched filenames (unless you pass the
Packit Service 20376f
 * `GIT_PATHSPEC_FAILURES_ONLY` flag) and may also contain the list of
Packit Service 20376f
 * pathspecs with no match (if you used the `GIT_PATHSPEC_FIND_FAILURES`
Packit Service 20376f
 * flag).  You must call `git_pathspec_match_list_free()` on this object.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Output list of matches; pass NULL to just get return value
Packit Service 20376f
 * @param repo The repository in which to match; bare repo is an error
Packit Service 20376f
 * @param flags Combination of git_pathspec_flag_t options to control match
Packit Service 20376f
 * @param ps Pathspec to be matched
Packit Service 20376f
 * @return 0 on success, -1 on error, GIT_ENOTFOUND if no matches and
Packit Service 20376f
 *         the GIT_PATHSPEC_NO_MATCH_ERROR flag was given
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_pathspec_match_workdir(
Packit Service 20376f
	git_pathspec_match_list **out,
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	uint32_t flags,
Packit Service 20376f
	git_pathspec *ps);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Match a pathspec against entries in an index.
Packit Service 20376f
 *
Packit Service 20376f
 * This matches the pathspec against the files in the repository index.
Packit Service 20376f
 *
Packit Service 20376f
 * NOTE: At the moment, the case sensitivity of this match is controlled
Packit Service 20376f
 * by the current case-sensitivity of the index object itself and the
Packit Service 20376f
 * USE_CASE and IGNORE_CASE flags will have no effect.  This behavior will
Packit Service 20376f
 * be corrected in a future release.
Packit Service 20376f
 *
Packit Service 20376f
 * If `out` is not NULL, this returns a `git_patchspec_match_list`.  That
Packit Service 20376f
 * contains the list of all matched filenames (unless you pass the
Packit Service 20376f
 * `GIT_PATHSPEC_FAILURES_ONLY` flag) and may also contain the list of
Packit Service 20376f
 * pathspecs with no match (if you used the `GIT_PATHSPEC_FIND_FAILURES`
Packit Service 20376f
 * flag).  You must call `git_pathspec_match_list_free()` on this object.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Output list of matches; pass NULL to just get return value
Packit Service 20376f
 * @param index The index to match against
Packit Service 20376f
 * @param flags Combination of git_pathspec_flag_t options to control match
Packit Service 20376f
 * @param ps Pathspec to be matched
Packit Service 20376f
 * @return 0 on success, -1 on error, GIT_ENOTFOUND if no matches and
Packit Service 20376f
 *         the GIT_PATHSPEC_NO_MATCH_ERROR flag is used
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_pathspec_match_index(
Packit Service 20376f
	git_pathspec_match_list **out,
Packit Service 20376f
	git_index *index,
Packit Service 20376f
	uint32_t flags,
Packit Service 20376f
	git_pathspec *ps);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Match a pathspec against files in a tree.
Packit Service 20376f
 *
Packit Service 20376f
 * This matches the pathspec against the files in the given tree.
Packit Service 20376f
 *
Packit Service 20376f
 * If `out` is not NULL, this returns a `git_patchspec_match_list`.  That
Packit Service 20376f
 * contains the list of all matched filenames (unless you pass the
Packit Service 20376f
 * `GIT_PATHSPEC_FAILURES_ONLY` flag) and may also contain the list of
Packit Service 20376f
 * pathspecs with no match (if you used the `GIT_PATHSPEC_FIND_FAILURES`
Packit Service 20376f
 * flag).  You must call `git_pathspec_match_list_free()` on this object.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Output list of matches; pass NULL to just get return value
Packit Service 20376f
 * @param tree The root-level tree to match against
Packit Service 20376f
 * @param flags Combination of git_pathspec_flag_t options to control match
Packit Service 20376f
 * @param ps Pathspec to be matched
Packit Service 20376f
 * @return 0 on success, -1 on error, GIT_ENOTFOUND if no matches and
Packit Service 20376f
 *         the GIT_PATHSPEC_NO_MATCH_ERROR flag is used
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_pathspec_match_tree(
Packit Service 20376f
	git_pathspec_match_list **out,
Packit Service 20376f
	git_tree *tree,
Packit Service 20376f
	uint32_t flags,
Packit Service 20376f
	git_pathspec *ps);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Match a pathspec against files in a diff list.
Packit Service 20376f
 *
Packit Service 20376f
 * This matches the pathspec against the files in the given diff list.
Packit Service 20376f
 *
Packit Service 20376f
 * If `out` is not NULL, this returns a `git_patchspec_match_list`.  That
Packit Service 20376f
 * contains the list of all matched filenames (unless you pass the
Packit Service 20376f
 * `GIT_PATHSPEC_FAILURES_ONLY` flag) and may also contain the list of
Packit Service 20376f
 * pathspecs with no match (if you used the `GIT_PATHSPEC_FIND_FAILURES`
Packit Service 20376f
 * flag).  You must call `git_pathspec_match_list_free()` on this object.
Packit Service 20376f
 *
Packit Service 20376f
 * @param out Output list of matches; pass NULL to just get return value
Packit Service 20376f
 * @param diff A generated diff list
Packit Service 20376f
 * @param flags Combination of git_pathspec_flag_t options to control match
Packit Service 20376f
 * @param ps Pathspec to be matched
Packit Service 20376f
 * @return 0 on success, -1 on error, GIT_ENOTFOUND if no matches and
Packit Service 20376f
 *         the GIT_PATHSPEC_NO_MATCH_ERROR flag is used
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(int) git_pathspec_match_diff(
Packit Service 20376f
	git_pathspec_match_list **out,
Packit Service 20376f
	git_diff *diff,
Packit Service 20376f
	uint32_t flags,
Packit Service 20376f
	git_pathspec *ps);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Free memory associates with a git_pathspec_match_list
Packit Service 20376f
 *
Packit Service 20376f
 * @param m The git_pathspec_match_list to be freed
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(void) git_pathspec_match_list_free(git_pathspec_match_list *m);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the number of items in a match list.
Packit Service 20376f
 *
Packit Service 20376f
 * @param m The git_pathspec_match_list object
Packit Service 20376f
 * @return Number of items in match list
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(size_t) git_pathspec_match_list_entrycount(
Packit Service 20376f
	const git_pathspec_match_list *m);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get a matching filename by position.
Packit Service 20376f
 *
Packit Service 20376f
 * This routine cannot be used if the match list was generated by
Packit Service 20376f
 * `git_pathspec_match_diff`.  If so, it will always return NULL.
Packit Service 20376f
 *
Packit Service 20376f
 * @param m The git_pathspec_match_list object
Packit Service 20376f
 * @param pos The index into the list
Packit Service 20376f
 * @return The filename of the match
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const char *) git_pathspec_match_list_entry(
Packit Service 20376f
	const git_pathspec_match_list *m, size_t pos);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get a matching diff delta by position.
Packit Service 20376f
 *
Packit Service 20376f
 * This routine can only be used if the match list was generated by
Packit Service 20376f
 * `git_pathspec_match_diff`.  Otherwise it will always return NULL.
Packit Service 20376f
 *
Packit Service 20376f
 * @param m The git_pathspec_match_list object
Packit Service 20376f
 * @param pos The index into the list
Packit Service 20376f
 * @return The filename of the match
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const git_diff_delta *) git_pathspec_match_list_diff_entry(
Packit Service 20376f
	const git_pathspec_match_list *m, size_t pos);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get the number of pathspec items that did not match.
Packit Service 20376f
 *
Packit Service 20376f
 * This will be zero unless you passed GIT_PATHSPEC_FIND_FAILURES when
Packit Service 20376f
 * generating the git_pathspec_match_list.
Packit Service 20376f
 *
Packit Service 20376f
 * @param m The git_pathspec_match_list object
Packit Service 20376f
 * @return Number of items in original pathspec that had no matches
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(size_t) git_pathspec_match_list_failed_entrycount(
Packit Service 20376f
	const git_pathspec_match_list *m);
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * Get an original pathspec string that had no matches.
Packit Service 20376f
 *
Packit Service 20376f
 * This will be return NULL for positions out of range.
Packit Service 20376f
 *
Packit Service 20376f
 * @param m The git_pathspec_match_list object
Packit Service 20376f
 * @param pos The index into the failed items
Packit Service 20376f
 * @return The pathspec pattern that didn't match anything
Packit Service 20376f
 */
Packit Service 20376f
GIT_EXTERN(const char *) git_pathspec_match_list_failed_entry(
Packit Service 20376f
	const git_pathspec_match_list *m, size_t pos);
Packit Service 20376f
Packit Service 20376f
GIT_END_DECL
Packit Service 20376f
#endif