Repo commit

class atproto_space.commit.RepoCommit(state: bytes | None = None)

Bases: object

Set hash of the records of a repo. The data of a commit is its digest.

Parameters:

state – State to continue from. The empty repo by default.

classmethod from_records(records: Iterable[RepoRecord]) → RepoCommit

Create RepoCommit instance from the records of a repo.

add(collection: str, rkey: str, cid: str) → None

Add the record to the repo.

Parameters:
  • collection – NSID of the record collection.

  • rkey – Record key.

  • cid – CID of the record.

remove(collection: str, rkey: str, cid: str) → None

Remove the record from the repo.

Parameters:
  • collection – NSID of the record collection.

  • rkey – Record key.

  • cid – CID of the record.

apply(collection: str, rkey: str, cid: str | None, prev: str | None) → None

Apply the operation to the repo.

Parameters:
  • collection – NSID of the record collection.

  • rkey – Record key.

  • cid – CID of the record after the operation. None when the record is deleted.

  • prev – CID of the record before the operation. None when the record is created.

matches(commit: models.ComAtprotoSpaceDefs.Commit) → bool

Tell whether the records of the repo are the ones that the commit describes.

Note

The commit is not verified. On its own a match says nothing about where the records came from.

Parameters:

commit – Commit of the repo.

Returns:

Whether the data of the commit is the digest of the records.

Return type:

bool

property state: bytes

Get state of the set hash, which a later RepoCommit continues from.

atproto_space.commit.verify_commit(commit: models.ComAtprotoSpaceDefs.Commit, space: str, repo: str) → None

Verify that a commit is well-formed and describes the requested repo.

Note

The commit is not authenticated. See atproto_space.mac.verify_commit_mac().

Parameters:
  • commit – Commit to verify.

  • space – URI of the space that was requested.

  • repo – DID of the repo that was requested.

Raises:

atproto_space.exceptions.SpaceRepoVerificationError – The commit has an unsupported version, describes another repo or another space, or is malformed.