Clippy housekeeping
Diff
src/git.rs | 18 +++++++++++-------
src/main.rs | 2 +-
src/database/indexer.rs | 13 +++++++------
src/methods/filters.rs | 3 +++
src/methods/index.rs | 6 ++++--
src/methods/repo.rs | 3 ++-
src/database/schema/commit.rs | 10 ++++------
src/database/schema/mod.rs | 2 ++
src/database/schema/prefixes.rs | 2 +-
src/database/schema/repository.rs | 4 ++--
10 files changed, 34 insertions(+), 29 deletions(-)
@@ -86,7 +86,7 @@
};
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 @@
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 @@
.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 @@
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 @@
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 @@
};
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();
@@ -41,7 +41,7 @@
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));
@@ -8,10 +8,10 @@
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 @@
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_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() {
@@ -1,3 +1,6 @@
#![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()))
}
@@ -17,8 +17,10 @@
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 {
let mut split: Vec<_> = k.split('/').collect();
split.pop();
@@ -16,6 +16,7 @@
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 @@
None
};
let commits = commits.iter().map(|v| v.get()).collect();
let commits = commits.iter().map(Yoke::get).collect();
into_response(&LogView {
repo,
@@ -27,12 +27,10 @@
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 @@
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 @@
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(),
)
})
@@ -1,3 +1,5 @@
#![allow(clippy::module_name_repetitions)]
use sled::IVec;
use yoke::Yoke;
@@ -30,7 +30,7 @@
);
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
}
@@ -45,7 +45,7 @@
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 @@
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()