Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ cherry-pick and an undo all stop here instead of being thrown away.
- [x] Force push with lease, and sending tags
- [x] Pull four ways: fetch, merge, fast-forward only and rebase
- [x] A column of branches and tags to the left of the graph
- [x] Every column of the graph as wide as you drag it, and it stays that way
- [x] Search the history by message, author or hash
- [x] A board of columns, worked out from the graph and storing nothing
- [x] In review means a pull request is open, asked of the forge through
Expand Down
7 changes: 4 additions & 3 deletions crates/gitrust-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ pub use remote_repo::RemoteRepo;
pub use rewrite::{Plan, Step};
pub use repo::Repo;
pub use settings::{
Appearance, Caret, General, Panel, Settings, FEWEST_COMMITS, LARGEST_TERMINAL_FONT,
LONGEST_FETCH_WAIT, LOOSEST_TERMINAL_LINE, SHORTEST_TERMINAL, SMALLEST_TERMINAL_FONT,
TALLEST_TERMINAL, TIGHTEST_TERMINAL_LINE,
Appearance, Caret, General, GraphColumns, Panel, Settings, FEWEST_COMMITS,
LARGEST_TERMINAL_FONT, LONGEST_FETCH_WAIT, LOOSEST_TERMINAL_LINE, NARROWEST_COLUMN,
SHORTEST_TERMINAL, SMALLEST_TERMINAL_FONT, TALLEST_TERMINAL, TIGHTEST_TERMINAL_LINE,
WIDEST_COLUMN,
};
pub use stash::StashEntry;
pub use submodule::Sub;
Expand Down
96 changes: 96 additions & 0 deletions crates/gitrust-core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,67 @@ pub const LOOSEST_TERMINAL_LINE: u32 = 500;
pub const SHORTEST_TERMINAL: u32 = 90;
pub const TALLEST_TERMINAL: u32 = 2_000;

/// The narrowest and the widest a column of the graph is remembered as, in
/// points. Under the first there is no room for a letter and the ellipsis
/// that says more were cut; the window decides how much of the second it
/// can have.
pub const NARROWEST_COLUMN: u32 = 32;
pub const WIDEST_COLUMN: u32 = 2_000;

/// How wide the graph's columns were dragged, in points.
///
/// Each is `None` until somebody drags it, and goes back to `None` when
/// they ask for it as it came. `None` is not a number written down in
/// advance: the branches' column measures the names it has to hold and the
/// lanes count the branches alive at once, so what they come as depends on
/// the repository. The message has no width of its own. It is what is left.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct GraphColumns {
pub refs: Option<u32>,
pub lanes: Option<u32>,
pub author: Option<u32>,
pub date: Option<u32>,
pub hash: Option<u32>,
}

impl GraphColumns {
/// The columns by the name each goes under in the file.
fn named(&self) -> [(&'static str, Option<u32>); 5] {
[
("refs", self.refs),
("lanes", self.lanes),
("author", self.author),
("date", self.date),
("hash", self.hash),
]
}

/// Takes `author 140`. A column nobody has heard of, or a width that
/// is not a number, leaves everything as it was.
fn take(&mut self, value: &str) {
let Some((name, points)) = value.trim().split_once(' ') else { return };
let Ok(points) = points.trim().parse::<u32>() else { return };
let slot = match name {
"refs" => &mut self.refs,
"lanes" => &mut self.lanes,
"author" => &mut self.author,
"date" => &mut self.date,
"hash" => &mut self.hash,
_ => return,
};
*slot = Some(points.clamp(NARROWEST_COLUMN, WIDEST_COLUMN));
}

/// Only the ones that were dragged: a column left alone is not in the
/// file, which is how it stays free to follow the repository.
fn render(&self) -> String {
self.named()
.into_iter()
.filter_map(|(name, width)| Some(format!("graph-column {name} {}\n", width?)))
.collect()
}
}

/// The fewest commits the graph will be asked to start with. Below this the
/// history stops before most people have scrolled once.
pub const FEWEST_COMMITS: usize = 500;
Expand Down Expand Up @@ -404,6 +465,10 @@ pub struct Settings {
pub terminal: Panel,
/// How tall it is when all of it is showing, in points.
pub terminal_height: u32,
/// How wide the graph's columns were dragged. One answer for the whole
/// window, like the terminal: it is how somebody likes to read a
/// history, not something about a repository.
pub columns: GraphColumns,
/// The version somebody said not to mention again, as its tag. The
/// one after it is mentioned: this is "not this one", not "never".
pub skipped: String,
Expand All @@ -420,6 +485,7 @@ impl Default for Settings {
front: 0,
terminal: Panel::default(),
terminal_height: 280,
columns: GraphColumns::default(),
skipped: String::new(),
}
}
Expand Down Expand Up @@ -480,6 +546,7 @@ impl Settings {
points.clamp(SHORTEST_TERMINAL, TALLEST_TERMINAL);
}
}
Some(("graph-column", value)) => settings.columns.take(value),
Some(("skip-update", value)) => settings.skipped = value.trim().to_string(),
Some((name, value)) => {
settings.general.take(name, value);
Expand Down Expand Up @@ -521,6 +588,7 @@ impl Settings {
self.terminal.as_str(),
self.terminal_height
));
text.push_str(&self.columns.render());
if !self.skipped.is_empty() {
text.push_str(&format!("skip-update {}\n", self.skipped));
}
Expand Down Expand Up @@ -680,6 +748,34 @@ mod tests {
}
}

#[test]
fn a_dragged_column_comes_back_as_wide_as_it_was_left() {
let columns = GraphColumns {
refs: Some(180),
lanes: None,
author: Some(64),
date: None,
hash: Some(90),
};
let settings = Settings { columns, ..Settings::default() };
let text = settings.render();
assert_eq!(Settings::parse(&text).columns, columns);
// One that was never dragged is not written down at all, so it is
// still free to follow the repository.
assert!(!text.contains("graph-column lanes"));
assert!(!Settings::default().render().contains("graph-column"));
}

#[test]
fn a_column_is_kept_inside_what_can_be_read() {
let columns = Settings::parse("graph-column author 3\ngraph-column refs 90000\n").columns;
assert_eq!(columns.author, Some(NARROWEST_COLUMN));
assert_eq!(columns.refs, Some(WIDEST_COLUMN));
// A column nobody has heard of, and a width that is not one.
let columns = Settings::parse("graph-column mood 80\ngraph-column date wide\n").columns;
assert_eq!(columns, GraphColumns::default());
}

#[test]
fn a_branch_name_with_a_space_in_it_is_not_taken() {
let settings = Settings::parse("default-branch my branch\n");
Expand Down
Loading
Loading