Skip to main content

Module pathspec

Module pathspec 

Source
Expand description

Git-compatible pathspec matching (magic tokens and global flags).

Global flags are read from the same environment variables as Git: GIT_LITERAL_PATHSPECS, GIT_GLOB_PATHSPECS, GIT_NOGLOB_PATHSPECS, GIT_ICASE_PATHSPECS. The grit binary sets these from CLI flags such as --literal-pathspecs before dispatching subcommands.

Structs§

PathspecMatchContext
Optional path metadata for literal pathspecs with a trailing / (tree-walk / diff-tree).

Functions§

bloom_lookup_prefix
bloom_lookup_prefix_with_cwd
Path prefix used for Bloom-filter lookups (revision.c convert_pathspec_to_bloom_keyvec).
context_from_mode_bits
Classify a raw Git mode (e.g. from an index or tree entry) for pathspec matching.
context_from_mode_octal
Parse a Git mode string (e.g. 100644, 040000) into a PathspecMatchContext.
extend_pathspec_list_implicit_cwd
When every pathspec is an exclude and none use :(top) / :/, Git prepends an implicit positive that matches only under the process cwd (relative to the work tree), not the whole repository (PATHSPEC_PREFER_CWD in pathspec.c). cwd_from_repo_root is that prefix without a trailing slash, or empty at the work tree root.
has_glob_chars
Whether the pattern uses wildcards after Git pathspec escaping rules.
literal_pathspecs_enabled
Whether GIT_LITERAL_PATHSPECS is enabled (shell * and ? are literal, not globs).
matches_ls_tree_pathspec
Pathspec matching for ls-tree after Git forces pathspec.has_wildcard = 0 (ls-tree.c).
matches_pathspec
Returns whether path matches the pathspec spec with default (file) context.
matches_pathspec_for_object
Match a pathspec against a tree path, using .gitattributes for :(attr:...).
matches_pathspec_list
Git match_pathspec semantics over a pathspec list: OR of positive specs minus OR of exclude specs. If every element is exclude-only, Git implicitly prepends . (match all); this function does the same.
matches_pathspec_list_for_object
matches_pathspec_list for tree/index objects with mode and .gitattributes rules.
matches_pathspec_list_with_context
Like matches_pathspec_list, but uses ctx for non-magic pathspec elements (trailing /).
matches_pathspec_set_for_object
True if path matches the combined pathspec list: any positive spec (or all paths when there are only excludes, matching Git parse_pathspec), and not matched by any exclude spec.
matches_pathspec_set_for_object_ls_tree
Like matches_pathspec_set_for_object, but uses matches_ls_tree_pathspec for each element so ls-files / index filtering agrees with ls-tree on patterns such as a[a].
matches_pathspec_with_context
Like matches_pathspec, but uses ctx for trailing-/ literal pathspecs and for wildcard pathspecs where the pattern continues after a directory boundary (Git matches_pathspec + directory semantics).
parse_pathspecs_from_source
Read pathspec entries from raw file bytes (stdin or file), matching Git’s --pathspec-from-file / --pathspec-file-nul rules.
path_allowed_by_pathspec_list
Whether path is included when Git applies a pathspec list with optional :(exclude) entries.
pathspec_contributes_match
True when spec matches path for pathspec bookkeeping (positive match or exclude hit).
pathspec_exclude_matches
True if path is matched by an exclude pathspec’s pattern. Returns false if spec is not an exclude pathspec.
pathspec_has_top
True if spec uses :(top) or short :/ (repo-root-relative) magic.
pathspec_is_exclude
Returns whether spec uses Git’s exclude magic (:(exclude), :!, :^, etc.).
pathspec_matches
True if path is matched by spec (Git pathspec syntax, including magic and globals).
pathspec_wants_descent_into_tree
Whether tree-walking should recurse into directory full_name for pathspec spec without -r (Git read_tree / show_recursive “interesting” descent).
pathspecs_allow_bloom
Whether every pathspec can participate in Bloom precomputation (Git forbid_bloom_filters).
simple_length
Returns the length of the leading literal segment before the first glob metacharacter, matching Git’s simple_length() (* ? [ \) on bytes.
validate_global_pathspec_flags
Validates global pathspec environment flags the same way Git does.
wildmatch_flags_icase_glob
Returns wildmatch flags for :(icase) / :(glob)-style patterns when those appear as explicit magic (not used by default CLI pathspecs).