Skip to main content

Module git_path

Module git_path 

Source
Expand description

Git-compatible path normalization and helpers for test-tool path-utils. Logic matches git/path.c (normalize_path_copy, longest_ancestor_length, relative_path, strip_path_suffix) and git/remote.c (relative_url).

Enums§

GitPathError
Errors returned by Git-compatible path helper routines.

Functions§

abspath_part_inside_repo
Git setup.c abspath_part_inside_repo (POSIX).
cleanup_path
Git’s cleanup_path from path.c: strip a single leading ./ and any directory separators immediately following it. Internal consecutive slashes (e.g. info//sparse-checkout) are deliberately preserved so the result matches git rev-parse --git-path byte-for-byte.
git_path_relative_component
The relative portion of a --git-path argument, mirroring how Git builds the buffer in repo_git_pathv: the caller-supplied fmt string is appended to <git_dir>/ verbatim and only cleanup_path runs over the whole buffer. In practice that means a single leading / (and a leading ./) is dropped from the user-supplied component while internal // runs are kept intact.
is_absolute_path_unix
Whether path is an absolute Unix-style path.
longest_ancestor_length
Git’s longest_ancestor_length - normalizes path and each colon-separated prefix.
normalize_path_copy
Purely textual path normalization matching Git’s normalize_path_copy. Returns GitPathError::EscapesRoot when .. would escape above the root (Git returns -1).
path_for_disk_compare
Canonicalize a path for on-disk comparison (macOS /private aliasing).
prefix_path_gently
Git setup.c prefix_path_gently (POSIX).
real_path_resolving
Like Git’s strbuf_realpath / test-tool path-utils real_path: resolve symlinks by walking path components (so symlink targets are interpreted at each step), then if the leaf is missing, resolve the longest existing prefix and append the remainder.
relative_path
Git’s relative_path from path.c (POSIX subset).
relative_url
Git’s relative_url from remote.c (POSIX; no DOS drive handling).
strip_path_suffix
Git’s stripped_path_suffix_offset / strip_path_suffix.