~/selfhut

392c317acb282764db05ae381b7f20b9abae5551 — Arthur Melton 76d4fa6d 2 years ago
format
5 files changed, 57 insertions(+), 55 deletions(-)

M src/git/commits.rs
M src/git/diffs.rs
M src/git/mod.rs
M src/repository/log.rs
M src/repository/mod.rs
M src/git/commits.rs => src/git/commits.rs +2 -2
@@ 1,9 1,9 @@

use crate::config::CONFIG;
use crate::git::diffs::diffs;
use chrono::{Duration, Utc};
use chrono_humanize::HumanTime;
use serde_derive::Serialize;
use std::borrow::Cow;
use crate::git::diffs::diffs;

pub fn get_commits(
    repo_name: String,

@@ 70,7 70,7 @@ pub fn get_commits(

                            )
                        },
                        time_relitive: HumanTime::from(time).to_string(),
                        commit_body: repo_commit.body().unwrap_or("").to_string()
                        commit_body: repo_commit.body().unwrap_or("").to_string(),
                    });
                    i += 1;
                }

M src/git/diffs.rs => src/git/diffs.rs +7 -13
@@ 1,23 1,17 @@

pub fn diffs<'a>(commit: git2::Commit<'a>, repo: &'a git2::Repository) -> Option<git2::Diff<'a>> {    
pub fn diffs<'a>(commit: git2::Commit<'a>, repo: &'a git2::Repository) -> Option<git2::Diff<'a>> {
    match commit.tree() {
        Ok(tree) => match commit.parent(0) {
            Ok(parent) => match parent.tree() {
                Ok(parent_tree) => {
                    match repo.diff_tree_to_tree(
                        Some(&tree),
                        Some(&parent_tree),
                        None,
                    ) {
                        Ok(diff) => {
                            Some(diff)
                        }
                        Err(_) => None
                    match repo.diff_tree_to_tree(Some(&tree), Some(&parent_tree), None) {
                        Ok(diff) => Some(diff),
                        Err(_) => None,
                    }
                }
                Err(_) => None
                Err(_) => None,
            },
            Err(_) => None
            Err(_) => None,
        },
        Err(_) => None
        Err(_) => None,
    }
}

M src/git/mod.rs => src/git/mod.rs +1 -1
@@ 1,6 1,6 @@

pub mod commits;
pub mod diffs;
pub mod file;
pub mod main_branch;
pub mod repos;
pub mod tag;
pub mod diffs;

M src/repository/log.rs => src/repository/log.rs +46 -38
@@ 1,19 1,19 @@

use rocket_dyn_templates::{context, Template};
use crate::config::CONFIG;
use crate::utils::repo_config::repo_config;
use crate::git::commits::get_commits;
use crate::git::file::{file, files};
use crate::git::main_branch::main_branch;
use crate::git::file::{files, file};
use crate::utils::repo_config::repo_config;
use crate::PathBufWithDotfiles;
use rocket_dyn_templates::{context, Template};
use std::ffi::OsStr;
use std::path::Path;
use syntect::easy::HighlightLines;
use syntect::highlighting::{Style, ThemeSet};
use syntect::html::highlighted_html_for_string;
use syntect::parsing::SyntaxSet;
use syntect::highlighting::{ThemeSet, Style};
use syntect::util::LinesWithEndings;
use syntect::html::highlighted_html_for_string;
use std::path::Path;

#[get("/<repo>/log?<from>", rank=2)]
#[get("/<repo>/log?<from>", rank = 2)]
pub fn log_main(repo: String, from: Option<String>) -> Option<Template> {
    let main_branch = main_branch(repo.clone())?;
    let commits = get_commits(repo.clone(), 21, from, None);

@@ 21,12 21,11 @@ pub fn log_main(repo: String, from: Option<String>) -> Option<Template> {

        Some(ref commits) => {
            if commits.len() == 21 {
                Some(commits[19].commit_hash.clone())
            }
            else {
            } else {
                None
            }
        },
        None => None
        }
        None => None,
    };
    let commits = match commits {
        Some(mut commits) => {

@@ 34,40 33,49 @@ pub fn log_main(repo: String, from: Option<String>) -> Option<Template> {

                commits.pop();
            }
            Some(commits)
        },
        None => None
        }
        None => None,
    };
    Some(Template::render(
            "repository/log",
            context! {
                title: format!("/ :: {}", repo.clone()),
                repo: repo.clone(),
                config: repo_config(repo.clone()),
                domain: CONFIG.domain.to_string(),
                active: "log",
                commits,
                branch: main_branch.clone(),
                current_dir_file: "/",
                current_dir: "/",
                payment: CONFIG.payment_link.clone(),
                last_commit,
            }
        ))
        "repository/log",
        context! {
            title: format!("/ :: {}", repo.clone()),
            repo: repo.clone(),
            config: repo_config(repo.clone()),
            domain: CONFIG.domain.to_string(),
            active: "log",
            commits,
            branch: main_branch.clone(),
            current_dir_file: "/",
            current_dir: "/",
            payment: CONFIG.payment_link.clone(),
            last_commit,
        },
    ))
}

#[get("/<repo>/log/<branch>/<location..>?<from>", rank=2)]
pub fn log(repo: String, branch: String, location: PathBufWithDotfiles, from: Option<String>) -> Option<Template> {
    let commits = get_commits(repo.clone(), 21, from, Some(format!("{}", location.get().display()).replace("//", "/")));
#[get("/<repo>/log/<branch>/<location..>?<from>", rank = 2)]
pub fn log(
    repo: String,
    branch: String,
    location: PathBufWithDotfiles,
    from: Option<String>,
) -> Option<Template> {
    let commits = get_commits(
        repo.clone(),
        21,
        from,
        Some(format!("{}", location.get().display()).replace("//", "/")),
    );
    let last_commit = match commits {
        Some(ref commits) => {
            if commits.len() == 21 {
                Some(commits[19].commit_hash.clone())
            }
            else {
            } else {
                None
            }
        },
        None => None
        }
        None => None,
    };
    let commits = match commits {
        Some(mut commits) => {

@@ 75,8 83,8 @@ pub fn log(repo: String, branch: String, location: PathBufWithDotfiles, from: Op

                commits.pop();
            }
            Some(commits)
        },
        None => None
        }
        None => None,
    };
    Some(Template::render(
        "repository/log",

@@ 92,6 100,6 @@ pub fn log(repo: String, branch: String, location: PathBufWithDotfiles, from: Op

            current_dir: format!("/{}", location.get().display()),
            payment: CONFIG.payment_link.clone(),
            last_commit,
        }
        },
    ))
}

M src/repository/mod.rs => src/repository/mod.rs +1 -1
@@ 1,4 1,4 @@

pub mod log;
pub mod raw;
pub mod summary;
pub mod tree;
pub mod log;