Skip to main content

Module worktree

Module worktree 

Source
Expand description

Worktree → tree-object builder.

Walks a directory, applies .mkitignore, hashes each file as a Blob, recurses on subdirectories, validates symlink targets against path-traversal, and writes a single root Tree into the supplied ObjectStore.

Notes:

  • Files at or below CHUNK_THRESHOLD are stored as a single Blob. Files above the threshold are chunked with crate::chunker::FastCdc::v1; each chunk is stored as a Blob and the file is represented by a ChunkedBlob manifest whose hash is what lands in the parent tree.
  • We never follow symlinks while walking. Linux/macOS read_link reports the target verbatim and we hash it as a blob.

Enums§

WorktreeError
Errors returned by this module.

Constants§

CHUNK_THRESHOLD
Files larger than this go through the chunker (1 MiB).
MAX_FILE_BYTES
Hard cap on a single file (1 GiB).

Functions§

build_tree
Build a tree object for dir and its subdirectories. Honours the .gitignore + .mkitignore ignore files loaded from dir.
build_tree_filtered
Like build_tree, but the caller supplies the authoritative tracked set (index). Callers that seed their index from HEAD when no index file exists yet (status, restore safety) MUST pass it here so a tracked file that matches an ignore rule is not dropped right after a checkout. None falls back to the on-disk <dir>/.mkit/index (empty if absent).
build_tree_from_index
Build a tree object from an Index (the staging area).
hash_file
Read a file from disk, hash it, store it, and return the content-address of the resulting object.
read_blob
Reassemble the full byte content of a Blob or ChunkedBlob object addressed by hash.
read_regular_file_bounded
Read a regular file without following the final path component on Unix, enforcing MAX_FILE_BYTES against both the opened handle’s metadata and the actual bytes read.
store_file_object
Store a regular file’s bytes as the canonical object and return its content-address.
validate_symlink_target
Validate a symlink target: must be relative and contain no .. segments.

Type Aliases§

WorktreeResult
Result alias used throughout this module.