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 |
|---|---|---|
|
Omit blobs until Git needs them |
|
|
Omit blobs at or above the byte limit |
|
|
Omit trees and blobs at depth |
|
|
Include one of |
|
|
Read sparse patterns from an object |
|
|
Ask Git to choose a server-recommended 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:
objectLet Git choose the filter from server recommendations.
-
class libvcs.cmd.git_filter.BlobLimit¶class libvcs.cmd.git_filter.BlobLimit¶
Bases:
objectOmit blobs at or above a byte limit.
-
class libvcs.cmd.git_filter.BlobNone¶class libvcs.cmd.git_filter.BlobNone¶
Bases:
objectOmit all blobs until Git needs them.
-
class libvcs.cmd.git_filter.Combine¶class libvcs.cmd.git_filter.Combine¶
Bases:
objectApply each child filter as one Git combine filter.
A validated Git partial-clone filter.
A filter model, spec, kind-tagged mapping, or nonempty sequence.
-
class libvcs.cmd.git_filter.ObjectType¶class libvcs.cmd.git_filter.ObjectType¶
Bases:
objectInclude one Git object type.
-
class libvcs.cmd.git_filter.SparseOid¶class libvcs.cmd.git_filter.SparseOid¶
Bases:
objectRead sparse-checkout patterns from a Git object.
-
class libvcs.cmd.git_filter.TreeDepth¶class libvcs.cmd.git_filter.TreeDepth¶
Bases:
objectOmit trees and blobs at or beyond a traversal depth.
-
libvcs.cmd.git_filter.coerce_filter(value)¶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-autofilter inputs.- Returns:
Validated filter model (sequences return
Combine).- Return type:
- Raises:
ValueError– IfvalueisNone, 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)¶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--filterspec per item rather than collapsing into a singlecombine:spec.- Returns:
Canonical filter specifications, or
()whenvalueisNone.- Return type:
- Raises:
ValueError– Ifvalueor any sequence element fails filter validation, or if a sequence containsauto.
Examples
>>> filter_specs(["blob:none", TreeDepth(2)]) ('blob:none', 'tree:2') >>> filter_specs(None) ()
-
libvcs.cmd.git_filter.from_mapping(value)¶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:
- 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)¶libvcs.cmd.git_filter.parse_filter(spec)¶
Parse one Git filter specification without running Git.
- Parameters:
spec (
str) – Native--filter=<spec>string, includingcombine:percent escapes.- Returns:
Validated filter model corresponding to
spec.- Return type:
- Raises:
ValueError– Ifspecis empty, contains NUL or newlines, exceeds 64-bit bounds or 32 nesting levels, embedsautoinsidecombine:, 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)))