From 37f9347ab57d9006437467c28a2d0deef573de9c Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 28 Sep 2024 15:23:46 +0400 Subject: [PATCH] Remove dependency on nom, once_cell & parking_lot --- Cargo.lock | 3 --- Cargo.toml | 3 --- src/git.rs | 31 ++++++++++++++++++++++--------- src/main.rs | 12 ++++++------ 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc531da..4139f0a 100644 --- a/Cargo.lock +++ a/Cargo.lock @@ -2926,9 +2926,6 @@ "itertools 0.13.0", "md5", "moka", - "nom", - "once_cell", - "parking_lot", "path-clean", "rand", "rocksdb", diff --git a/Cargo.toml b/Cargo.toml index 6eeb66b..e05198b 100644 --- a/Cargo.toml +++ a/Cargo.toml @@ -30,9 +30,6 @@ itertools = "0.13.0" md5 = "0.7" moka = { version = "0.12.0", features = ["future"] } -nom = "7.1" -once_cell = "1.18" -parking_lot = "0.12" path-clean = "1.0.1" rand = "0.8.5" rocksdb = { version = "0.22", default-features = false, features = ["snappy"] } diff --git a/src/git.rs b/src/git.rs index 6980140..e7c5a1b 100644 --- a/src/git.rs +++ a/src/git.rs @@ -22,10 +22,9 @@ objs::tree::EntryRef, prelude::TreeEntryRefExt, traverse::tree::visit::Action, - ObjectId, + ObjectId, ThreadSafeRepository, }; use moka::future::Cache; -use parking_lot::Mutex; use syntect::{ parsing::{BasicScopeStackOp, ParseState, Scope, ScopeStack, SyntaxSet, SCOPE_REPO}, util::LinesWithEndings, @@ -71,9 +70,13 @@ repo_path: PathBuf, branch: Option>, ) -> Result> { - let mut repo = tokio::task::spawn_blocking({ + let repo = tokio::task::spawn_blocking({ let repo_path = repo_path.clone(); - move || gix::open(repo_path) + move || { + gix::open::Options::isolated() + .open_path_as_is(true) + .open(&repo_path) + } }) .await .context("Failed to join Tokio task")? @@ -81,13 +84,11 @@ error!("{}", err); anyhow!("Failed to open repository") })?; - - repo.object_cache_size(10 * 1024 * 1024); Ok(Arc::new(OpenRepository { git: self, cache_key: repo_path, - repo: Mutex::new(repo), + repo, branch, })) } @@ -96,7 +97,7 @@ pub struct OpenRepository { git: Arc, cache_key: PathBuf, - repo: Mutex, + repo: ThreadSafeRepository, branch: Option>, } @@ -113,7 +114,7 @@ .context("Failed to parse tree hash")?; tokio::task::spawn_blocking(move || { - let repo = self.repo.lock(); + let repo = self.repo.to_thread_local(); let mut tree = if let Some(tree_id) = tree_id { repo.find_tree(tree_id) @@ -213,7 +214,7 @@ pub async fn tag_info(self: Arc) -> Result { tokio::task::spawn_blocking(move || { let tag_name = self.branch.clone().context("no tag given")?; - let repo = self.repo.lock(); + let repo = self.repo.to_thread_local(); let tag = repo .find_reference(&format!("refs/tags/{tag_name}")) @@ -255,7 +256,7 @@ git.readme_cache .try_get_with((self.cache_key.clone(), self.branch.clone()), async move { tokio::task::spawn_blocking(move || { - let repo = self.repo.lock(); + let repo = self.repo.to_thread_local(); let mut head = if let Some(reference) = &self.branch { repo.find_reference(reference.as_ref())? @@ -306,7 +307,7 @@ pub async fn default_branch(self: Arc) -> Result> { tokio::task::spawn_blocking(move || { - let repo = self.repo.lock(); + let repo = self.repo.to_thread_local(); let head = repo.head().context("Couldn't find HEAD of repository")?; Ok(head.referent_name().map(|v| v.shorten().to_string())) }) @@ -317,7 +318,7 @@ #[instrument(skip(self))] pub async fn latest_commit(self: Arc, highlighted: bool) -> Result { tokio::task::spawn_blocking(move || { - let repo = self.repo.lock(); + let repo = self.repo.to_thread_local(); let mut head = if let Some(reference) = &self.branch { repo.find_reference(reference.as_ref())? @@ -354,7 +355,7 @@ .context("failed to build oid")?; tokio::task::spawn_blocking(move || { - let repo = self.repo.lock(); + let repo = self.repo.to_thread_local(); let tree = if let Some(commit) = commit { repo.find_commit(commit)?.tree()? @@ -411,7 +412,7 @@ git.commits .try_get_with((commit, highlighted), async move { tokio::task::spawn_blocking(move || { - let repo = self.repo.lock(); + let repo = self.repo.to_thread_local(); let commit = repo.find_commit(commit)?; diff --git a/src/main.rs b/src/main.rs index d192f32..28e4ba7 100644 --- a/src/main.rs +++ a/src/main.rs @@ -7,7 +7,7 @@ net::SocketAddr, path::PathBuf, str::FromStr, - sync::Arc, + sync::{Arc, LazyLock, OnceLock}, time::Duration, }; @@ -24,8 +24,6 @@ use bat::assets::HighlightingAssets; use clap::Parser; use database::schema::SCHEMA_VERSION; -use nom::AsBytes; -use once_cell::sync::{Lazy, OnceCell}; use rocksdb::{Options, SliceTransform}; use sha2::{digest::FixedOutput, Digest}; use syntect::html::ClassStyle; @@ -57,10 +55,10 @@ const CRATE_VERSION: &str = clap::crate_version!(); static GLOBAL_CSS: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/statics/css/style.css",)); -static GLOBAL_CSS_HASH: Lazy> = Lazy::new(|| build_asset_hash(GLOBAL_CSS)); +static GLOBAL_CSS_HASH: LazyLock> = LazyLock::new(|| build_asset_hash(GLOBAL_CSS)); -static HIGHLIGHT_CSS_HASH: OnceCell> = OnceCell::new(); -static DARK_HIGHLIGHT_CSS_HASH: OnceCell> = OnceCell::new(); +static HIGHLIGHT_CSS_HASH: OnceLock> = OnceLock::new(); +static DARK_HIGHLIGHT_CSS_HASH: OnceLock> = OnceLock::new(); #[derive(Parser, Debug)] #[clap(author, version, about)] @@ -260,7 +258,7 @@ )?; let needs_schema_regen = match db.get("schema_version")? { - Some(v) if v.as_bytes() != SCHEMA_VERSION.as_bytes() => Some(Some(v)), + Some(v) if v.as_slice() != SCHEMA_VERSION.as_bytes() => Some(Some(v)), Some(_) => None, None => { db.put("schema_version", SCHEMA_VERSION)?; -- rgit 0.1.3