Skip to main content

Index

Struct Index 

Source
pub struct Index { /* private fields */ }
Expand description

SQLite-backed cache index.

Wraps a single Connection. All public methods in this module treat index errors as non-fatal: they warn to stderr and fall back gracefully, matching the tolerant pattern used in inventory.rs.

Implementations§

Source§

impl Index

Source

pub fn open(base: &Path) -> Self

Opens (or creates) the index at <base>/index.db.

Behaviour on failure at any stage (open, WAL pragma, migration, integrity check):

  1. Print warning: … to stderr.
  2. Delete index.db, index.db-wal, index.db-shm from base.
  3. Attempt to create a fresh db in the same location.
  4. If that also fails, fall back to an in-memory db so the command continues without an index — never panic, never abort.
Source

pub fn open_in_memory() -> Self

Opens an in-memory index for tests (same migration, no disk I/O).

Source

pub fn cached_common_dir(&self, path: &Path) -> Option<(String, PathBuf)>

Returns (common_dir_hash, common_dir) cached for path, or None on miss or any index error.

Source

pub fn put_repo_common_dir( &self, path: &Path, common_dir_hash: &str, common_dir: &Path, )

Upserts (path, common_dir_hash, common_dir) into repos, leaving the remaining columns (default_branch, default_sha, refs_fingerprint, last_indexed) NULL. On any index error, prints a warning and continues.

Source

pub fn cached_loops( &self, hash: &str, refs_fp: i64, default_sha: &str, ) -> Option<Vec<LoopRow>>

Returns the cached loops for hash, but ONLY when the stored repo row proves the cache is still valid:

  1. repos.refs_fingerprint == refs_fp (refs haven’t changed), AND
  2. repos.default_sha == default_sha (the base hasn’t moved).

Returns None on any mismatch, on a missing/un-populated repo row, or on any index error. A NULL default_sha / refs_fingerprint (a repo row inserted by put_repo_common_dir but never put_loops’d) is a clean miss — no warning is emitted, since it is the normal pre-put_loops state.

Source

pub fn put_loops( &self, hash: &str, path: &Path, common_dir: &Path, default_branch: &str, default_sha: &str, refs_fp: i64, rows: &[LoopRow], )

Write-through for a completed scan of one repo: upserts the repos row (default branch/SHA, refs fingerprint, last_indexed) and REPLACES the repo’s loops rows — all in a single transaction.

On any index error, prints a warning and continues (git is the source of truth; the index is disposable).

Source

pub fn upsert_session( &self, path: &Path, repo_path: &Path, mtime: i64, size: i64, text: &str, )

Upserts a session’s bounded tail text into the sessions table and the sessions_fts virtual table.

Reindexes ONLY when the stored (mtime, size) for path differs from the supplied values. Unchanged files are skipped (no I/O, no FTS write). size is compared alongside mtime so a same-second append that grows the file still forces a reindex (closes the same-second FTS staleness window, I-2). On any index error, prints a warning and continues.

Source

pub fn session_mentions( &self, repo_path: &Path, branch: &str, ) -> HashSet<PathBuf>

Returns the set of session file paths (scoped to repo_path) whose indexed text matches branch via FTS5.

No file reads. On any index error, returns an empty set.

Source

pub fn prune_missing_repos(&self)

Deletes repos rows (and their dependent loops rows) whose repo is gone from disk. This is stricter than inventory::prune_orphans, which prunes on a single repo_path existence check (and also reclaims unreadable files); here a row is removed only when BOTH the scanned path AND the common_dir are gone.

A repo is an orphan only when BOTH its scanned path and its common_dir no longer exist: a worktree directory may be removed while the shared bare store under common_dir survives (its branches are still real), so we must keep the row in that case. Removal is self-healing — a returning repo is simply re-discovered and re-indexed on the next scan.

On any index error, prints a warning and continues (git is the source of truth; the index is disposable).

Auto Trait Implementations§

§

impl !Freeze for Index

§

impl !RefUnwindSafe for Index

§

impl !Sync for Index

§

impl !UnwindSafe for Index

§

impl Send for Index

§

impl Unpin for Index

§

impl UnsafeUnpin for Index

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.