Skip to content

Commit 95d5c6f

Browse files
authored
More docs (#111)
This PR is a subset of PR 106 multi-fix. It only contains documentation changes, plus a rust 1.89.0 fix.
1 parent 91c1f09 commit 95d5c6f

5 files changed

Lines changed: 85 additions & 6 deletions

File tree

src/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//! Branching model configurations.
2+
//!
3+
//! In this module you will find functions to read and write branching model
4+
//! configurations on disk.
5+
//!
6+
//! The [branching models][BranchSettingsDef] themselves are defined in
7+
//! module [settings][super::settings]
8+
19
use crate::settings::{BranchSettingsDef, RepoSettings};
210
use git2::Repository;
311
use std::ffi::OsStr;

src/graph.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
//! A graph structure representing the history of a Git repository.
2+
//!
3+
//! To generate a graph, call [GitGraph::new()].
4+
//!
5+
//! ### Visualization of branches
6+
//! git-graph uses the term *branch* a little different from how git uses it.
7+
//! In git-lingo this means "a label on some commit", whereas in git-graph
8+
//! it means "a path in the ancestor graph of a repository". Nodes are
9+
//! commits, edges are directed from a child to its parents.
10+
//!
11+
//! In the text below, the term
12+
//! - *git-branch* is a label on a commit.
13+
//! - *branch* is the visualization of an ancestor path.
14+
//!
15+
//! git-graph visualizes branches as a vertical line. Only
16+
//! the primary parent of a commit can be on the same branch as the
17+
//! commit. Horizontal lines represent forks (multiple children) or
18+
//! merges (multiple parents), and show the remaining parent relations.
219
320
use crate::print::colors::to_terminal_color;
421
use crate::settings::{BranchOrder, BranchSettings, MergePatterns, Settings};
@@ -170,7 +187,7 @@ impl GitGraph {
170187
self.repository
171188
}
172189

173-
pub fn commit(&self, id: Oid) -> Result<Commit, Error> {
190+
pub fn commit(&self, id: Oid) -> Result<Commit<'_>, Error> {
174191
self.repository.find_commit(id)
175192
}
176193
}

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//! git-graph shows clear git graphs arranged for your branching model.
22
//!
33
//! It provides both a library and a command line tool.
4+
//!
5+
//! The main steps are:
6+
//! 1. Read branching model configuration (See [config] and [settings])
7+
//! 2. Lay out the graph structure according to the branching model (See [graph])
8+
//! 3. Render the layout to text or SVG (See [mod@print])
49
510
use git2::Repository;
611
use std::path::Path;

src/print/unicode.rs

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Create graphs in SVG format (Scalable Vector Graphics).
1+
//! Create graphs in Unicode format with ANSI X3.64 / ISO 6429 colour codes
22
33
use crate::graph::{CommitInfo, GitGraph, HeadInfo};
44
use crate::print::format::CommitFormat;
@@ -33,7 +33,26 @@ const WHITE: u8 = 7;
3333
const HEAD_COLOR: u8 = 14;
3434
const HASH_COLOR: u8 = 11;
3535

36-
type UnicodeGraphInfo = (Vec<String>, Vec<String>, Vec<usize>);
36+
/**
37+
UnicodeGraphInfo is a type alias for a tuple containing three elements:
38+
graph-lines, text-lines, start-row
39+
40+
1. graph_lines: `Vec<String>` - This represents the lines of the generated text-based graph
41+
visualization. Each `String` in this vector corresponds to a single row of
42+
the graph output, containing characters that form the visual representation
43+
of the commit history (like lines, dots, and branch intersections).
44+
45+
2. text_lines: `Vec<String>`: This represents the lines of the commit messages or other
46+
textual information associated with each commit in the graph. Each `String`
47+
in this vector corresponds to a line of text that is displayed alongside
48+
the graph. This can include commit hashes, author information, commit
49+
messages, branch names, and tags, depending on the formatting settings.
50+
Some entries in this vector might be empty strings or correspond to
51+
inserted blank lines for visual spacing.
52+
53+
3. start_row: `Vec<usize>`: Starting row for commit in the `graph.commits` vector.
54+
*/
55+
pub type UnicodeGraphInfo = (Vec<String>, Vec<String>, Vec<usize>);
3756

