Skip to content

Commit 47e1694

Browse files
committed
renamings and more precise structure
1 parent 2c72c7e commit 47e1694

2 files changed

Lines changed: 128 additions & 86 deletions

File tree

asyncgit/src/graph/walker.rs

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use super::buffer::Buffer;
22
use super::chunk::{Chunk, Markers};
3-
use super::oids::Oids;
4-
use super::{ConnType, GraphRow};
3+
use super::oids::GraphOids;
4+
use super::{ConnectionType, GraphRow, MAX_LANE_COLORS};
55
use crate::sync::{CommitId, CommitInfo};
66
use im::Vector;
77
use std::collections::{HashMap, HashSet};
88

99
pub struct GraphWalker {
1010
pub buffer: Buffer,
11-
pub oids: Oids,
11+
pub oids: GraphOids,
1212
pub branch_lane_map: HashMap<CommitId, usize>,
13-
pub mergers_map: HashMap<u32, u32>,
13+
pub mergers_map: HashMap<usize, usize>,
1414
}
1515

1616
impl Default for GraphWalker {
@@ -23,7 +23,7 @@ impl GraphWalker {
2323
pub fn new() -> Self {
2424
Self {
2525
buffer: Buffer::new(),
26-
oids: Oids::new(),
26+
oids: GraphOids::new(),
2727
branch_lane_map: HashMap::new(),
2828
mergers_map: HashMap::new(),
2929
}
@@ -189,9 +189,9 @@ impl GraphWalker {
189189
to,
190190
commit_lane,
191191
target_lane,
192-
ConnType::MergeBridgeMid,
193-
ConnType::MergeBridgeStart,
194-
ConnType::MergeBridgeEnd,
192+
ConnectionType::MergeBridgeMid,
193+
ConnectionType::MergeBridgeStart,
194+
ConnectionType::MergeBridgeEnd,
195195
);
196196
}
197197

@@ -211,9 +211,9 @@ impl GraphWalker {
211211
to,
212212
branch_lane,
213213
branch_lane,
214-
ConnType::MergeBridgeMid,
215-
ConnType::BranchUp,
216-
ConnType::BranchUpRight,
214+
ConnectionType::MergeBridgeMid,
215+
ConnectionType::BranchUp,
216+
ConnectionType::BranchUpRight,
217217
);
218218
}
219219

@@ -232,9 +232,9 @@ impl GraphWalker {
232232
#[allow(clippy::too_many_arguments)]
233233
fn fill_lanes(
234234
&self,
235-
lanes: &mut [Option<(ConnType, usize)>],
235+
lanes: &mut [Option<(ConnectionType, usize)>],
236236
curr: &Vector<Option<Chunk>>,
237-
alias: Option<u32>,
237+
alias: Option<usize>,
238238
head_id: Option<&CommitId>,
239239
is_stash: bool,
240240
is_merge: bool,
@@ -245,21 +245,21 @@ impl GraphWalker {
245245
let Some(chunk) = chunk_item.as_ref() else {
246246
if branching_lanes.contains(&lane_idx) {
247247
lanes[lane_idx] =
248-
Some((ConnType::BranchUp, lane_idx % 16));
248+
Some((ConnectionType::BranchUp, lane_idx % MAX_LANE_COLORS));
249249
}
250250
continue;
251251
};
252252

253253
if alias.is_some() && chunk.alias == alias {
254254
let conn_type =
255255
match (is_stash, is_merge, is_branch_tip) {
256-
(true, _, _) => ConnType::CommitStash,
257-
(_, true, _) => ConnType::CommitMerge,
258-
(_, _, true) => ConnType::CommitBranch,
259-
_ => ConnType::CommitNormal,
256+
(true, _, _) => ConnectionType::CommitStash,
257+
(_, true, _) => ConnectionType::CommitMerge,
258+
(_, _, true) => ConnectionType::CommitBranch,
259+
_ => ConnectionType::CommitNormal,
260260
};
261261

262-
lanes[lane_idx] = Some((conn_type, lane_idx % 16));
262+
lanes[lane_idx] = Some((conn_type, lane_idx % MAX_LANE_COLORS));
263263
} else {
264264
let is_dotted = head_id
265265
.and_then(|h| self.oids.get(h))
@@ -276,44 +276,52 @@ impl GraphWalker {
276276
}
277277

278278
let conn = if is_dotted {
279-
ConnType::VerticalDotted
279+
ConnectionType::VerticalDotted
280280
} else {
281-
ConnType::Vertical
281+
ConnectionType::Vertical
282282
};
283283

284-
lanes[lane_idx] = Some((conn, lane_idx % 16));
284+
lanes[lane_idx] = Some((conn, lane_idx % MAX_LANE_COLORS));
285285
}
286286
}
287287
}
288288

289289
fn draw_bridge(
290-
lanes: &mut [Option<(ConnType, usize)>],
290+
lanes: &mut [Option<(ConnectionType, usize)>],
291291
from: usize,
292292
to: usize,
293293
color_lane: usize,
294294
corner_lane: usize,
295-
mid: ConnType,
296-
corner_right: ConnType,
297-
corner_left: ConnType,
295+
mid: ConnectionType,
296+
corner_right: ConnectionType,
297+
corner_left: ConnectionType,
298298
) {
299299
for lane in lanes.iter_mut().take(to).skip(from + 1) {
300300
match lane {
301301
Some((
302-
ConnType::Vertical | ConnType::VerticalDotted,
302+
ConnectionType::Vertical | ConnectionType::VerticalDotted,
303303
_,
304304
)) => {
305-
*lane = Some((ConnType::Cross, color_lane % 16));
305+
*lane = Some((ConnectionType::Cross, color_lane % MAX_LANE_COLORS));
306306
}
307307
_ => {
308-
*lane = Some((mid, color_lane % 16));
308+
*lane = Some((mid, color_lane % MAX_LANE_COLORS));
309309
}
310310
}
311311
}
312312

313313
if corner_lane == to {
314-
lanes[to] = Some((corner_right, color_lane % 16));
314+
let new_corner = match (lanes[to], corner_right) {
315+
(Some((ConnectionType::MergeBridgeStart, _)), ConnectionType::BranchUp) => ConnectionType::BranchUpMergeStart,
316+
_ => corner_right,
317+
};
318+
lanes[to] = Some((new_corner, color_lane % MAX_LANE_COLORS));
315319
} else if corner_lane == from {
316-
lanes[from] = Some((corner_left, color_lane % 16));
320+
let new_corner = match (lanes[from], corner_left) {
321+
(Some((ConnectionType::MergeBridgeEnd, _)), ConnectionType::BranchUpRight) => ConnectionType::BranchUpRightMergeEnd,
322+
_ => corner_left,
323+
};
324+
lanes[from] = Some((new_corner, color_lane % MAX_LANE_COLORS));
317325
}
318326
}
319327
}

src/components/commitlist.rs

Lines changed: 89 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use super::utils::graphrow::{
22
SYM_BRANCH_DOWN, SYM_BRANCH_UP, SYM_BRANCH_UP_RIGHT, SYM_COMMIT,
33
SYM_COMMIT_BRANCH, SYM_COMMIT_MERGE, SYM_COMMIT_STASH,
4-
SYM_COMMIT_UNCOMMITTED, SYM_CROSS, SYM_HORIZONTAL, SYM_MERGE_BRIDGE_END,
5-
SYM_MERGE_BRIDGE_MID, SYM_MERGE_BRIDGE_START, SYM_SPACE,
6-
SYM_VERTICAL, SYM_VERTICAL_DOTTED,
4+
SYM_COMMIT_UNCOMMITTED, SYM_CROSS, SYM_HORIZONTAL,
5+
SYM_MERGE_BRIDGE_END, SYM_MERGE_BRIDGE_MID,
6+
SYM_MERGE_BRIDGE_START, SYM_SPACE, SYM_VERTICAL,
7+
SYM_VERTICAL_DOTTED,
78
};
89
use super::utils::logitems::{ItemBatch, LogEntry};
910
use crate::{
@@ -21,7 +22,7 @@ use crate::{
2122
};
2223
use anyhow::Result;
2324
use asyncgit::{
24-
graph::{ConnType, GraphRow},
25+
graph::{ConnectionType, GraphRow},
2526
sync::{
2627
self, checkout_commit, BranchDetails, BranchInfo, CommitId,
2728
RepoPathRef, Tags,
@@ -502,50 +503,78 @@ impl CommitList {
502503
}
503504
let (sym, graph_color) = match conn {
504505
None => (SYM_SPACE, Color::Reset),
505-
Some((ConnType::Vertical, color_idx)) => {
506-
(SYM_VERTICAL, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()])
507-
}
508-
Some((ConnType::VerticalDotted, color_idx)) => {
509-
(SYM_VERTICAL_DOTTED, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()])
510-
}
511-
Some((ConnType::Cross, color_idx)) => {
512-
(SYM_CROSS, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()])
513-
}
514-
Some((ConnType::CommitNormal, color_idx)) => {
515-
(SYM_COMMIT, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()])
516-
}
517-
Some((ConnType::CommitBranch, color_idx)) => {
518-
(SYM_COMMIT_BRANCH, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()])
519-
}
520-
Some((ConnType::CommitMerge, color_idx)) => {
521-
(SYM_COMMIT_MERGE, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()])
522-
}
523-
Some((ConnType::CommitStash, color_idx)) => {
524-
(SYM_COMMIT_STASH, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()])
525-
}
526-
Some((ConnType::CommitUncommitted, color_idx)) => {
527-
(SYM_COMMIT_UNCOMMITTED, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()])
528-
}
529-
Some((ConnType::MergeBridgeStart, color_idx)) => {
530-
(SYM_MERGE_BRIDGE_START, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()])
531-
}
532-
Some((ConnType::MergeBridgeMid, color_idx)) => {
533-
(SYM_MERGE_BRIDGE_MID, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()])
534-
}
535-
Some((ConnType::MergeBridgeEnd, color_idx)) => {
536-
(SYM_MERGE_BRIDGE_END, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()])
537-
}
538-
Some((ConnType::BranchDown, color_idx)) => {
539-
(SYM_BRANCH_DOWN, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()])
540-
}
541-
Some((ConnType::BranchUp, color_idx)) => {
542-
(SYM_BRANCH_UP, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()])
543-
}
544-
Some((ConnType::BranchUpRight, color_idx)) => {
545-
(SYM_BRANCH_UP_RIGHT, GRAPH_COLORS[color_idx % GRAPH_COLORS.len()])
546-
}
506+
Some((ConnectionType::Vertical, color_idx)) => (
507+
SYM_VERTICAL,
508+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
509+
),
510+
Some((ConnectionType::VerticalDotted, color_idx)) => (
511+
SYM_VERTICAL_DOTTED,
512+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
513+
),
514+
Some((ConnectionType::Cross, color_idx)) => (
515+
SYM_CROSS,
516+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
517+
),
518+
Some((ConnectionType::BranchUpMergeStart, color_idx)) => (
519+
SYM_BRANCH_UP, // Reusing '┛'
520+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
521+
),
522+
Some((
523+
ConnectionType::BranchUpRightMergeEnd,
524+
color_idx,
525+
)) => (
526+
SYM_BRANCH_UP_RIGHT, // Reusing '┗'
527+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
528+
),
529+
Some((ConnectionType::CommitNormal, color_idx)) => (
530+
SYM_COMMIT,
531+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
532+
),
533+
Some((ConnectionType::CommitBranch, color_idx)) => (
534+
SYM_COMMIT_BRANCH,
535+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
536+
),
537+
Some((ConnectionType::CommitMerge, color_idx)) => (
538+
SYM_COMMIT_MERGE,
539+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
540+
),
541+
Some((ConnectionType::CommitStash, color_idx)) => (
542+
SYM_COMMIT_STASH,
543+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
544+
),
545+
Some((ConnectionType::CommitUncommitted, color_idx)) => (
546+
SYM_COMMIT_UNCOMMITTED,
547+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
548+
),
549+
Some((ConnectionType::MergeBridgeStart, color_idx)) => (
550+
SYM_MERGE_BRIDGE_START,
551+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
552+
),
553+
Some((ConnectionType::MergeBridgeMid, color_idx)) => (
554+
SYM_MERGE_BRIDGE_MID,
555+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
556+
),
557+
Some((ConnectionType::MergeBridgeEnd, color_idx)) => (
558+
SYM_MERGE_BRIDGE_END,
559+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
560+
),
561+
Some((ConnectionType::BranchDown, color_idx)) => (
562+
SYM_BRANCH_DOWN,
563+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
564+
),
565+
Some((ConnectionType::BranchUp, color_idx)) => (
566+
SYM_BRANCH_UP,
567+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
568+
),
569+
Some((ConnectionType::BranchUpRight, color_idx)) => (
570+
SYM_BRANCH_UP_RIGHT,
571+
GRAPH_COLORS[color_idx % GRAPH_COLORS.len()],
572+
),
547573
};
548-
spans.push(Span::styled(sym, Style::default().fg(graph_color)));
574+
spans.push(Span::styled(
575+
sym,
576+
Style::default().fg(graph_color),
577+
));
549578

