ftwin 0.8.10
|
Implementation of the hierarchical .gitignore-style pattern matching logic. More...
#include "ft_ignore.h"
#include "debug.h"
#include <apr_file_io.h>
#include <apr_strings.h>
#include <string.h>
#include <ctype.h>
Go to the source code of this file.
Functions | |
static char * | ft_glob_to_pcre (const char *pattern, apr_pool_t *pool, unsigned int *flags) |
Convert Git glob pattern to PCRE regex Handles: *, **, ?, [abc], !, /, escapes. | |
ft_ignore_context_t * | ft_ignore_context_create (apr_pool_t *pool, ft_ignore_context_t *parent, const char *base_dir) |
Creates a new ignore context. | |
apr_status_t | ft_ignore_add_pattern_str (ft_ignore_context_t *ctx, const char *pattern_str) |
Adds a single pattern string to a context. | |
apr_status_t | ft_ignore_load_file (ft_ignore_context_t *ctx, const char *filepath) |
Loads and parses an ignore file (like .gitignore) into a context. | |
ft_ignore_match_result_t | ft_ignore_match (ft_ignore_context_t *ctx, const char *fullpath, int is_dir) |
Checks if a given path should be ignored based on the hierarchical context. | |
Variables | |
static const size_t | MAX_PATTERN_LEN = 4096 |
The maximum length of a pattern string. | |
Implementation of the hierarchical .gitignore-style pattern matching logic.
Definition in file ft_ignore.c.
apr_status_t ft_ignore_add_pattern_str | ( | ft_ignore_context_t * | ctx, |
const char * | pattern_str | ||
) |
Adds a single pattern string to a context.
The pattern is parsed, compiled into a regex, and added to the context's list.
[in] | ctx | The context to add the pattern to. |
[in] | pattern_str | The raw pattern string to add. |
Definition at line 197 of file ft_ignore.c.
References DEBUG_ERR, ft_ignore_pattern_t::flags, ft_glob_to_pcre(), ft_ignore_pattern_t::pattern_str, ft_ignore_context_t::patterns, ft_ignore_context_t::pool, and ft_ignore_pattern_t::regex.
Referenced by ft_ignore_load_file().
ft_ignore_context_t * ft_ignore_context_create | ( | apr_pool_t * | pool, |
ft_ignore_context_t * | parent, | ||
const char * | base_dir | ||
) |
Creates a new ignore context.
[in] | pool | The APR pool to allocate the new context from. |
[in] | parent | The parent context, or NULL to create a root context. |
[in] | base_dir | The absolute path to the directory this context represents. |
Definition at line 184 of file ft_ignore.c.
References ft_ignore_context_t::base_dir, ft_ignore_context_t::base_dir_len, ft_ignore_context_t::parent, ft_ignore_context_t::patterns, and ft_ignore_context_t::pool.
apr_status_t ft_ignore_load_file | ( | ft_ignore_context_t * | ctx, |
const char * | filepath | ||
) |
Loads and parses an ignore file (like .gitignore) into a context.
[in] | ctx | The context to load the patterns into. |
[in] | filepath | The path to the ignore file. |
Definition at line 239 of file ft_ignore.c.
References ft_ignore_add_pattern_str(), MAX_PATTERN_LEN, and ft_ignore_context_t::pool.
ft_ignore_match_result_t ft_ignore_match | ( | ft_ignore_context_t * | ctx, |
const char * | fullpath, | ||
int | is_dir | ||
) |
Checks if a given path should be ignored based on the hierarchical context.
It traverses the context hierarchy from the current context up to the root, applying rules from each level. The last matching pattern determines the outcome.
[in] | ctx | The starting context for matching (usually the one for the file's direct parent). |
[in] | fullpath | The absolute path of the file or directory to check. |
[in] | is_dir | A flag indicating if the path is a directory. |
Definition at line 268 of file ft_ignore.c.
References ft_ignore_context_t::base_dir, ft_ignore_context_t::base_dir_len, ft_ignore_pattern_t::flags, FT_IGNORE_MATCH_IGNORED, FT_IGNORE_MATCH_NONE, FT_IGNORE_MATCH_WHITELISTED, ft_ignore_context_t::parent, ft_ignore_context_t::patterns, and ft_ignore_pattern_t::regex.
|
static |
The maximum length of a pattern string.
This constant defines the maximum buffer size for reading and processing a single pattern from a .gitignore file.
Definition at line 35 of file ft_ignore.c.
Referenced by ft_glob_to_pcre(), and ft_ignore_load_file().