digest
Content digest computation and
sync_digests cache helpers.compute is a thin wrapper over SHA-256 used by the per-entity adapters
to decide whether an on-disk file needs rewriting. is_unchanged and
record are the read/write halves of the sync_digests cache, keyed by
(project_id, repo-relative path).
fn compute
pub fn compute(content: &[u8]) -> StringCompute the SHA-256 digest of content, returned as a lowercase hex string.
| Parameter | Type | Description |
|---|---|---|
content |
&[u8] | the bytes of the file as it would be written |
| returns | String | The digest, 64 characters long. |
fn is_unchanged
pub async fn is_unchanged(
conn: &Connection,
project_id: &Id,
relative_path: &str,
digest: &str,
) -> Result<bool, Error>Return true if the cached digest for (project_id, relative_path) matches
digest. Returns false when no entry exists or when the entry is stale.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection |
project_id |
&Id | the project that owns the file |
relative_path |
&str | the file’s path relative to the .gest/ directory, as [super::paths::relative] gives it |
digest |
&str | the digest of the content about to be written, from [compute] |
| returns | Result<bool, Error> | The flag, or a database error when the query fails. |
fn invalidate
pub async fn invalidate(
conn: &Connection,
project_id: &Id,
relative_path: &str,
) -> Result<(), Error>Remove the cached digest for relative_path so that a follow-up
undo + export cycle sees the cache as stale and rewrites the file.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection |
project_id |
&Id | the project that owns the file |
relative_path |
&str | the file’s path relative to the .gest/ directory |
| returns | Result<(), Error> | Ok(()) whether or not a row existed, or a database error. |
fn record
pub async fn record(
conn: &Connection,
project_id: &Id,
relative_path: &str,
digest: &str,
) -> Result<(), Error>Insert or update the cached digest for (project_id, relative_path).
The row’s synced_at is set to now.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection |
project_id |
&Id | the project that owns the file |
relative_path |
&str | the file’s path relative to the .gest/ directory |
digest |
&str | the digest of the content just written, from [compute] |
| returns | Result<(), Error> | Ok(()) once the row is stored, or a database error. |