Partial-clone filters

libvcs.cmd.git_filter validates Git object filters before a command creates a checkout or starts a process. The frozen models cover Git’s current filter grammar:

Model

Git specification

Meaning

BlobNone

blob:none

Omit blobs until Git needs them

BlobLimit

blob:limit=n[KMG]

Omit blobs at or above the byte limit

TreeDepth

tree:n

Omit trees and blobs at depth n or deeper

ObjectType

object:type=TYPE

Include one of blob, tree, commit, or tag

SparseOid

sparse:oid=OID

Read sparse patterns from an object

Auto

auto

Ask Git to choose a server-recommended filter

Combine

combine:FILTER+FILTER

Apply every encoded child filter

Build a model directly, parse a Git specification, or coerce a kind-tagged mapping:

>>> from libvcs.cmd.git_filter import BlobLimit, coerce_filter, parse_filter
>>> BlobLimit("4m")
BlobLimit(limit='4m')
>>> str(BlobLimit("4m")), BlobLimit("4m").kind
('blob:limit=4m', 'blob:limit')
>>> parse_filter("tree:2")
TreeDepth(depth=2)
>>> coerce_filter({"kind": "object:type", "type": "commit"})
ObjectType(type='commit')

coerce_filter() turns a nonempty sequence into a Combine. Clone and fetch preserve a top-level sequence as repeated flags. Submodule update emits one equivalent combine: specification because Git otherwise keeps only the last repeated filter.

>>> from libvcs.cmd.git_filter import (
...     BlobNone,
...     TreeDepth,
...     coerce_filter,
...     filter_specs,
... )
>>> coerce_filter([BlobNone(), TreeDepth(1)])
Combine(filters=(BlobNone(), TreeDepth(depth=1)))
>>> filter_specs([BlobNone(), TreeDepth(1)])
('blob:none', 'tree:1')

Pass the same accepted values to _filter on clone(), fetch(), or update(). Existing string values remain valid. Native git pull has no filter option, so pull() rejects every nonempty filter. Call fetch() with the filter before an unfiltered pull.

Validation limits

Explicit integer values range from zero through 18446744073709551615. Textual values use Git’s unsigned-long syntax: decimal, leading-zero octal, or 0x hexadecimal with an optional leading plus sign. A case-insensitive K, M, or G suffix uses powers of 1024, and the expanded value must remain in range. Boolean values are not integers for these fields.

Combine filters percent-encode whitespace, percent, plus, and Git’s reserved characters. Parsing rejects malformed escapes, decoded NUL bytes, empty child filters, and nesting beyond 32 levels. auto cannot be combined with another filter.

auto requires Git 2.54 or newer. libvcs passes it only to git clone and git fetch; an older Git reports the capability error. git pull rejects all filters, and git submodule update rejects auto before starting Git.

Typed Git object filters for partial clone and fetch operations.

class libvcs.cmd.git_filter.Auto
class libvcs.cmd.git_filter.Auto

Bases: object

Let Git choose the filter from server recommendations.

class libvcs.cmd.git_filter.BlobLimit
class libvcs.cmd.git_filter.BlobLimit

Bases: object

Omit blobs at or above a byte limit.

class libvcs.cmd.git_filter.BlobNone
class libvcs.cmd.git_filter.BlobNone

Bases: object

Omit all blobs until Git needs them.

class libvcs.cmd.git_filter.Combine
class libvcs.cmd.git_filter.Combine

Bases: object

Apply each child filter as one Git combine filter.

libvcs.cmd.git_filter.GitFilter: TypeAlias = <...truncated, 228 chars>
data
data
libvcs.cmd.git_filter.GitFilter: TypeAlias = <...truncated, 228 chars>

A validated Git partial-clone filter.

libvcs.cmd.git_filter.GitFilterInput: TypeAlias = <...truncated, 308 chars>
data
data
libvcs.cmd.git_filter.GitFilterInput: TypeAlias = <...truncated, 308 chars>

A filter model, spec, kind-tagged mapping, or nonempty sequence.

class libvcs.cmd.git_filter.ObjectType
class libvcs.cmd.git_filter.ObjectType

Bases: object

Include one Git object type.

class libvcs.cmd.git_filter.SparseOid
class libvcs.cmd.git_filter.SparseOid

Bases: object

Read sparse-checkout patterns from a Git object.

class libvcs.cmd.git_filter.TreeDepth
class libvcs.cmd.git_filter.TreeDepth

Bases: object

Omit trees and blobs at or beyond a traversal depth.

libvcs.cmd.git_filter.coerce_filter(value)
function[source]
function[source]
libvcs.cmd.git_filter.coerce_filter(value)

Validate and convert one accepted filter value to a model.

Parameters:

value (object) – A filter dataclass, native spec string, kind-tagged mapping, or nonempty sequence of non-auto filter inputs.

Returns:

Validated filter model (sequences return Combine).

Return type:

GitFilter

Raises:

ValueError – If value is None, empty, an unsupported type, or invalid under Git’s filter rules.

Examples

>>> coerce_filter(["blob:none", {"kind": "tree", "depth": 1}])
Combine(filters=(BlobNone(), TreeDepth(depth=1)))
libvcs.cmd.git_filter.filter_specs(value)
function[source]
function[source]
libvcs.cmd.git_filter.filter_specs(value)

Return canonical specs, preserving one flag per sequence item.

Parameters:

value (GitFilterInput | None) – Optional filter input. Sequences emit one --filter spec per item rather than collapsing into a single combine: spec.

Returns:

Canonical filter specifications, or () when value is None.

Return type:

tuple[str, ...]

Raises:

ValueError – If value or any sequence element fails filter validation, or if a sequence contains auto.

Examples

>>> filter_specs(["blob:none", TreeDepth(2)])
('blob:none', 'tree:2')
>>> filter_specs(None)
()
libvcs.cmd.git_filter.from_mapping(value)
function[source]
function[source]
libvcs.cmd.git_filter.from_mapping(value)

Build one Git filter from a kind-tagged mapping.

Parameters:

value (Mapping[str, object]) – Mapping carrying "kind" and the exact required fields for that filter kind.

Returns:

Validated filter model built from value.

Return type:

GitFilter

Raises:

ValueError – If "kind" is missing or unknown, any required field is absent or unsupported, or field values fail filter validation.

Examples

>>> from_mapping({"kind": "tree", "depth": 0})
TreeDepth(depth=0)
libvcs.cmd.git_filter.parse_filter(spec)
function[source]
function[source]
libvcs.cmd.git_filter.parse_filter(spec)

Parse one Git filter specification without running Git.

Parameters:

spec (str) – Native --filter=<spec> string, including combine: percent escapes.

Returns:

Validated filter model corresponding to spec.

Return type:

GitFilter

Raises:

ValueError – If spec is empty, contains NUL or newlines, exceeds 64-bit bounds or 32 nesting levels, embeds auto inside combine:, or violates Git’s filter grammar.

Examples

>>> parse_filter("blob:limit=4m")
BlobLimit(limit='4m')
>>> parse_filter("combine:blob:none+tree:1")
Combine(filters=(BlobNone(), TreeDepth(depth=1)))