M src/git/blame.rs => src/git/blame.rs +13 -6
@@ 1,8 1,8 @@
use crate::config::CONFIG;
-use std::path::Path;
-use crate::git::commits::{Commits, get_commits};
+use crate::git::commits::{get_commits, Commits};
use serde_derive::Serialize;
use std::ops::Range;
+use std::path::Path;
pub fn blame<'a>(repo: String, branch: String, path: String) -> Option<Vec<Blame>> {
if branch.contains(":") {
@@ 15,9 15,16 @@ pub fn blame<'a>(repo: String, branch: String, path: String) -> Option<Vec<Blame
let blame = repo.blame_file(Path::new(&path), None).ok()?;
let mut blames = Vec::new();
for i in blame.iter() {
- blames.push( Blame {
- commit: (*get_commits(repo_clone.clone(), 1, Some(i.final_commit_id().to_string()), None)?.first()?).clone(),
- lines: (0..i.lines_in_hunk()-1).collect()
+ blames.push(Blame {
+ commit: (*get_commits(
+ repo_clone.clone(),
+ 1,
+ Some(i.final_commit_id().to_string()),
+ None,
+ )?
+ .first()?)
+ .clone(),
+ lines: (0..i.lines_in_hunk() - 1).collect(),
});
}
Some(blames)
@@ 26,5 33,5 @@ pub fn blame<'a>(repo: String, branch: String, path: String) -> Option<Vec<Blame
#[derive(Serialize, Clone)]
pub struct Blame {
commit: Commits,
- lines: Vec<usize>
+ lines: Vec<usize>,
}
M src/git/commits.rs => src/git/commits.rs +0 -1
@@ 4,7 4,6 @@ use chrono::{Duration, Utc};
use chrono_humanize::HumanTime;
use serde_derive::Serialize;
-
pub fn get_commits(
repo_name: String,
ammount: usize,
M src/git/mod.rs => src/git/mod.rs +1 -1
@@ 1,7 1,7 @@
+pub mod blame;
pub mod commits;
pub mod diffs;
pub mod file;
pub mod main_branch;
pub mod repos;
pub mod tag;
-pub mod blame;
M src/main.rs => src/main.rs +1 -1
@@ 11,11 11,11 @@ use utils::config;
use rocket::fs::relative;
use std::path::Path;
+use crate::repository::blame;
use crate::repository::log;
use crate::repository::raw;
use crate::repository::summary;
use crate::repository::tree;
-use crate::repository::blame;
use crate::utils::own_pathbuf::PathBufWithDotfiles;
use rocket_dyn_templates::Template;
M src/repository/blame.rs => src/repository/blame.rs +13 -10
@@ 1,20 1,24 @@
use crate::config::CONFIG;
-use crate::git::file::files;
-use rocket_dyn_templates::{context, Template};
+use crate::git::blame::blame;
use crate::git::commits::get_commits;
+use crate::git::file::file;
+use crate::git::file::files;
use crate::utils::repo_config::repo_config;
-use syntect::html::highlighted_html_for_string;
+use crate::PathBufWithDotfiles;
+use rocket_dyn_templates::{context, Template};
+use std::ffi::OsStr;
use std::path::Path;
use syntect::highlighting::ThemeSet;
+use syntect::html::highlighted_html_for_string;
use syntect::parsing::SyntaxSet;
-use crate::git::file::file;
-use crate::git::blame::blame;
-use crate::PathBufWithDotfiles;
-use std::ffi::OsStr;
#[get("/<repo>/blame/<branch>/<location..>", rank = 2)]
pub fn blames(repo: String, branch: String, location: PathBufWithDotfiles) -> Option<Template> {
- let blames = blame(repo.clone(), branch.clone(), location.get().display().to_string());
+ let blames = blame(
+ repo.clone(),
+ branch.clone(),
+ location.get().display().to_string(),
+ );
let file = file(
repo.clone(),
branch.clone(),
@@ 37,8 41,7 @@ pub fn blames(repo: String, branch: String, location: PathBufWithDotfiles) -> Op
let s = file.1.as_ref().unwrap();
lines = (1..s.lines().count() + 1).collect();
content =
- highlighted_html_for_string(s, &ps, syntax, &ts.themes["Solarized (light)"])
- .ok()?
+ highlighted_html_for_string(s, &ps, syntax, &ts.themes["Solarized (light)"]).ok()?
}
Some(Template::render(
"repository/blame",
M src/repository/log.rs => src/repository/log.rs +0 -7
@@ 6,13 6,6 @@ use crate::utils::repo_config::repo_config;
use crate::PathBufWithDotfiles;
use rocket_dyn_templates::{context, Template};
-
-
-
-
-
-
-
#[get("/<repo>/log?<from>", rank = 2)]
pub fn log_main(repo: String, from: Option<String>) -> Option<Template> {
let main_branch = main_branch(repo.clone())?;
M src/repository/mod.rs => src/repository/mod.rs +1 -1
@@ 1,5 1,5 @@
+pub mod blame;
pub mod log;
pub mod raw;
pub mod summary;
pub mod tree;
-pub mod blame;