gitscope
← rgit / Diff · 37f9347 → 37f9347
Changes 37f9347..37f9347
Patch commit
diff --git a/Cargo.lock b/Cargo.lock
index dc531da..4139f0a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2926,9 +2926,6 @@ dependencies = [
"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
+++ b/Cargo.toml
@@ -30,9 +30,6 @@ humantime = "2.1"
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
+++ b/src/git.rs
@@ -22,10 +22,9 @@ use gix::{
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 @@ impl Git {
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")?
@@ -82,12 +85,10 @@ impl Git {
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 @@ impl Git {
pub struct OpenRepository {
git: Arc<Git>,
cache_key: PathBuf,
- repo: Mutex<gix::Repository>,
+ repo: ThreadSafeRepository,
branch: Option<Arc<str>>,
}
@@ -113,7 +114,7 @@ impl OpenRepository {
.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 @@ impl OpenRepository {
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 @@ impl OpenRepository {
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 @@ impl OpenRepository {
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 @@ impl OpenRepository {
#[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 @@ impl OpenRepository {
.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 @@ impl OpenRepository {
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
+++ b/src/main.rs
@@ -7,7 +7,7 @@ use std::{
net::SocketAddr,
path::PathBuf,
str::FromStr,
- sync::Arc,
+ sync::{Arc, LazyLock, OnceLock},
time::Duration,
};
@@ -24,8 +24,6 @@ use axum::{
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 @@ mod unified_diff_builder;
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 @@ fn open_db(args: &Args) -> Result<Arc<rocksdb::DB>, anyhow::Error> {
)?;
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)?;