module documentation

Safe access to git files.

Exception FileLocked File is already locked.
Function ensure_dir_exists Ensure a directory exists, creating if necessary.
Function GitFile Create a file object that obeys the git file locking protocol.
Class _GitFile File that follows the git locking protocol for writes.
Function _fancy_rename Rename file with temporary backup file to rollback if rename fails.
def ensure_dir_exists(dirname: str | bytes | os.PathLike[str] | os.PathLike[bytes]):

Ensure a directory exists, creating if necessary.

def GitFile(filename: str | bytes | os.PathLike[str] | os.PathLike[bytes], mode: Literal['wb'], bufsize: int = -1, mask: int = 420, fsync: bool = True) -> _GitFile:
def GitFile(filename: str | bytes | os.PathLike[str] | os.PathLike[bytes], mode: Literal['rb'] = 'rb', bufsize: int = -1, mask: int = 420, fsync: bool = True) -> IO[bytes]:
def GitFile(filename: str | bytes | os.PathLike[str] | os.PathLike[bytes], mode: str = 'rb', bufsize: int = -1, mask: int = 420, fsync: bool = True) -> IO[bytes] | _GitFile:

Create a file object that obeys the git file locking protocol.

Returns: a builtin file object or a _GitFile object

Note: See _GitFile for a description of the file locking protocol.

Only read-only and write-only (binary) modes are supported; r+, w+, and a are not. To read and write from the same file, you can take advantage of the fact that opening a file for write does not actually open the file you request.

The default file mask makes any created files user-writable and world-readable.

Parameters
filename:str | bytes | os.PathLike[str] | os.PathLike[bytes]Path to the file
mode:strFile mode (only 'rb' and 'wb' are supported)
bufsize:intBuffer size for file operations
mask:intFile mask for created files
fsync:boolWhether to call fsync() before closing (default: True)
Returns
IO[bytes] | _GitFileUndocumented
def _fancy_rename(oldname: str | bytes, newname: str | bytes):

Rename file with temporary backup file to rollback if rename fails.