Skip to content

Commit 37f9347

Browse files
committed
Remove dependency on nom, once_cell & parking_lot
1 parent 3a3f23a commit 37f9347

File tree

4 files changed

+21
-28
lines changed

4 files changed

+21
-28
lines changed

Cargo.lock

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ humantime = "2.1"
3030
itertools = "0.13.0"
3131
md5 = "0.7"
3232
moka = { version = "0.12.0", features = ["future"] }
33-
nom = "7.1"
34-
once_cell = "1.18"
35-
parking_lot = "0.12"
3633
path-clean = "1.0.1"
3734
rand = "0.8.5"
3835
rocksdb = { version = "0.22", default-features = false, features = ["snappy"] }

src/git.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ use gix::{
2222
objs::tree::EntryRef,
2323
prelude::TreeEntryRefExt,
2424
traverse::tree::visit::Action,
25-
ObjectId,
25+
ObjectId, ThreadSafeRepository,
2626
};
2727
use moka::future::Cache;
28-
use parking_lot::Mutex;
2928
use syntect::{
3029
parsing::{BasicScopeStackOp, ParseState, Scope, ScopeStack, SyntaxSet, SCOPE_REPO},
3130
util::LinesWithEndings,
@@ -71,9 +70,13 @@ impl Git {
7170
repo_path: PathBuf,
7271
branch: Option<Arc<str>>,
7372
) -> Result<Arc<OpenRepository>> {
74-
let mut repo = tokio::task::spawn_blocking({
73+
let repo = tokio::task::spawn_blocking({
7574
let repo_path = repo_path.clone();
76-
move || gix::open(repo_path)
75+
move || {
76+
gix::open::Options::isolated()
77+
.open_path_as_is(true)
78+
.open(&repo_path)
79+
}
7780
})
7881
.await
7982
.context("Failed to join Tokio task")?
@@ -82,12 +85,10 @@ impl Git {
8285
anyhow!("Failed to open repository")
8386
})?;
8487

85-
repo.object_cache_size(10 * 1024 * 1024);
86-
8788
Ok(Arc::new(OpenRepository {
8889
git: self,
8990
cache_key: repo_path,
90-
repo: Mutex::new(repo),
91+
repo,
9192
branch,
9293
}))
9394
}
@@ -96,7 +97,7 @@ impl Git {
9697
pub struct OpenRepository {
9798
git: Arc<Git>,
9899
cache_key: PathBuf,
99-
repo: Mutex<gix::Repository>,
100+
repo: ThreadSafeRepository,
100101
branch: Option<Arc<str>>,
101102
}
102103

@@ -113,7 +114,7 @@ impl OpenRepository {
113114
.context("Failed to parse tree hash")?;
114115

115116
tokio::task::spawn_blocking(move || {
116-
let repo = self.repo.lock();
117+
let repo = self.repo.to_thread_local();
117118

118119
let mut tree = if let Some(tree_id) = tree_id {
119120
repo.find_tree(tree_id)
@@ -213,7 +214,7 @@ impl OpenRepository {
213214
pub async fn tag_info(self: Arc<Self>) -> Result<DetailedTag> {
214215
tokio::task::spawn_blocking(move || {
215216
let tag_name = self.branch.clone().context("no tag given")?;
216-
let repo = self.repo.lock();
217+
let repo = self.repo.to_thread_local();
217218

218219
let tag = repo
219220
.find_reference(&format!("refs/tags/{tag_name}"))
@@ -255,7 +256,7 @@ impl OpenRepository {
255256
git.readme_cache
256257
.try_get_with((self.cache_key.clone(), self.branch.clone()), async move {
257258
tokio::task::spawn_blocking(move || {
258-
let repo = self.repo.lock();
259+
let repo = self.repo.to_thread_local();
259260

260261
let mut head = if let Some(reference) = &self.branch {
261262
repo.find_reference(reference.as_ref())?
@@ -306,7 +307,7 @@ impl OpenRepository {
306307

307308
pub async fn default_branch(self: Arc<Self>) -> Result<Option<String>> {
308309
tokio::task::spawn_blocking(move || {
309-
let repo = self.repo.lock();
310+
let repo = self.repo.to_thread_local();
310311
let head = repo.head().context("Couldn't find HEAD of repository")?;
311312
Ok(head.referent_name().map(|v| v.shorten().to_string()))
312313
})
@@ -317,7 +318,7 @@ impl OpenRepository {
317318
#[instrument(skip(self))]
318319
pub async fn latest_commit(self: Arc<Self>, highlighted: bool) -> Result<Commit> {
319320
tokio::task::spawn_blocking(move || {
320-
let repo = self.repo.lock();
321+
let repo = self.repo.to_thread_local();
321322

322323
let mut head = if let Some(reference) = &self.branch {
323324
repo.find_reference(reference.as_ref())?
@@ -354,7 +355,7 @@ impl OpenRepository {
354355
.context("failed to build oid")?;
355356

356357
tokio::task::spawn_blocking(move || {
357-
let repo = self.repo.lock();
358+
let repo = self.repo.to_thread_local();
358359

359360
let tree = if let Some(commit) = commit {
360361
repo.find_commit(commit)?.tree()?
@@ -411,7 +412,7 @@ impl OpenRepository {
411412
git.commits
412413
.try_get_with((commit, highlighted), async move {
413414
tokio::task::spawn_blocking(move || {
414-
let repo = self.repo.lock();
415+
let repo = self.repo.to_thread_local();
415416

416417
let commit = repo.find_commit(commit)?;
417418

src/main.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
net::SocketAddr,
88
path::PathBuf,
99
str::FromStr,
10-
sync::Arc,
10+
sync::{Arc, LazyLock, OnceLock},
1111
time::Duration,
1212
};
1313

@@ -24,8 +24,6 @@ use axum::{
2424
use bat::assets::HighlightingAssets;
2525
use clap::Parser;
2626
use database::schema::SCHEMA_VERSION;
27-
use nom::AsBytes;
28-
use once_cell::sync::{Lazy, OnceCell};
2927
use rocksdb::{Options, SliceTransform};
3028
use sha2::{digest::FixedOutput, Digest};
3129
use syntect::html::ClassStyle;
@@ -57,10 +55,10 @@ mod unified_diff_builder;
5755
const CRATE_VERSION: &str = clap::crate_version!();
5856

5957
static GLOBAL_CSS: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/statics/css/style.css",));
60-
static GLOBAL_CSS_HASH: Lazy<Box<str>> = Lazy::new(|| build_asset_hash(GLOBAL_CSS));
58+
static GLOBAL_CSS_HASH: LazyLock<Box<str>> = LazyLock::new(|| build_asset_hash(GLOBAL_CSS));
6159

62-
static HIGHLIGHT_CSS_HASH: OnceCell<Box<str>> = OnceCell::new();
63-
static DARK_HIGHLIGHT_CSS_HASH: OnceCell<Box<str>> = OnceCell::new();
60+
static HIGHLIGHT_CSS_HASH: OnceLock<Box<str>> = OnceLock::new();
61+
static DARK_HIGHLIGHT_CSS_HASH: OnceLock<Box<str>> = OnceLock::new();
6462

6563
#[derive(Parser, Debug)]
6664
#[clap(author, version, about)]
@@ -260,7 +258,7 @@ fn open_db(args: &Args) -> Result<Arc<rocksdb::DB>, anyhow::Error> {
260258
)?;
261259

262260
let needs_schema_regen = match db.get("schema_version")? {
263-
Some(v) if v.as_bytes() != SCHEMA_VERSION.as_bytes() => Some(Some(v)),
261+
Some(v) if v.as_slice() != SCHEMA_VERSION.as_bytes() => Some(Some(v)),
264262
Some(_) => None,
265263
None => {
266264
db.put("schema_version", SCHEMA_VERSION)?;

0 commit comments

Comments
 (0)