~/selfhut

e4d868e23a8442b2022f381d8698ba31b8681dcd — Arthur Melton 6f431590 2 years ago
cargo fmt
M src/git/branches.rs => src/git/branches.rs +16 -11
@@ 1,5 1,5 @@

use crate::config::CONFIG;
use crate::git::commits::{Commits, get_commits};
use crate::git::commits::{get_commits, Commits};
use serde_derive::Serialize;

pub fn branches(repo_name: String) -> Option<Vec<Branch>> {

@@ 11,15 11,20 @@ pub fn branches(repo_name: String) -> Option<Vec<Branch>> {

        match i {
            Ok(x) => match x.0.name() {
                Ok(name) => match name {
                        Some(name) => branches.push(Branch {
                            branch: name.to_string(),
                            commit: match get_commits(repo_name.clone(), 1, Some(name.to_string()), None) {
                                Some(x) => x.first().cloned(),
                                None => None
                            },
                        }),
                        None => {}
                    }
                    Some(name) => branches.push(Branch {
                        branch: name.to_string(),
                        commit: match get_commits(
                            repo_name.clone(),
                            1,
                            Some(name.to_string()),
                            None,
                        ) {
                            Some(x) => x.first().cloned(),
                            None => None,
                        },
                    }),
                    None => {}
                },
                Err(_) => {}
            },
            Err(_) => {}

@@ 31,5 36,5 @@ pub fn branches(repo_name: String) -> Option<Vec<Branch>> {

#[derive(Serialize, Clone)]
pub struct Branch {
    branch: String,
    commit: Option<Commits>
    commit: Option<Commits>,
}

M src/git/commits.rs => src/git/commits.rs +3 -3
@@ 25,7 25,7 @@ pub fn get_commits(

                    Err(_) => {
                        let mut tag = None;
                        let tag_name = id.as_bytes();
                        let _ = repo.tag_foreach(|x,y| {
                        let _ = repo.tag_foreach(|x, y| {
                            if &y[10..] == tag_name {
                                tag = Some(x);
                                return false;

@@ 37,10 37,10 @@ pub fn get_commits(

                };
                match oid {
                    Some(x) => revwalk.push(x).ok()?,
                    None => revwalk.push_head().ok()?
                    None => revwalk.push_head().ok()?,
                }
            }
        }
        },
        None => revwalk.push_head().ok()?,
    }
    let mut commits = Vec::new();

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

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

M src/git/tag.rs => src/git/tag.rs +13 -8
@@ 2,35 2,40 @@ use crate::config::CONFIG;

use crate::git::commits::{get_commits, Commits};
use serde_derive::Serialize;

pub fn get_tag(repo_name: String, amount: usize, after: usize, name: Option<String>) -> Option<(Vec<Tags>, usize)> {
pub fn get_tag(
    repo_name: String,
    amount: usize,
    after: usize,
    name: Option<String>,
) -> Option<(Vec<Tags>, usize)> {
    let mut repo_path = CONFIG.git_location.clone();
    repo_path.push(format!("{}.git", repo_name));
    let repo = git2::Repository::open(repo_path).ok()?;
    let mut tags = Vec::new();
    let total = repo.tag_names(None).ok()?.len();
    let mut i = total-1;
    let _ = repo.tag_foreach(|x,y| {
    let mut i = total - 1;
    let _ = repo.tag_foreach(|x, y| {
        if (name.is_some() && name.as_ref().unwrap().as_bytes() == &y[10..]) || name.is_none() {
            if i >= after && (total < amount + after ||  i < amount - after) {
            if i >= after && (total < amount + after || i < amount - after) {
                match get_commits(repo_name.clone(), 1, Some(x.to_string()), None) {
                    Some(z) => match z.first() {
                        Some(z) => tags.push(Tags {
                            commit: z.clone(),
                            body: match repo.find_tag(x) {
                                Ok(x) => x.message().unwrap_or("").to_string(),
                                Err(_) => "".to_string()
                                Err(_) => "".to_string(),
                            },
                            name: std::str::from_utf8(&y[10..]).unwrap_or("").to_string()
                            name: std::str::from_utf8(&y[10..]).unwrap_or("").to_string(),
                        }),
                        None => {}
                    },
                    None => {}
                }
            }
            if i < after+1 {
            if i < after + 1 {
                return false;
            }
            i-=1;
            i -= 1;
        }
        true
    });

M src/main.rs => src/main.rs +1 -1
@@ 15,9 15,9 @@ use crate::repository::blame;

use crate::repository::commit;
use crate::repository::log;
use crate::repository::raw;
use crate::repository::refs;
use crate::repository::summary;
use crate::repository::tree;
use crate::repository::refs;
use crate::utils::own_pathbuf::PathBufWithDotfiles;
use rocket_dyn_templates::Template;


M src/repository/mod.rs => src/repository/mod.rs +1 -1
@@ 2,6 2,6 @@ pub mod blame;

pub mod commit;
pub mod log;
pub mod raw;
pub mod refs;
pub mod summary;
pub mod tree;
pub mod refs;

M src/repository/refs.rs => src/repository/refs.rs +2 -3
@@ 1,17 1,16 @@

use crate::config::CONFIG;
use crate::git::branches::branches;


use crate::git::tag::get_tag;
use crate::utils::repo_config::repo_config;
use rocket_dyn_templates::{context, Template};

#[get("/<repo>/refs?<page>", rank = 2)]
pub fn refs(repo: String, page: Option<usize>) -> Option<Template> {
    let mut tags = get_tag(repo.clone(), 10, (page.unwrap_or(1)-1)*10, None);
    let mut tags = get_tag(repo.clone(), 10, (page.unwrap_or(1) - 1) * 10, None);
    let mut pages = 1;
    match tags {
        Some(ref mut x) => pages = x.1/10+1,
        Some(ref mut x) => pages = x.1 / 10 + 1,
        None => {}
    }
    Some(Template::render(