3857
/// Creates a text-based visual representation of a graph.
3958
pub fn print_unicode(graph: &GitGraph, settings: &Settings) -> Result<UnicodeGraphInfo, String> {
@@ -652,8 +671,19 @@ pub fn format_branches(
652671

653672
/// Occupied row ranges
654673
enum Occ {
655-
Commit(usize, usize),
656-
Range(usize, usize, usize, usize),
674+
/// Horizontal position of commit markers
675+
// First field (usize): The index of a commit within the graph.commits vector.
676+
// Second field (usize): The visual column in the grid where this commit is located. This column is determined by the branch the commit belongs to.
677+
// Purpose: This variant of Occ signifies that a specific row in the grid is occupied by a commit marker (dot or circle) at a particular column.
678+
Commit(usize, usize), // index in Graph.commits, column
679+
680+
/// Horizontal line connecting two commits
681+
// First field (usize): The index of the starting commit of a visual connection (usually the child commit).
682+
// Second field (usize): The index of the ending commit of a visual connection (usually the parent commit).
683+
// Third field (usize): The starting visual column of the range occupied by the connection line between the two commits. This is the minimum of the columns of the two connected commits.
684+
// Fourth field (usize): The ending visual column of the range occupied by the connection line between the two commits. This is the maximum of the columns of the two connected commits.
685+
// Purpose: This variant of Occ signifies that a range of columns in a particular row is occupied by a horizontal line segment connecting a commit to one of its parents. The range spans from the visual column of one commit to the visual column of the other.
686+
Range(usize, usize, usize, usize), // ?child index, parent index, leftmost column, rightmost column
657687
}
658688

659689
impl Occ {
@@ -674,11 +704,17 @@ fn sorted(v1: usize, v2: usize) -> (usize, usize) {
674704
}
675705
}
676706

677-
/// Two-dimensional grid with 3 layers, used to produce the graph representation.
707+
/// Two-dimensional grid used to produce the graph representation.
678708
#[allow(dead_code)]
679709
struct Grid {
680710
width: usize,
681711
height: usize,
712+
713+
/// Grid cells are stored in the data vector, layout row wise.
714+
/// For each cell in the grid, three values are stored:
715+
/// - Character (symbol)
716+
/// - Colour
717+
/// - Persistence level (z-order, lower numbers take preceedence)
682718
data: Vec<[u8; 3]>,
683719
}
684720

@@ -694,6 +730,7 @@ impl Grid {
694730
pub fn reverse(&mut self) {
695731
self.data.reverse();
696732
}
733+
/// Turn a 2D coordinate into an index of Grid.data
697734
pub fn index(&self, x: usize, y: usize) -> usize {
698735
y * self.width + x
699736
}

src/settings.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
//! Graph generation settings.
2+
//!
3+
//! The settings control how a branching graph is layed out.
4+
//! They are used in the [print][super::print] module when generating
5+
//! a visualization and persisted to disk in the [config][super::config] module.
6+
//!
7+
//! These are the main structs
8+
//! * [Settings] The main settings object, which contains:
9+
//! * [CommitFormat] Format of the commit summary text to the right of the graph.
10+
//! * [Characters] The symbols to use when rendering a graph as text.
11+
//! * [BranchSettings] Control how a graph is formatted.
12+
//! * [BranchOrder] Determines the left-to-right order of branches.
13+
//! * [MergePatterns] Regex that extract branch names from a merge commit.
214
315
use crate::print::format::CommitFormat;
416
use regex::{Error, Regex};

0 commit comments

Comments
 (0)