diff --git a/src/database/indexer.rs b/src/database/indexer.rs
@@ -8,10 +8,10 @@ use crate::database::schema::{
repository::{Repository, RepositoryId},
};
-pub fn run_indexer(db: &sled::Db) {
+pub fn run(db: &sled::Db) {
let scan_path = Path::new("/Users/jordan/Code/test-git");
- update_repository_metadata(scan_path, &db);
- update_repository_reflog(scan_path, &db);
+ update_repository_metadata(scan_path, db);
+ update_repository_reflog(scan_path, db);
}
fn update_repository_metadata(scan_path: &Path, db: &sled::Db) {
@@ -21,9 +21,8 @@ fn update_repository_metadata(scan_path: &Path, db: &sled::Db) {
for repository in discovered {
let relative = get_relative_path(scan_path, &repository);
- let id = Repository::open(db, relative)
- .map(|v| v.get().id)
- .unwrap_or_else(|| RepositoryId::new(db));
+ let id =
+ Repository::open(db, relative).map_or_else(|| RepositoryId::new(db), |v| v.get().id);
let name = relative.file_name().unwrap().to_string_lossy();
let description = std::fs::read(repository.join("description")).unwrap_or_default();
let description = Some(String::from_utf8_lossy(&description)).filter(|v| !v.is_empty());
@@ -40,7 +39,7 @@ fn update_repository_metadata(scan_path: &Path, db: &sled::Db) {
}
fn update_repository_reflog(scan_path: &Path, db: &sled::Db) {
- for (relative_path, db_repository) in Repository::fetch_all(&db) {
+ for (relative_path, db_repository) in Repository::fetch_all(db) {
let git_repository = git2::Repository::open(scan_path.join(&relative_path)).unwrap();
for reference in git_repository.references().unwrap() {
diff --git a/src/database/schema/commit.rs b/src/database/schema/commit.rs
@@ -27,12 +27,10 @@ impl<'a> Commit<'a> {
Self {
summary: commit
.summary_bytes()
- .map(String::from_utf8_lossy)
- .unwrap_or(Cow::Borrowed("")),
+ .map_or(Cow::Borrowed(""), String::from_utf8_lossy),
message: commit
.body_bytes()
- .map(String::from_utf8_lossy)
- .unwrap_or(Cow::Borrowed("")),
+ .map_or(Cow::Borrowed(""), String::from_utf8_lossy),
committer: committer.into(),
author: author.into(),
hash: CommitHash::Oid(commit.id()),
@@ -127,7 +125,7 @@ impl CommitTree {
// to box the value as well to get a stablederef...
let value = Box::new(value);
- Yoke::try_attach_to_cart(value, |data: &IVec| bincode::deserialize(&data)).unwrap()
+ Yoke::try_attach_to_cart(value, |data: &IVec| bincode::deserialize(data)).unwrap()
})
}
@@ -156,7 +154,7 @@ impl CommitTree {
let value = Box::new(value);
Ok(
- Yoke::try_attach_to_cart(value, |data: &IVec| bincode::deserialize(&data))
+ Yoke::try_attach_to_cart(value, |data: &IVec| bincode::deserialize(data))
.unwrap(),
)
})
diff --git a/src/database/schema/mod.rs b/src/database/schema/mod.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::module_name_repetitions)]
+
use sled::IVec;
use yoke::Yoke;
diff --git a/src/database/schema/prefixes.rs b/src/database/schema/prefixes.rs
@@ -30,7 +30,7 @@ impl TreePrefix {
);
prefixed.push(TreePrefix::Commit as u8);
prefixed.extend_from_slice(&repository.to_ne_bytes());
- prefixed.extend_from_slice(&reference);
+ prefixed.extend_from_slice(reference);
prefixed
}
diff --git a/src/database/schema/repository.rs b/src/database/schema/repository.rs
@@ -45,7 +45,7 @@ impl Repository<'_> {
let value = Box::new(value);
let value =
- Yoke::try_attach_to_cart(value, |data: &IVec| bincode::deserialize(&data))
+ Yoke::try_attach_to_cart(value, |data: &IVec| bincode::deserialize(data))
.unwrap();
(key, value)
@@ -72,7 +72,7 @@ impl Repository<'_> {
// to box the value as well to get a stablederef...
let value = Box::new(value);
- Yoke::try_attach_to_cart(value, |data: &IVec| bincode::deserialize(&data))
+ Yoke::try_attach_to_cart(value, |data: &IVec| bincode::deserialize(data))
})
.transpose()
.unwrap()
diff --git a/src/git.rs b/src/git.rs
@@ -86,7 +86,7 @@ impl OpenRepository {
};
if let Some(path) = path.as_ref() {
- let item = tree.get_path(&path).unwrap();
+ let item = tree.get_path(path).unwrap();
let object = item.to_object(&repo).unwrap();
if let Some(blob) = object.as_blob() {
@@ -95,7 +95,7 @@ impl OpenRepository {
let extension = path
.extension()
- .or(path.file_name())
+ .or_else(|| path.file_name())
.unwrap()
.to_string_lossy();
let content = format_file(blob.content(), &extension, &self.git.syntax_set);
@@ -498,7 +498,7 @@ fn fetch_diff_and_stats(
.as_str()
.unwrap()
.to_string();
- let diff_output = format_diff(&diff, &syntax_set);
+ let diff_output = format_diff(&diff, syntax_set);
(diff_output, diff_stats)
}
@@ -507,10 +507,10 @@ fn format_file(content: &[u8], extension: &str, syntax_set: &SyntaxSet) -> Strin
let content = std::str::from_utf8(content).unwrap();
let syntax = syntax_set
- .find_syntax_by_extension(&extension)
- .unwrap_or(syntax_set.find_syntax_plain_text());
+ .find_syntax_by_extension(extension)
+ .unwrap_or_else(|| syntax_set.find_syntax_plain_text());
let mut html_generator =
- ClassedHTMLGenerator::new_with_class_style(syntax, &syntax_set, ClassStyle::Spaced);
+ ClassedHTMLGenerator::new_with_class_style(syntax, syntax_set, ClassStyle::Spaced);
for line in LinesWithEndings::from(content) {
html_generator
@@ -544,7 +544,7 @@ fn format_diff(diff: &git2::Diff<'_>, syntax_set: &SyntaxSet) -> String {
let extension = if should_highlight_as_source {
let path = delta.new_file().path().unwrap();
path.extension()
- .or(path.file_name())
+ .or_else(|| path.file_name())
.unwrap()
.to_string_lossy()
} else {
@@ -552,9 +552,9 @@ fn format_diff(diff: &git2::Diff<'_>, syntax_set: &SyntaxSet) -> String {
};
let syntax = syntax_set
.find_syntax_by_extension(&extension)
- .unwrap_or(syntax_set.find_syntax_plain_text());
+ .unwrap_or_else(|| syntax_set.find_syntax_plain_text());
let mut html_generator =
- ClassedHTMLGenerator::new_with_class_style(syntax, &syntax_set, ClassStyle::Spaced);
+ ClassedHTMLGenerator::new_with_class_style(syntax, syntax_set, ClassStyle::Spaced);
html_generator
.parse_html_for_line_which_includes_newline(&line)
.unwrap();
diff --git a/src/main.rs b/src/main.rs
@@ -41,7 +41,7 @@ async fn main() {
move || loop {
info!("Running periodic index");
- crate::database::indexer::run_indexer(&db);
+ crate::database::indexer::run(&db);
info!("Finished periodic index");
std::thread::sleep(Duration::from_secs(300));
diff --git a/src/methods/filters.rs b/src/methods/filters.rs
@@ -1,3 +1,6 @@
+// sorry clippy, we don't have a choice. askama forces this on us
+#![allow(clippy::unnecessary_wraps, clippy::trivially_copy_pass_by_ref)]
+
pub fn timeago(s: time::OffsetDateTime) -> Result<String, askama::Error> {
Ok(timeago::Formatter::new().convert((time::OffsetDateTime::now_utc() - s).unsigned_abs()))
}
diff --git a/src/methods/index.rs b/src/methods/index.rs
@@ -17,8 +17,10 @@ pub struct View<'a> {
pub async fn handle(Extension(db): Extension<sled::Db>) -> Response {
let mut repositories: BTreeMap<Option<String>, Vec<&Repository<'_>>> = BTreeMap::new();
- let fetched = Repository::fetch_all(&db);
- for (k, v) in fetched.iter() {
+ let fetched = tokio::task::spawn_blocking(move || Repository::fetch_all(&db))
+ .await
+ .unwrap();
+ for (k, v) in &fetched {
// TODO: fixme
let mut split: Vec<_> = k.split('/').collect();
split.pop();
diff --git a/src/methods/repo.rs b/src/methods/repo.rs
@@ -16,6 +16,7 @@ use axum::{
use path_clean::PathClean;
use serde::Deserialize;
use tower::{util::BoxCloneService, Service};
+use yoke::Yoke;
use super::filters;
use crate::git::{DetailedTag, FileWithContent, PathDestination, Refs, TreeItem};
@@ -182,7 +183,7 @@ pub async fn handle_log(
None
};
- let commits = commits.iter().map(|v| v.get()).collect();
+ let commits = commits.iter().map(Yoke::get).collect();
into_response(&LogView {
repo,