A Git Index file.
| Method | __contains__ |
Check if a path exists in the index. |
| Method | __delitem__ |
Delete an entry from the index. |
| Method | __getitem__ |
Retrieve entry by relative path and stage. |
| Method | __init__ |
Create an index object associated with the given filename. |
| Method | __iter__ |
Iterate over the paths and stages in this index. |
| Method | __len__ |
Number of entries in this index file. |
| Method | __repr__ |
Return string representation of Index. |
| Method | __setitem__ |
Set an entry in the index. |
| Method | canonical |
Resolve name to the canonical key stored in the index. |
| Method | changes |
Find the differences between the contents of this index and a tree. |
| Method | clear |
Remove all contents from this index. |
| Method | commit |
Create a new tree from an index. |
| Method | convert |
Convert full index entries to sparse directory entries. |
| Method | ensure |
Expand all sparse directory entries into full file entries. |
| Method | get |
Return the POSIX file mode for the object at a path. |
| Method | get |
Return the (git object) SHA1 for the object at a path. |
| Method | has |
Check if the index contains any conflicted entries. |
| Method | is |
Check if this index contains sparse directory entries. |
| Method | items |
Get an iterator over (path, entry) pairs. |
| Method | iteritems |
Iterate over (path, entry) pairs in the index. |
| Method | iterobjects |
Iterate over path, sha, mode tuples for use with commit_tree. |
| Method | paths |
Generate all paths in the index. |
| Method | read |
Read current contents of index from disk. |
| Method | update |
Update the index with multiple entries. |
| Method | write |
Write current contents of index to disk. |
| Property | path |
Get the path to the index file. |
| Method | _expand |
Recursively expand a tree into index entries. |
| Method | _find |
Find the SHA of a subtree at a given path. |
| Instance Variable | _byname |
Undocumented |
| Instance Variable | _extensions |
Undocumented |
| Instance Variable | _file |
Undocumented |
| Instance Variable | _filename |
Undocumented |
| Instance Variable | _normalized |
Undocumented |
| Instance Variable | _path |
Undocumented |
| Instance Variable | _skip |
Undocumented |
| Instance Variable | _version |
Undocumented |
Retrieve entry by relative path and stage.
Returns: Either a IndexEntry or a ConflictedIndexEntry Raises KeyError: if the entry does not exist
bytes | str | os.PathLike[ str], read: bool = True, skip_hash: bool = False, version: int | None = None, *, file_mode: int | None = None, path_normalizer: Callable[ [ bytes], bytes] | None = None):
¶
Create an index object associated with the given filename.
| Parameters | |
filename:bytes | str | os.PathLike[ | Path to the index file |
read:bool | Whether to initialize the index from the given file, should it exist. |
skipbool | Whether to skip SHA1 hash when writing (for manyfiles feature) |
version:int | None | Index format version to use (None = auto-detect from file or use default) |
fileint | None | Optional file permission mask for shared repository |
pathCallable[ | Optional function mapping a filesystem path to a canonical form (e.g. case-folded, NFC-normalized). When provided, lookups (index[path], path in index, del index[path]) transparently match paths that normalize to the same form as an existing entry. |
Resolve name to the canonical key stored in the index.
If an entry already exists under name (or no normalizer is configured), name is returned unchanged. Otherwise the normalizer is applied and the key of any entry with the same normalized form is returned. Falls back to name if none.
Normally callers do not need this because index[name], name in index, and del index[name] already apply normalization transparently. Use this when the path is also being used outside the index (for example to look up the same entry in a commit tree), so that both sides agree on the key.
ObjectContainer, tree: ObjectID, want_unchanged: bool = False) -> Generator[ tuple[ tuple[ bytes | None, bytes | None], tuple[ int | None, int | None], tuple[ bytes | None, bytes | None]], None, None]:
¶
Find the differences between the contents of this index and a tree.
- Returns: Iterator over tuples with (oldpath, newpath), (oldmode,
- newmode), (oldsha, newsha)
| Parameters | |
objectObjectContainer | Object store to use for retrieving tree contents |
tree:ObjectID | SHA1 of the root tree |
wantbool | Whether unchanged files should be reported |
| Returns | |
Generator[ | Undocumented |
Create a new tree from an index.
| Parameters | |
objectObjectContainer | Object store to save the tree in |
| Returns | |
ObjectID | Root tree SHA |
BaseObjectStore, tree_sha: ObjectID, sparse_dirs: Set[ bytes]):
¶
Convert full index entries to sparse directory entries.
This collapses directories that are entirely outside the sparse checkout cone into single sparse directory entries.
| Parameters | |
objectBaseObjectStore | Object store to read tree objects |
treeObjectID | SHA of the tree (usually HEAD) to base sparse dirs on |
sparseSet[ | Set of directory paths (with trailing /) to collapse |
| Raises | |
KeyError | If tree_sha or a subdirectory doesn't exist |
Expand all sparse directory entries into full file entries.
This converts a sparse index into a full index by recursively expanding any sparse directory entries into their constituent files.
| Parameters | |
objectBaseObjectStore | Object store to read tree objects from |
| Raises | |
KeyError | If a tree object referenced by a sparse dir entry doesn't exist |
Check if the index contains any conflicted entries.
| Returns | |
bool | True if any entries are conflicted, False otherwise |
Check if this index contains sparse directory entries.
| Returns | |
bool | True if any sparse directory extension is present |
Get an iterator over (path, entry) pairs.
| Returns | |
Iterator[ | Iterator of (path, entry) tuples |
Iterate over (path, entry) pairs in the index.
| Returns | |
Iterator[ | Iterator of (path, entry) tuples |
Update the index with multiple entries.
| Parameters | |
entries:dict[ | Dictionary mapping paths to index entries |
bytes, tree: Tree, object_store: BaseObjectStore, template_entry: IndexEntry):
¶
Recursively expand a tree into index entries.
| Parameters | |
prefix:bytes | Path prefix for entries (without trailing slash) |
tree:Tree | Tree object to expand |
objectBaseObjectStore | Object store to read nested trees from |
templateIndexEntry | Template entry to copy metadata from |
Tree, path: bytes, object_store: BaseObjectStore) -> bytes | None:
¶
Find the SHA of a subtree at a given path.
| Parameters | |
tree:Tree | Root tree object to search in |
path:bytes | Path to the subdirectory (no trailing slash) |
objectBaseObjectStore | Object store to read nested trees from |
| Returns | |
bytes | None | SHA of the subtree, or None if path doesn't exist |