Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 37 additions & 11 deletions src/explorer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct GitExplorer {
stop_condition_i: usize,
stop_conditions: Vec<Option<BranchData>>,
nodes_len: usize,
abort: bool,
Copy link
Owner Author

@KarlHeitmann KarlHeitmann Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created abort and limit_stack attributes created in GitExplorer struct, the idea is to remove the arguments here. Separate responsibilities, they are not necessary to be as arguments

limit_stack: Option<usize>,
}

impl<'a> GitExplorer {
Expand Down Expand Up @@ -69,6 +71,8 @@ impl<'a> GitExplorer {
};

Self {
abort: false,
limit_stack: Some(500),
stop_condition_i: 0,
repo,
root_oid,
Expand Down Expand Up @@ -169,6 +173,28 @@ impl<'a> GitExplorer {
}
// let branches = branches.map(|b| BranchData::new(b)).collect();
self.paint_commit_track(self.repo.head().unwrap().peel_to_commit().unwrap(), branches)

/*
Copy link
Owner Author

@KarlHeitmann KarlHeitmann Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all the attempts I made to fix the error[0502] I've got when adding the abort and limit_stack attributes to GitExplorer struct. (lines 177 to 197)

// self.paint_commit_track(self.repo.head().unwrap().peel_to_commit().unwrap(), self.repo.branches(Some(BranchType::Local)).unwrap())
let x = self.paint_commit_track(self.repo.head().unwrap().peel_to_commit().unwrap(), self.repo.branches(Some(BranchType::Local)).unwrap());
x
*/

/*
// let repo = &self.repo;
let branches = self.repo
.branches(Some(BranchType::Local))
.unwrap();
let head_data = self.repo.head().unwrap().peel_to_commit().unwrap().clone();
self.paint_commit_track(head_data, branches)
*/
/*
let mut repo = &mut self.repo;
// let repo = &self.repo;
let mut branches = repo.branches(Some(BranchType::Local)).unwrap();
let mut head_data = repo.head().unwrap().peel_to_commit().unwrap().clone();
self.paint_commit_track(head_data, branches)
*/
}
};
self.nodes_len = nodes.len();
Expand Down Expand Up @@ -204,23 +230,23 @@ impl<'a> GitExplorer {
}

fn paint_branch(
&self,
&mut self,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed immutable reference to self to mutable reference to self. I also need to change mutable reference to self in paint_commit_track

mut commits: Vec<Commit>,
mut output: Vec<GraphNode>,
limit_stack: Option<usize>,
branches: Vec<BranchData>,
abort: bool) -> Vec<GraphNode> {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limit_stack and abort attributes are not necessary as arguments. I can use them from the GitExplorer struct if I define them as attributes of that struct.

branches: Vec<BranchData>,) -> Vec<GraphNode> {
// fn paint_branch(mut commits: Vec<Commit>, mut output: Vec<(String, Oid)>, limit_stack: Option<usize>) -> Vec<(String, Oid)> {
// let debug_data: Vec<String> = commits.clone().into_iter().map(|c| short_id(c.id())).collect();
// println!("{:?}", debug_data);
let l = commits.len();
let mut status = Status::Same;

let (abort, limit_stack) = match limit_stack {
Some(limit_stack) => { (abort || l == 0 || limit_stack == 0, Some(limit_stack - 1))},
None => {(abort || l == 0, None)}
let (abort, limit_stack) = match self.limit_stack {
Some(limit_stack) => { (self.abort || l == 0 || limit_stack == 0, Some(limit_stack - 1))},
None => {(self.abort || l == 0, None)}
};

self.limit_stack = limit_stack;

if abort { return vec![] }

let max_index = self.find_max_index(commits.clone().into_iter().map(|c| c.time()).collect());
Expand Down Expand Up @@ -304,26 +330,26 @@ impl<'a> GitExplorer {
}

let stop_condition = self.stop_conditions.get(self.stop_condition_i).unwrap();
let abort_next = match stop_condition {
self.abort = match stop_condition {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will need to mutate GitExplorer instance, and this cascades the error until reaching this point

Some(stop_condition) => {
stop_condition.oid() == commit_max.id()
}
_ => false
};

let vec_str = self.paint_branch(dedup.to_vec(), vec![], limit_stack, branches, abort_next);
let vec_str = self.paint_branch(dedup.to_vec(), vec![], branches);

output.push(GraphNode { grapheme: paint_string, oid: commit_max.id(), branch_shorthand: shorthand, summary: commit_max.summary().unwrap().to_string() });

[output, vec_str].concat()
}

pub fn paint_commit_track(&self, commit: Commit, branches: Vec<BranchData>) -> Vec<GraphNode> {
pub fn paint_commit_track(&mut self, commit: Commit, branches: Vec<BranchData>) -> Vec<GraphNode> {
// let limit_stack = 1000; // Works fine
let limit_stack = 500; // Works fine
// let limit_stack = 10000; // Works, but it is unhandeable :/
// paint_branch(vec![commit], vec![], Some(limit_stack), branches)
self.paint_branch(vec![commit], vec![], Some(limit_stack), branches, false)
self.paint_branch(vec![commit], vec![], branches)
}

}
Expand Down