ignore.h 1.95 KB
Newer Older
1
/*
Edward Thomson committed
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
3 4 5 6 7 8 9
 *
 * 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_ignore_h__
#define INCLUDE_ignore_h__

10 11
#include "common.h"

12 13
#include "repository.h"
#include "vector.h"
14 15 16
#include "attr_file.h"

#define GIT_IGNORE_FILE			".gitignore"
17
#define GIT_IGNORE_FILE_INREPO	"exclude"
18
#define GIT_IGNORE_FILE_XDG		"ignore"
19

20 21 22 23 24 25 26
/* The git_ignores structure maintains three sets of ignores:
 * - internal ignores
 * - per directory ignores
 * - global ignores (at lower priority than the others)
 * As you traverse from one directory to another, you can push and pop
 * directories onto git_ignores list efficiently.
 */
27 28
typedef struct {
	git_repository *repo;
29
	git_str dir; /* current directory reflected in ign_path */
30 31 32
	git_attr_file *ign_internal;
	git_vector ign_path;
	git_vector ign_global;
33
	size_t dir_root; /* offset in dir to repo root */
34
	int ignore_case;
35
	int depth;
36 37
} git_ignores;

38 39
extern int git_ignore__for_path(
	git_repository *repo, const char *path, git_ignores *ign);
40 41

extern int git_ignore__push_dir(git_ignores *ign, const char *dir);
42

43 44 45
extern int git_ignore__pop_dir(git_ignores *ign);

extern void git_ignore__free(git_ignores *ign);
46

47 48 49 50
enum {
	GIT_IGNORE_UNCHECKED = -2,
	GIT_IGNORE_NOTFOUND = -1,
	GIT_IGNORE_FALSE = 0,
51
	GIT_IGNORE_TRUE = 1
52 53
};

54
extern int git_ignore__lookup(int *out, git_ignores *ign, const char *path, git_dir_flag dir_flag);
55

56 57 58 59 60 61 62 63 64
/* command line Git sometimes generates an error message if given a
 * pathspec that contains an exact match to an ignored file (provided
 * --force isn't also given).  This makes it easy to check it that has
 * happened.  Returns GIT_EINVALIDSPEC if the pathspec contains ignored
 * exact matches (that are not already present in the index).
 */
extern int git_ignore__check_pathspec_for_exact_ignores(
	git_repository *repo, git_vector *pathspec, bool no_fnmatch);

65
#endif