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
5 changes: 3 additions & 2 deletions crates/gitcomet-git-gix/src/repo/remotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ fn branches_to_prune(
}

/// The branch `refs/remotes/<remote>/HEAD` points at, as `git remote set-head`
/// records it. An unreadable HEAD reads as none: only the Add-worktree dialog's
/// preselection depends on it, never the remote itself.
/// records it. An unreadable HEAD reads as none: only presentation depends on
/// it (the Add-worktree dialog's preselection and the commit card's badge
/// order), never the remote itself.
fn remote_default_branch(refs: &crate::refs::RefsView<'_>, remote: &str) -> Option<String> {
let head = refs
.find(format!("refs/remotes/{remote}/HEAD"))
Expand Down
26 changes: 16 additions & 10 deletions crates/gitcomet-ui-gpui/src/view/history_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,20 @@ where
{
let branch_heads: SmallVec<[&str; 8]> = branch_heads.into_iter().collect();
let has_branch_heads = !branch_heads.is_empty();
if let Some(graph) = compute_linear_visible_history_fast_path(
commits,
has_branch_heads,
active_head_target,
dotted_rows,
) {
// Below the first row, a branch tip changes its lane's colour.
let tips_below = !tip_colors.is_empty()
&& commits
.iter()
.skip(1)
.any(|commit| tip_colors.contains_key(commit.id_str()));
if !tips_below
&& let Some(graph) = compute_linear_visible_history_fast_path(
commits,
has_branch_heads,
active_head_target,
dotted_rows,
)
{
return graph;
}

Expand Down Expand Up @@ -419,10 +427,8 @@ where
is_branch_head,
true,
dotted_rows.get(commit_ix).copied().unwrap_or(false),
// Only a branch head starts a lane a branch owns.
is_branch_head
.then(|| tip_colors.get(commit.id_str()).copied())
.flatten(),
// A tip colours its lane even where branch heads fork none.
tip_colors.get(commit.id_str()).copied(),
)
.paint,
);
Expand Down
49 changes: 39 additions & 10 deletions crates/gitcomet-ui-gpui/src/view/history_graph_walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,17 @@ impl GraphWalk {
head: bool,
materialize: bool,
dotted: bool,
// The colour the branch at this tip owns; its new lane takes it even
// while another lane shows the same colour, so the log matches the
// branch's badges everywhere.
// The colour the branch at this tip owns, with or without `head`.
// The lane takes it from the tip on, even while another lane shows
// the same colour, so the log matches the branch's badges
// everywhere; above the tip, whatever arrives keeps its own.
tip_color: Option<LaneColorIx>,
) -> GraphTransition {
if materialize {
gitcomet_core::history_perf::record(gitcomet_core::history_perf::Work::PaintRow);
} else if !head && let Some(transition) = self.plain_transition(row, parents, merge, dotted)
} else if !head
&& tip_color.is_none()
&& let Some(transition) = self.plain_transition(row, parents, merge, dotted)
{
return transition;
}
Expand All @@ -301,16 +304,28 @@ impl GraphWalk {
now.push((col, LanePaint::lane(color, false, false)));
}
let only_main = hits.len() == 1 && self.main == self.lanes[hits[0]].map(|lane| lane.id);
let force = head
&& had_hits
&& hits.len() == 1
&& parents.len() <= 1
&& !(self.main_target == Some(row) && only_main);
let node = hits
.iter()
.copied()
.find(|&col| self.main == self.lanes[col].map(|lane| lane.id))
.unwrap_or(hits[0]);
let node_is_main = self.main == self.lanes[node].map(|lane| lane.id);
// A tip that lanes from above run into, or that sits on the main
// lane below HEAD, has no lane of its own to fork, and where branch
// heads fork nothing (`!head`) no tip has: the lane through it
// changes to the tip's colour there.
let recolor = tip_color.filter(|color| {
had_hits
&& (hits.len() > 1 || node_is_main || !head)
&& self.main_target != Some(row)
&& self.lanes[node].is_some_and(|lane| lane.color != *color)
});
let force = head
&& had_hits
&& hits.len() == 1
&& parents.len() <= 1
&& recolor.is_none()
&& !(self.main_target == Some(row) && only_main);
let fork_color = force.then(|| tip_color.unwrap_or_else(|| self.color(&[])));
let fork = fork_color.and_then(|color| {
self.lanes
Expand All @@ -327,7 +342,7 @@ impl GraphWalk {
let node_color = if adopt {
fork_color.unwrap()
} else {
self.lanes[node].unwrap().color
recolor.unwrap_or(self.lanes[node].unwrap().color)
};
let reserved_id = self.main.filter(|_| self.reserved);
let lanes_now = if materialize {
Expand Down Expand Up @@ -379,6 +394,20 @@ impl GraphWalk {
self.next_id += 1;
lane.born = row;
}
if let Some(color) = recolor
&& let Some(lane) = self.lanes.get_mut(node).and_then(Option::as_mut)
{
ended.push(lane.color);
self.colors[usize::from(lane.color)] -= 1;
lane.color = color;
self.colors[usize::from(color)] += 1;
lane.born = row;
// The main lane stays the main lane under its new colour.
if !node_is_main {
lane.id = self.next_id;
self.next_id += 1;
}
}
for &parent in parents.iter().skip(parents.len().min(hits.len())) {
if self.targets.contains_key(&(parent as u32)) {
continue;
Expand Down
64 changes: 61 additions & 3 deletions crates/gitcomet-ui-gpui/src/view/lane_colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
use super::history_graph::LaneColorIx;
use crate::theme::AppTheme;
use gitcomet_core::domain::{Branch, RemoteBranch};
use gitcomet_state::model::{RepoId, RepoState};
use gitcomet_ui_kit::theme::GRAPH_LANE_PALETTE_SIZE;
use gpui::Rgba;
use rustc_hash::FxHashMap;
use std::hash::{Hash as _, Hasher as _};
use std::sync::Arc;

/// The current branch's colour, which the log's main lane always takes.
pub(in crate::view) const HEAD_LANE_COLOR: LaneColorIx = 0;
Expand Down Expand Up @@ -120,6 +122,50 @@ impl BranchLaneColors {
}
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
struct BranchLaneColorsKey {
repo_id: RepoId,
lifetime: u64,
branches_rev: u64,
remote_branches_rev: u64,
head_branch_rev: u64,
}

/// One repository's [`BranchLaneColors`], rebuilt only when its branch lists
/// or current branch change.
#[derive(Default)]
pub(in crate::view) struct BranchLaneColorsCache {
cached: Option<(BranchLaneColorsKey, Arc<BranchLaneColors>)>,
}

impl BranchLaneColorsCache {
pub(in crate::view) fn get(&mut self, repo: &RepoState) -> Arc<BranchLaneColors> {
let key = BranchLaneColorsKey {
repo_id: repo.id,
lifetime: repo.lifetime(),
branches_rev: repo.branches_rev,
remote_branches_rev: repo.remote_branches_rev,
head_branch_rev: repo.head_branch_rev,
};
if let Some((cached, colors)) = &self.cached
&& *cached == key
{
return colors.clone();
}
let colors = Arc::new(BranchLaneColors::new(
repo.branches
.ready()
.map_or(&[][..], |rows| rows.as_slice()),
repo.remote_branches
.ready()
.map_or(&[][..], |rows| rows.as_slice()),
repo.head_branch.ready().map(String::as_str),
));
self.cached = Some((key, colors.clone()));
colors
}
}

/// Which lane a repository's log highlights, as the sidebar fades by it.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(in crate::view) enum LaneFocus {
Expand Down Expand Up @@ -183,10 +229,21 @@ pub(in crate::view) fn label_rgba(theme: AppTheme, full: Rgba, tone: LaneTone) -
}
}

/// The colours of a chip or badge that belongs to a lane, in the log and the
/// sidebar alike: one solid surface, the lane on its border and icon.
/// The solid surface every branch chip and badge sits on, log and sidebar alike.
pub(in crate::view) fn chip_surface(theme: AppTheme) -> Rgba {
if theme.is_dark {
theme.colors.surface.raised
} else {
theme.colors.surface.canvas
}
}

/// The colours of a chip or badge that belongs to a lane, in the log, the
/// sidebar and the commit card alike: one solid surface, the lane on its
/// border and icon.
#[derive(Clone, Copy, Debug, PartialEq)]
pub(in crate::view) struct LaneChipColors {
pub(in crate::view) bg: Rgba,
pub(in crate::view) border: Rgba,
/// The border while the chip is hovered, selected or picked.
pub(in crate::view) strong_border: Rgba,
Expand All @@ -195,8 +252,9 @@ pub(in crate::view) struct LaneChipColors {

impl LaneChipColors {
/// `lane` is the lane's colour at the tone it shows in.
pub(in crate::view) fn new(lane: Rgba) -> Self {
pub(in crate::view) fn new(theme: AppTheme, lane: Rgba) -> Self {
Self {
bg: chip_surface(theme),
border: super::color::with_alpha(lane, lane.alpha * CHIP_BORDER_ALPHA),
strong_border: lane,
icon: lane,
Expand Down
123 changes: 123 additions & 0 deletions crates/gitcomet-ui-gpui/src/view/lane_colors/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,129 @@ fn the_graph_draws_each_branch_tip_in_its_assigned_colour() {
assert_eq!(rows[2].node_color_ix, colors.local("other").unwrap());
}

/// The owner's report: branches forked from `dev` arrive at its tip on
/// their own lanes, and the tip took the first one's colour, so the log drew
/// `dev` in a colour its badges elsewhere do not wear. From its tip on, the
/// lane is `dev`'s; above it each fork keeps its own.
#[test]
fn a_tip_where_lanes_converge_takes_its_branchs_colour() {
// a: a1 - d; b: b1 - d; dev: d - base; main (checked out): h - base.
let commits = [
commit("a1", &["d"]),
commit("b1", &["d"]),
commit("d", &["base"]),
commit("h", &["base"]),
commit("base", &[]),
];
let branches = [
branch("a", "a1"),
branch("b", "b1"),
branch("dev", "d"),
branch("main", "h"),
];
let colors = BranchLaneColors::new(&branches, &[], Some("main"));
let tips = colors.tip_colors(&branches, &[], Some("main"));
let rows = crate::view::history_graph::compute_graph_lanes_styled(
&commits,
["a1", "b1", "d", "h"],
Some("h"),
&[],
&tips,
);
let dev = colors.local("dev").unwrap();
assert_eq!(rows[0].node_color_ix, colors.local("a").unwrap());
assert_eq!(rows[1].node_color_ix, colors.local("b").unwrap());
assert_eq!(rows[2].node_color_ix, dev, "dev's tip is dev's colour");
let below = rows[2].lanes_next[usize::from(rows[2].node_col)];
assert_eq!(
(below.color_ix, below.starts_at_node()),
(dev, true),
"the lane leaving the tip is dev's, begun at its node"
);
let above = rows[2].lanes_now[usize::from(rows[2].node_col)];
assert_eq!(
above.color_ix,
colors.local("a").unwrap(),
"the lane arriving from the fork above keeps the fork's colour"
);
assert_eq!(rows[3].node_color_ix, HEAD_LANE_COLOR);
}

/// The same on the checked-out branch's lane: it is that branch's down to
/// the next branch tip it passes, `origin/main` here, and that branch's
/// from there on.
#[test]
fn the_main_lane_takes_the_colour_of_each_branch_tip_it_passes() {
// feature (checked out): f2 - f1 - m; origin/main: m - base.
let commits = [
commit("f2", &["f1"]),
commit("f1", &["m"]),
commit("m", &["base"]),
commit("base", &[]),
];
let branches = [branch("feature", "f2")];
let remotes = [remote("main", "m")];
let colors = BranchLaneColors::new(&branches, &remotes, Some("feature"));
let tips = colors.tip_colors(&branches, &remotes, Some("feature"));
let rows = crate::view::history_graph::compute_graph_lanes_styled(
&commits,
["f2", "m"],
Some("f2"),
&[],
&tips,
);
let main = colors.remote("main").unwrap();
assert_ne!(main, HEAD_LANE_COLOR);
assert_eq!(
[0, 1, 2, 3].map(|row| rows[row].node_color_ix),
[HEAD_LANE_COLOR, HEAD_LANE_COLOR, main, main]
);
assert_eq!(
[0, 1, 2, 3].map(|row| rows[row].node_col),
[rows[0].node_col; 4],
"one lane throughout, with no fork beside it"
);
assert!(rows[2].joins_in.is_empty());
}

/// A current-branch view gives the graph no branch heads, so nothing forks,
/// but its one lane still changes colour at each branch tip it passes: the
/// tip's chip there matches the branch's badges too.
#[test]
fn a_current_branch_view_colours_its_lane_at_each_tip() {
let commits = [
commit("f2", &["f1"]),
commit("f1", &["dev"]),
commit("dev", &["m"]),
commit("m", &[]),
];
let branches = [branch("feature", "f2"), branch("dev", "dev")];
let remotes = [remote("main", "m")];
let colors = BranchLaneColors::new(&branches, &remotes, Some("feature"));
let tips = colors.tip_colors(&branches, &remotes, Some("feature"));
let rows = crate::view::history_graph::compute_graph_lanes_styled(
&commits,
[],
Some("f2"),
&[],
&tips,
);
assert_eq!(
[0, 1, 2, 3].map(|row| rows[row].node_color_ix),
[
HEAD_LANE_COLOR,
HEAD_LANE_COLOR,
colors.local("dev").unwrap(),
colors.remote("main").unwrap(),
]
);
assert!(
rows.iter()
.all(|row| row.node_col == rows[0].node_col && row.joins_in.is_empty()),
"one lane, nothing forked"
);
}

/// Each repository keeps its own highlighted lane: another tab's log clearing
/// its selection leaves the active repository's badges faded.
#[test]
Expand Down
5 changes: 3 additions & 2 deletions crates/gitcomet-ui-gpui/src/view/mod_helpers/mode_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ pub(crate) enum PopoverKind {
BranchPicker {
purpose: BranchPickerPurpose,
},
/// Selects or clears the live remote-tracking branch for the captured
/// checked-out local branch.
/// Selects or clears the live remote-tracking branch for the local branch
/// it names: the checked-out one from the action bar's upstream badge, any
/// one from the commit card's "No upstream" chip.
UpstreamPicker {
repo_id: RepoId,
branch: String,
Expand Down
Loading
Loading