550579
// Spacer
551580
let mut is_bridge_lane = false;
@@ -554,15 +583,21 @@ impl CommitList {
554583
if let Some((from, to)) = row.merge_bridge {
555584
if lane_index >= from && lane_index < to {
556585
is_bridge_lane = true;
557-
spacer_color = GRAPH_COLORS[row.commit_lane % GRAPH_COLORS.len()];
586+
spacer_color = GRAPH_COLORS
587+
[row.commit_lane % GRAPH_COLORS.len()];
558588
}
559589
}
560590

561591
for &(from, to) in &row.branches {
562592
if lane_index >= from && lane_index < to {
563593
is_bridge_lane = true;
564-
let branch_lane = if row.commit_lane == from { to } else { from };
565-
spacer_color = GRAPH_COLORS[branch_lane % GRAPH_COLORS.len()];
594+
let branch_lane = if row.commit_lane == from {
595+
to
596+
} else {
597+
from
598+
};
599+
spacer_color = GRAPH_COLORS
600+
[branch_lane % GRAPH_COLORS.len()];
566601
}
567602
}
568603

@@ -788,7 +823,7 @@ impl CommitList {
788823
if !matches!(
789824
conn,
790825
None | Some((
791-
ConnType::MergeBridgeMid,
826+
ConnectionType::MergeBridgeMid,
792827
_
793828
))
794829
) {
@@ -849,7 +884,7 @@ impl CommitList {
849884
local_branches,
850885
self.remote_branches_string(e),
851886
&self.theme,
852-
width,
887+
width.into(),
853888
now,
854889
marked,
855890
&empty_lanes,
@@ -1330,12 +1365,11 @@ mod tests {
13301365
is_merge: false,
13311366
is_branch_tip: false,
13321367
is_stash: false,
1333-
lanes: vec![Some((ConnType::CommitNormal, 0))],
1368+
lanes: vec![Some((ConnectionType::CommitNormal, 0))],
13341369
merge_bridge: None,
13351370
branches: vec![],
13361371
};
1337-
let empty_lanes = std::collections::HashSet::new();
1338-
let spans = cl.build_graph_spans(&row, 1, &empty_lanes);
1372+
let spans = cl.build_graph_spans(&row, 1);
13391373

13401374
assert_eq!(spans.len(), 2);
13411375
assert_eq!(spans[0].content, Cow::from(SYM_COMMIT));

0 commit comments

Comments
 (0)