From ab6fcffd553aaca6b83823b0380e8058c7b35b1e Mon Sep 17 00:00:00 2001 From: Kyosuke Fujimoto <31386431+lusingander@users.noreply.github.com> Date: Mon, 16 Sep 2024 09:36:11 +0900 Subject: [PATCH] Minor code cleanup (#51) * Remove unnecessary struct * Remove unnecessary clippy suppession * Remove unused struct * Move SortCommit to git module from graph module --- src/git.rs | 8 +++-- src/graph/calc.rs | 12 -------- src/graph/image.rs | 15 ++-------- src/lib.rs | 9 +++--- tests/graph.rs | 74 +++++++++++++++++++++++----------------------- 5 files changed, 49 insertions(+), 69 deletions(-) diff --git a/src/git.rs b/src/git.rs index e2c6ec6..037cc88 100644 --- a/src/git.rs +++ b/src/git.rs @@ -8,8 +8,6 @@ use std::{ use chrono::{DateTime, FixedOffset}; -use crate::graph::SortCommit; - #[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct CommitHash(String); @@ -98,6 +96,12 @@ pub enum Head { Detached { target: CommitHash }, } +#[derive(Debug, Clone, Copy)] +pub enum SortCommit { + Chronological, + Topological, +} + type CommitMap = HashMap; type CommitsMap = HashMap>; diff --git a/src/graph/calc.rs b/src/graph/calc.rs index f9faa88..b2b8413 100644 --- a/src/graph/calc.rs +++ b/src/graph/calc.rs @@ -43,17 +43,6 @@ pub enum EdgeType { LeftBottom, // ╰ } -#[derive(Debug, Clone, Copy)] -pub struct CalcGraphOptions { - pub sort: SortCommit, -} - -#[derive(Debug, Clone, Copy)] -pub enum SortCommit { - Chronological, - Topological, -} - pub fn calc_graph(repository: &Repository) -> Graph<'_> { let commits = repository.all_commits(); @@ -285,7 +274,6 @@ fn calc_edges( let mut new_pos_x = pos_x; let mut skip_judge_overlap = true; - #[allow(clippy::needless_range_loop)] for y in (child_pos_y + 1)..pos_y { let processing_commit_pos_x = commit_pos_map.get(&commits[y].commit_hash).unwrap().0; diff --git a/src/graph/image.rs b/src/graph/image.rs index 4bee140..f509b64 100644 --- a/src/graph/image.rs +++ b/src/graph/image.rs @@ -27,12 +27,12 @@ pub struct GraphImageManager<'a> { impl<'a> GraphImageManager<'a> { pub fn new( graph: &'a Graph, - options: GraphImageOptions, + color_set: &ColorSet, cell_width_type: CellWidthType, image_protocol: ImageProtocol, preload: bool, ) -> Self { - let image_params = ImageParams::new(&options.color_set, cell_width_type); + let image_params = ImageParams::new(color_set, cell_width_type); let drawing_pixels = DrawingPixels::new(&image_params); let mut m = GraphImageManager { @@ -172,17 +172,6 @@ impl ImageParams { } } -#[derive(Debug, Clone)] -pub struct GraphImageOptions { - color_set: ColorSet, -} - -impl GraphImageOptions { - pub fn new(color_set: ColorSet) -> Self { - Self { color_set } - } -} - fn build_single_graph_row_image( graph: &Graph<'_>, image_params: &ImageParams, diff --git a/src/lib.rs b/src/lib.rs index c7fe44e..3987a19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -63,11 +63,11 @@ enum CommitOrderType { Topo, } -impl From for graph::SortCommit { +impl From for git::SortCommit { fn from(order: CommitOrderType) -> Self { match order { - CommitOrderType::Chrono => graph::SortCommit::Chronological, - CommitOrderType::Topo => graph::SortCommit::Topological, + CommitOrderType::Chrono => git::SortCommit::Chronological, + CommitOrderType::Topo => git::SortCommit::Topological, } } } @@ -103,10 +103,9 @@ pub fn run() -> std::io::Result<()> { let cell_width_type = check::decide_cell_width_type(&graph, args.graph_width.map(|w| w.into()))?; - let graph_image_options = graph::GraphImageOptions::new(color_set.clone()); let graph_image_manager = GraphImageManager::new( &graph, - graph_image_options, + &color_set, cell_width_type, image_protocol, args.preload, diff --git a/tests/graph.rs b/tests/graph.rs index 7f1d514..0d8ad35 100644 --- a/tests/graph.rs +++ b/tests/graph.rs @@ -30,7 +30,7 @@ fn straight_001() -> TestResult { let options = &[GenerateGraphOption::new( "straight_001", - graph::SortCommit::Chronological, + git::SortCommit::Chronological, )]; copy_git_dir(repo_path, "straight_001"); @@ -98,8 +98,8 @@ fn branch_001() -> TestResult { git.log(); let options = &[ - GenerateGraphOption::new("branch_001_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("branch_001_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("branch_001_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("branch_001_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "branch_001"); @@ -166,8 +166,8 @@ fn branch_002() -> TestResult { git.log(); let options = &[ - GenerateGraphOption::new("branch_002_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("branch_002_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("branch_002_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("branch_002_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "branch_002"); @@ -212,8 +212,8 @@ fn branch_003() -> TestResult { git.log(); let options = &[ - GenerateGraphOption::new("branch_003_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("branch_003_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("branch_003_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("branch_003_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "branch_003"); @@ -293,8 +293,8 @@ fn branch_004() -> TestResult { git.log(); let options = &[ - GenerateGraphOption::new("branch_004_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("branch_004_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("branch_004_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("branch_004_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "branch_004"); @@ -341,8 +341,8 @@ fn branch_005() -> TestResult { git.log(); let options = &[ - GenerateGraphOption::new("branch_005_chrono", serie::graph::SortCommit::Chronological), - GenerateGraphOption::new("branch_005_topo", serie::graph::SortCommit::Topological), + GenerateGraphOption::new("branch_005_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("branch_005_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "branch_005"); @@ -408,8 +408,8 @@ fn merge_001() -> TestResult { git.log(); let options = &[ - GenerateGraphOption::new("merge_001_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("merge_001_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("merge_001_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("merge_001_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "merge_001"); @@ -457,8 +457,8 @@ fn merge_002() -> TestResult { git.log(); let options = &[ - GenerateGraphOption::new("merge_002_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("merge_002_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("merge_002_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("merge_002_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "merge_002"); @@ -508,8 +508,8 @@ fn merge_003() -> TestResult { git.log(); let options = &[ - GenerateGraphOption::new("merge_003_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("merge_003_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("merge_003_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("merge_003_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "merge_003"); @@ -571,8 +571,8 @@ fn merge_004() -> TestResult { git.log(); let options = &[ - GenerateGraphOption::new("merge_004_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("merge_004_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("merge_004_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("merge_004_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "merge_004"); @@ -640,8 +640,8 @@ fn merge_005() -> TestResult { git.log(); let options = &[ - GenerateGraphOption::new("merge_005_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("merge_005_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("merge_005_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("merge_005_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "merge_005"); @@ -686,8 +686,8 @@ fn stash_001() -> TestResult { git.commit("007", "2024-01-10"); let options = &[ - GenerateGraphOption::new("stash_001_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("stash_001_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("stash_001_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("stash_001_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "stash_001"); @@ -729,8 +729,8 @@ fn stash_002() -> TestResult { git.stash("2024-01-09"); let options = &[ - GenerateGraphOption::new("stash_002_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("stash_002_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("stash_002_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("stash_002_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "stash_002"); @@ -765,8 +765,8 @@ fn stash_003() -> TestResult { git.branch_d("10"); let options = &[ - GenerateGraphOption::new("stash_003_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("stash_003_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("stash_003_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("stash_003_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "stash_003"); @@ -797,8 +797,8 @@ fn stash_004() -> TestResult { git.commit("003", "2024-03-01"); let options = &[ - GenerateGraphOption::new("stash_004_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("stash_004_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("stash_004_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("stash_004_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "stash_004"); @@ -840,8 +840,8 @@ fn orphan_001() -> TestResult { git.log(); let options = &[ - GenerateGraphOption::new("orphan_001_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("orphan_001_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("orphan_001_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("orphan_001_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "orphan_001"); @@ -883,8 +883,8 @@ fn orphan_002() -> TestResult { git.log(); let options = &[ - GenerateGraphOption::new("orphan_002_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("orphan_002_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("orphan_002_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("orphan_002_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "orphan_002"); @@ -966,8 +966,8 @@ fn complex_001() -> TestResult { git.log(); let options = &[ - GenerateGraphOption::new("complex_001_chrono", graph::SortCommit::Chronological), - GenerateGraphOption::new("complex_001_topo", graph::SortCommit::Topological), + GenerateGraphOption::new("complex_001_chrono", git::SortCommit::Chronological), + GenerateGraphOption::new("complex_001_topo", git::SortCommit::Topological), ]; copy_git_dir(repo_path, "complex_001"); @@ -1059,11 +1059,11 @@ fn parse_date(date: &str) -> DateTime { struct GenerateGraphOption<'a> { output_name: &'a str, - sort: graph::SortCommit, + sort: git::SortCommit, } impl GenerateGraphOption<'_> { - fn new(output_name: &str, sort: graph::SortCommit) -> GenerateGraphOption { + fn new(output_name: &str, sort: git::SortCommit) -> GenerateGraphOption { GenerateGraphOption { output_name, sort } } }