🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2022-07-18 0:39:07.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2022-07-18 0:39:07.0 +01:00:00
commit
81056c93b94bbe3800ccca6354ddf618ea384527 [patch]
tree
1e8735772f8c3c26bdf21d1420aec6739bd4df50
parent
7ac6770f934b7304460d43b14daab9ba473cd266
download
81056c93b94bbe3800ccca6354ddf618ea384527.tar.gz

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(-)

diff --git a/src/git.rs b/src/git.rs
index 401d1ce..65a78f8 100644
--- a/src/git.rs
+++ a/src/git.rs
@@ -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();
diff --git a/src/main.rs b/src/main.rs
index 1f6a0f7..06d08b0 100644
--- a/src/main.rs
+++ a/src/main.rs
@@ -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));
diff --git a/src/database/indexer.rs b/src/database/indexer.rs
index 2363a6d..29ff671 100644
--- a/src/database/indexer.rs
+++ a/src/database/indexer.rs
@@ -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() {
diff --git a/src/methods/filters.rs b/src/methods/filters.rs
index 58df841..95b52a1 100644
--- a/src/methods/filters.rs
+++ a/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
index dcf7c67..7c92cd9 100644
--- a/src/methods/index.rs
+++ a/src/methods/index.rs
@@ -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 {
        // TODO: fixme
        let mut split: Vec<_> = k.split('/').collect();
        split.pop();
diff --git a/src/methods/repo.rs b/src/methods/repo.rs
index 6964b03..09f0744 100644
--- a/src/methods/repo.rs
+++ a/src/methods/repo.rs
@@ -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,
diff --git a/src/database/schema/commit.rs b/src/database/schema/commit.rs
index 5dfb258..a2ad226 100644
--- a/src/database/schema/commit.rs
+++ a/src/database/schema/commit.rs
@@ -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 @@
            // 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 @@
                    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
index 16364b9..2f51a8b 100644
--- a/src/database/schema/mod.rs
+++ a/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
index 4473e4a..a1e2e90 100644
--- a/src/database/schema/prefixes.rs
+++ a/src/database/schema/prefixes.rs
@@ -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
    }
diff --git a/src/database/schema/repository.rs b/src/database/schema/repository.rs
index 1889418..b8e9046 100644
--- a/src/database/schema/repository.rs
+++ a/src/database/schema/repository.rs
@@ -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 @@
                // 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()