ftwin 0.8.10
ft_ignore.h File Reference

Interface for handling hierarchical ignore patterns, similar to .gitignore. More...

#include <apr_pools.h>
#include <apr_tables.h>
#include <pcre.h>
Include dependency graph for ft_ignore.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ft_ignore_pattern_t
 Represents a single compiled ignore pattern. More...
 
struct  ft_ignore_context_t
 Represents the ignore rules for a specific directory and its descendants. More...
 

Typedefs

typedef struct ft_ignore_context_t ft_ignore_context_t
 Represents the ignore rules for a specific directory and its descendants.
 

Enumerations

enum  ft_ignore_match_result_t { FT_IGNORE_MATCH_NONE , FT_IGNORE_MATCH_IGNORED , FT_IGNORE_MATCH_WHITELISTED }
 Result codes for an ignore match operation. More...
 

Functions

ft_ignore_context_tft_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_load_file (ft_ignore_context_t *ctx, const char *filepath)
 Loads and parses an ignore file (like .gitignore) into a 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.
 
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.
 

Detailed Description

Interface for handling hierarchical ignore patterns, similar to .gitignore.

Definition in file ft_ignore.h.

Typedef Documentation

◆ ft_ignore_context_t

Represents the ignore rules for a specific directory and its descendants.

An ignore context is tied to a base directory and contains patterns loaded from a .gitignore file within that directory. Contexts are linked to their parent's context, forming a hierarchy that mirrors the filesystem.

Enumeration Type Documentation

◆ ft_ignore_match_result_t

Result codes for an ignore match operation.

Enumerator
FT_IGNORE_MATCH_NONE 

The path is not matched by any pattern.

FT_IGNORE_MATCH_IGNORED 

The path is matched by an ignore pattern.

FT_IGNORE_MATCH_WHITELISTED 

The path is matched by a negation (whitelist) pattern.

Definition at line 62 of file ft_ignore.h.

Function Documentation

◆ ft_ignore_add_pattern_str()

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.

Parameters
[in]ctxThe context to add the pattern to.
[in]pattern_strThe raw pattern string to add.
Returns
APR_SUCCESS on success, or an error code on failure.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_ignore_context_create()

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.

Parameters
[in]poolThe APR pool to allocate the new context from.
[in]parentThe parent context, or NULL to create a root context.
[in]base_dirThe absolute path to the directory this context represents.
Returns
A pointer to the newly created context.

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.

◆ ft_ignore_load_file()

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.

Parameters
[in]ctxThe context to load the patterns into.
[in]filepathThe path to the ignore file.
Returns
APR_SUCCESS on success, or an error code on failure.

Definition at line 239 of file ft_ignore.c.

References ft_ignore_add_pattern_str(), MAX_PATTERN_LEN, and ft_ignore_context_t::pool.

Here is the call graph for this function:

◆ ft_ignore_match()

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.

Parameters
[in]ctxThe starting context for matching (usually the one for the file's direct parent).
[in]fullpathThe absolute path of the file or directory to check.
[in]is_dirA flag indicating if the path is a directory.
Returns
The match result (ignored, whitelisted, or no match).

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.