Skip to content

Commit

Permalink
Minor code cleanup (#51)
Browse files Browse the repository at this point in the history
* Remove unnecessary struct

* Remove unnecessary clippy suppession

* Remove unused struct

* Move SortCommit to git module from graph module
  • Loading branch information
lusingander committed Sep 16, 2024
1 parent 4225309 commit ab6fcff
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 69 deletions.
8 changes: 6 additions & 2 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -98,6 +96,12 @@ pub enum Head {
Detached { target: CommitHash },
}

#[derive(Debug, Clone, Copy)]
pub enum SortCommit {
Chronological,
Topological,
}

type CommitMap = HashMap<CommitHash, Commit>;
type CommitsMap = HashMap<CommitHash, Vec<CommitHash>>;

Expand Down
12 changes: 0 additions & 12 deletions src/graph/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
15 changes: 2 additions & 13 deletions src/graph/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ enum CommitOrderType {
Topo,
}

impl From<CommitOrderType> for graph::SortCommit {
impl From<CommitOrderType> 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,
}
}
}
Expand Down Expand Up @@ -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,
Expand Down
74 changes: 37 additions & 37 deletions tests/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -1059,11 +1059,11 @@ fn parse_date(date: &str) -> DateTime<Utc> {

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 }
}
}
Expand Down

0 comments on commit ab6fcff

Please sign in to comment.