pub struct GitGraph {
pub repository: Repository,
pub commits: Vec<CommitInfo>,
pub indices: HashMap<Oid, usize>,
pub all_branches: Vec<BranchInfo>,
pub head: HeadInfo,
}Expand description
Represents a git history graph.
Fields§
§repository: Repository§commits: Vec<CommitInfo>§indices: HashMap<Oid, usize>Mapping from commit id to index in commits
all_branches: Vec<BranchInfo>All detected branches and tags, including merged and deleted
head: HeadInfoThe current HEAD
Implementations§
Source§impl GitGraph
impl GitGraph
Sourcepub fn new(
repository: Repository,
settings: &Settings,
start_point: Option<String>,
max_count: Option<usize>,
) -> Result<Self, String>
pub fn new( repository: Repository, settings: &Settings, start_point: Option<String>, max_count: Option<usize>, ) -> Result<Self, String>
Generate a branch graph for a repository
§Overview
To generate a graph, GitGraph::new() will read the repository and assign every commit to a single branch.
It takes the following steps to generate the graph
- Identify branches
- Sort branches by persistence
- Trace branches to commits
- Filtering and indexing
§Identify branches
Local and remote git-branches and tags are used as candidates for branches. A branch can be identified by a merge commit, even though no current git-branch refers to it.
§Sort branches by persistence
Each branch is assigned a persistence which can be configured by settings. Think of persistence as z-order where lower values take preceedence. TODO Merge branch
§Trace branches to commits
The branches now get to pick their commits, in order of persistence. Each branch starts with a head, and follow the primary parent while it is available. It stops when the parent is a commit already assigned to a branch. TODO Duplicate branch names TODO Handle visual artifacts on merge
§Filtering and indexing
Commits that have not been assigned a branch is filtered out. An index_map is created to map from original commit index, to filtered commit index. TODO what? why? Would it not be better to track from child/heads instead of every single commit in repo?
§Branch sorting
The goal of this algorithm is to assign a column number to each tracked branch so that they can be visualized linearly without overlapping in the graph. It uses a shortest-first scheduling strategy (optionally longest-first and with forward/backward start sorting).
§Initialization
- occupied: A vector of vectors of vectors of tuples. The outer vector is indexed by the branch’s order_group (determined by branch_order based on the settings.branches.order). Each inner vector represents a column within that order group, and the tuples (start, end) store the range of commits occupied by a branch in that column.
§Preparing Branches for Sorting
- It creates branches_sort, a vector of tuples containing the branch index, its start commit index (range.0), its end commit index (range.1), its source order group, and its target order group.
- It filters out branches that don’t have a defined range (meaning they weren’t associated with any commits).
§Sorting Branches
- The branches_sort vector is sorted based on a key that prioritizes:
- The maximum of the source and target order groups. This likely aims to keep related branches (e.g., those involved in merges) closer together.
- The length of the branch’s lifespan (end - start commit index), either shortest-first or longest-first based on the shortest_first setting.
- The starting commit index, either forward or backward based on the forward setting.
pub fn take_repository(self) -> Repository
pub fn commit(&self, id: Oid) -> Result<Commit<'_>, Error>
Auto Trait Implementations§
impl Freeze for GitGraph
impl RefUnwindSafe for GitGraph
impl Send for GitGraph
impl !Sync for GitGraph
impl Unpin for GitGraph
impl UnwindSafe for GitGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);