Object filtering for Git partial clone and pack generation.
This module implements Git's object filter specifications for partial clone, as documented in: https://git-scm.com/docs/rev-list-options#Documentation/rev-list-options.txt---filterltfilter-specgt
Filter specifications control which objects are included when generating packs, enabling partial clone (downloading only needed objects) and similar operations.
Supported filter specs: - blob:none - Exclude all blobs - blob:limit=<n>[kmg] - Exclude blobs larger than n bytes/KB/MB/GB - tree:<depth> - Exclude trees beyond specified depth - sparse:oid=<oid> - Use sparse specification from object - combine:<filter>+<filter>+... - Combine multiple filters
| Class | |
Filter that excludes blobs larger than a specified size. |
| Class | |
Filter that excludes all blobs. |
| Class | |
Filter that combines multiple filters with AND logic. |
| Class | |
Base class for all filter specifications. |
| Class | |
Filter that uses a sparse specification from an object. |
| Class | |
Filter that excludes trees beyond a specified depth. |
| Function | filter |
Filter a list of object IDs based on a filter specification. |
| Function | filter |
Filter objects for a pack with full path and depth tracking. |
| Function | parse |
Parse a filter specification string. |
| Function | _parse |
Parse a size specification like '100', '10k', '5m', '1g'. |
BaseObjectStore, object_ids: list[ ObjectID], filter_spec: FilterSpec) -> list[ ObjectID]:
¶
Filter a list of object IDs based on a filter specification.
This function examines each object and excludes those that don't match the filter criteria (e.g., blobs that are too large, trees beyond max depth).
Note
This function currently supports blob size filtering. Tree depth filtering requires additional path/depth tracking which is not yet implemented.
| Parameters | |
objectBaseObjectStore | Object store to retrieve objects from |
objectlist[ | List of object IDs to filter |
filterFilterSpec | Filter specification to apply |
| Returns | |
list[ | Filtered list of object IDs that should be included in the pack |
BaseObjectStore, wants: list[ ObjectID], filter_spec: FilterSpec, *, progress: Callable[ [ bytes], None] | None = None) -> list[ ObjectID]:
¶
Filter objects for a pack with full path and depth tracking.
This function performs a complete tree traversal starting from the wanted commits, tracking paths and depths to enable proper filtering for sparse:oid and tree:<depth> filters.
| Parameters | |
objectBaseObjectStore | Object store to retrieve objects from |
wants:list[ | List of commit/tree/blob IDs that are wanted |
filterFilterSpec | Filter specification to apply |
progress:Callable[ | Optional progress callback |
| Returns | |
list[ | Filtered list of object IDs that should be included in the pack |
str | bytes, object_store: BaseObjectStore | None = None) -> FilterSpec:
¶
Parse a filter specification string.
Examples
>>> parse_filter_spec("blob:none") BlobNoneFilter() >>> parse_filter_spec("blob:limit=1m") BlobLimitFilter(limit=1048576) >>> parse_filter_spec("tree:0") TreeDepthFilter(max_depth=0)
| Parameters | |
spec:str | bytes | Filter specification (e.g., 'blob:none', 'blob:limit=1m') |
objectBaseObjectStore | None | Optional object store for loading sparse specifications |
| Returns | |
FilterSpec | Parsed FilterSpec object |
| Raises | |
ValueError | If spec is not a valid filter specification |