~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/knotless

git that lives in your Atmosphere account

knotless.dev
1 collaborator

knotless 0.13.0 Latest 2 packages, 1 image

1
10

Code search skips a repository with no commits, rather than failing

Merged chadtmiller.com asked to merge into main from chadtmiller.com/knotless:serve/index-empty-repos
crates/knotless-serve/src/code.rs+5−1
@@ -504,7 +504,7 @@ async fn indexed(app: Arc<App>, code: Arc<Code>, did: String, key: String) {
}
/// Indexes `did`'s repository with `key` again, or forgets it if the
/// index no longer lists it.
/// index no longer lists it or its default branch has no commit to index.
async fn reindex(app: &App, code: &Code, did: &str, key: &str) -> Result<()> {
let index = app.index.as_ref().context("no index")?;
index.reindexed(did, key);
@@ -514,6 +514,10 @@ async fn reindex(app: &App, code: &Code, did: &str, key: &str) -> Result<()> {
};
let git = app.mirror(did, &listed.name).await.ok();
let git = git.context("its mirror could not be read")?;
if git.rev_parse("HEAD").await.is_err() {
code.forget(did, key);
return Ok(());
}
code.index(did, key, &git.dir).await
}
crates/knotless-serve/tests/web.rs+6−0
@@ -3618,6 +3618,8 @@ fn searching_code() {
let site = serve_with(Sandbox::new(), true, true);
let s = person(account(), &site);
let handle = s.account.handle.clone();
// With nothing pushed, there is nothing to index.
ok(&s, &["repo", "create", &s.url("unpushed")]);
// Pushed before code is indexed: what has no shards yet is indexed as
// indexing starts.
for (name, n) in [("needle-one", 1), ("needle-two", 2)] {
@@ -3721,6 +3723,10 @@ fn searching_code() {
};
// A push's new shard is found before the one it replaces is deleted.
wait_until(|| shards() == 2);
// Each pushed repository has its meta file, and the unpushed one none.
let metas = std::fs::read_dir(site._sandbox.path("code").join("meta")).unwrap();
let metas = metas.map(|e| e.unwrap().file_name().into_string().unwrap());
assert_eq!(metas.filter(|n| n.starts_with(&theirs)).count(), 2);
// `/_status` tells of the index.
let (_, status) = site.status("/_status");
let status: Value = serde_json::from_str(&status).unwrap();
docs/design/serve.md+2−1
@@ -422,7 +422,8 @@ built for searching code, as two programs beside it:
shards as they are written, so a repository written again is searched
at once.
- `zoekt-git-index` writes one repository's shards from its mirror, of
its default branch. A commit already indexed is left as it is.
its default branch. A commit already indexed is left as it is, and a
default branch with no commit has no shards.
A single task in the background indexes one repository at a time. As
the server starts it indexes each public repository the index lists