pathspec.h 1.91 KB
Newer Older
1
/*
Edward Thomson committed
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
3 4 5 6 7 8 9 10
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
#ifndef INCLUDE_pathspec_h__
#define INCLUDE_pathspec_h__

#include "common.h"
11 12

#include "git2/pathspec.h"
13 14 15
#include "buffer.h"
#include "vector.h"
#include "pool.h"
16 17 18 19 20 21 22 23 24 25
#include "array.h"

/* public compiled pathspec */
struct git_pathspec {
	git_refcount rc;
	char *prefix;
	git_vector pathspec;
	git_pool pool;
};

26 27 28 29 30 31 32
enum {
	PATHSPEC_DATATYPE_STRINGS = 0,
	PATHSPEC_DATATYPE_DIFF = 1,
};

typedef git_array_t(char *) git_pathspec_string_array_t;

33 34 35
/* public interface to pathspec matching */
struct git_pathspec_match_list {
	git_pathspec *pathspec;
36 37
	git_array_t(void *) matches;
	git_pathspec_string_array_t failures;
38
	git_pool pool;
39
	int datatype;
40
};
41 42 43 44 45

/* what is the common non-wildcard prefix for all items in the pathspec */
extern char *git_pathspec_prefix(const git_strarray *pathspec);

/* is there anything in the spec that needs to be filtered on */
46
extern bool git_pathspec_is_empty(const git_strarray *pathspec);
47 48

/* build a vector of fnmatch patterns to evaluate efficiently */
49
extern int git_pathspec__vinit(
50 51 52
	git_vector *vspec, const git_strarray *strspec, git_pool *strpool);

/* free data from the pathspec vector */
53 54 55
extern void git_pathspec__vfree(git_vector *vspec);

#define GIT_PATHSPEC_NOMATCH ((size_t)-1)
56

57 58 59 60 61
/*
 * Match a path against the vectorized pathspec.
 * The matched pathspec is passed back into the `matched_pathspec` parameter,
 * unless it is passed as NULL by the caller.
 */
62 63
extern bool git_pathspec__match(
	const git_vector *vspec,
64 65 66
	const char *path,
	bool disable_fnmatch,
	bool casefold,
67 68
	const char **matched_pathspec,
	size_t *matched_at);
69

70 71
/* easy pathspec setup */

72
extern int git_pathspec__init(git_pathspec *ps, const git_strarray *paths);
73

74
extern void git_pathspec__clear(git_pathspec *ps);
75

76
#endif