Remove dependency on nom, once_cell & parking_lot
Diff
Cargo.lock | 3 ---
Cargo.toml | 3 ---
src/git.rs | 31 ++++++++++++++++++++++---------
src/main.rs | 12 ++++++------
4 files changed, 21 insertions(+), 28 deletions(-)
@@ -2926,9 +2926,6 @@
"itertools 0.13.0",
"md5",
"moka",
"nom",
"once_cell",
"parking_lot",
"path-clean",
"rand",
"rocksdb",
@@ -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"] }
@@ -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<Arc<str>>,
) -> Result<Arc<OpenRepository>> {
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<Git>,
cache_key: PathBuf,
repo: Mutex<gix::Repository>,
repo: ThreadSafeRepository,
branch: Option<Arc<str>>,
}
@@ -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<Self>) -> Result<DetailedTag> {
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<Self>) -> Result<Option<String>> {
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<Self>, highlighted: bool) -> Result<Commit> {
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)?;
@@ -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<Box<str>> = Lazy::new(|| build_asset_hash(GLOBAL_CSS));
static GLOBAL_CSS_HASH: LazyLock<Box<str>> = LazyLock::new(|| build_asset_hash(GLOBAL_CSS));
static HIGHLIGHT_CSS_HASH: OnceCell<Box<str>> = OnceCell::new();
static DARK_HIGHLIGHT_CSS_HASH: OnceCell<Box<str>> = OnceCell::new();
static HIGHLIGHT_CSS_HASH: OnceLock<Box<str>> = OnceLock::new();
static DARK_HIGHLIGHT_CSS_HASH: OnceLock<Box<str>> = 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)?;