brain: Simplify history review status
4d8663d40b619f1a4412251ab88061f7d4e8c979
Show review state directly in each history row instead of a commit graph and progress bar. Keep dropped commits distinct with a muted dash. Refresh aggregate progress and diff statistics immediately after commit accept, reject, and drop decisions, excluding dropped commits from the remaining review totals. Assisted-by: Codex:gpt-5.6-sol
1 parent
d429fb8a
crates/brain/src/backend.rs
+14 -0
| 431 | 431 | ) -> Self { |
|
| 432 | 432 | let statuses = brain.commit_statuses(commits); |
|
| 433 | 433 | let mut progress = ReviewProgress::default(); |
|
| 434 | 434 | let mut stats = DiffStat::default(); |
|
| 435 | 435 | for status in statuses.values() { |
|
| 436 | + | if matches!(status.state, CommitReviewState::Dropped) { |
|
| 437 | + | continue; |
|
| 438 | + | } |
|
| 436 | 439 | progress.accepted += status.progress.accepted; |
|
| 437 | 440 | progress.total += status.progress.total; |
|
| 438 | 441 | stats.files_changed += status.stats.files_changed; |
|
| 439 | 442 | stats.insertions += status.stats.insertions; |
|
| 440 | 443 | stats.deletions += status.stats.deletions; |
| 2010 | 2013 | brain.toggle_commit_dropped(commit).unwrap(); |
|
| 2011 | 2014 | let stored = backend.brain().unwrap(); |
|
| 2012 | 2015 | assert!(stored.dropped.contains_key(&commit)); |
|
| 2013 | 2016 | assert!(stored.rejected.is_empty()); |
|
| 2014 | 2017 | ||
| 2018 | + | let document = backend.diff_document(commit).unwrap().split_hunks(); |
|
| 2019 | + | let identities = brain.hunk_identities(&document, commit).unwrap(); |
|
| 2020 | + | let history = HistoryStatus::for_commits(&brain, &[(commit, &document, &identities)]); |
|
| 2021 | + | assert_eq!(history.progress, ReviewProgress::default()); |
|
| 2022 | + | assert_eq!(history.stats, DiffStat::default()); |
|
| 2023 | + | ||
| 2015 | 2024 | brain.toggle_commit_rejected(commit).unwrap(); |
|
| 2016 | 2025 | let stored = backend.brain().unwrap(); |
|
| 2017 | 2026 | assert!(stored.rejected.contains_key(&commit)); |
|
| 2018 | 2027 | assert!(stored.dropped.is_empty()); |
|
| 2019 | 2028 |
| 2029 | 2038 | brain.accept(identities.into_values(), [patches]).unwrap(); |
|
| 2030 | 2039 | let stored = backend.brain().unwrap(); |
|
| 2031 | 2040 | ||
| 2032 | 2041 | assert!(stored.rejected.is_empty()); |
|
| 2033 | 2042 | assert!(stored.dropped.is_empty()); |
|
| 2043 | + | ||
| 2044 | + | let identities = brain.hunk_identities(&document, commit).unwrap(); |
|
| 2045 | + | let history = HistoryStatus::for_commits(&brain, &[(commit, &document, &identities)]); |
|
| 2046 | + | assert!(history.progress.is_complete()); |
|
| 2047 | + | assert_eq!(history.stats, DiffStat::default()); |
|
| 2034 | 2048 | } |
|
| 2035 | 2049 | ||
| 2036 | 2050 | #[test] |
|
| 2037 | 2051 | fn rebase_keeps_unchanged_hunk_acceptance_after_amend() { |
|
| 2038 | 2052 | let repository = TestRepository::new(); |
f
+0 -0
new.rs
+0 -0
image.png
+0 -0
new.txt
+0 -0
crates/brain/src/session.rs
+12 -22
| 212 | 212 | commits: Vec<Commit>, |
|
| 213 | 213 | backend: &dyn Backend, |
|
| 214 | 214 | brain: &Brain, |
|
| 215 | 215 | palette: rustik_diff::DiffPalette, |
|
| 216 | 216 | width: usize, |
|
| 217 | - | ) -> Result<Table<8, Line>, Error> { |
|
| 217 | + | ) -> Result<Table<7, Line>, Error> { |
|
| 218 | 218 | let (mut slots, _) = reviewed_slots(commits, backend, brain)?; |
|
| 219 | 219 | slots.reverse(); |
|
| 220 | 220 | Ok(history_table(&slots, palette, width)) |
|
| 221 | 221 | } |
|
| 222 | 222 |
| 261 | 261 | /// Builds the commit table shared by interactive and regular history output. |
|
| 262 | 262 | fn history_table( |
|
| 263 | 263 | commits: &[CommitSlot], |
|
| 264 | 264 | palette: rustik_diff::DiffPalette, |
|
| 265 | 265 | width: usize, |
|
| 266 | - | ) -> Table<8, Line> { |
|
| 266 | + | ) -> Table<7, Line> { |
|
| 267 | 267 | let now = current_timestamp(); |
|
| 268 | - | let last = commits.len() - 1; |
|
| 269 | 268 | let largest_change_count = commits |
|
| 270 | 269 | .iter() |
|
| 271 | 270 | .map(|slot| { |
|
| 272 | 271 | let stats = slot.remaining_stats(); |
|
| 273 | 272 | stats.insertions + stats.deletions |
|
| 274 | 273 | }) |
|
| 275 | 274 | .max() |
|
| 276 | 275 | .unwrap_or(0); |
|
| 277 | 276 | let diffstat_width = (width / HISTORY_DIFFSTAT_WIDTH_DIVISOR) |
|
| 278 | 277 | .clamp(HISTORY_DIFFSTAT_MIN_WIDTH, HISTORY_DIFFSTAT_MAX_WIDTH); |
|
| 279 | - | let mut table = Table::<8, Line>::new(TableOptions { |
|
| 278 | + | let mut table = Table::<7, Line>::new(TableOptions { |
|
| 280 | 279 | spacing: 2, |
|
| 281 | 280 | ..TableOptions::default() |
|
| 282 | 281 | }) |
|
| 283 | 282 | .with_layout([ |
|
| 284 | 283 | Column::auto(), |
|
| 285 | 284 | Column::auto(), |
|
| 286 | 285 | Column::flex(1), |
|
| 287 | 286 | Column::collapse(2), |
|
| 288 | 287 | Column::collapse(3), |
|
| 289 | 288 | Column::collapse(1), |
|
| 290 | - | Column::auto(), |
|
| 291 | 289 | Column::collapse(4), |
|
| 292 | 290 | ]); |
|
| 293 | - | for (index, slot) in commits.iter().enumerate() { |
|
| 294 | - | let graph = match (index, last) { |
|
| 295 | - | (0, 0) => "──◉︎", |
|
| 296 | - | (0, _) => "╭─◉︎", |
|
| 297 | - | (index, last) if index == last => "╰─◉︎", |
|
| 298 | - | _ => "├─◉︎", |
|
| 299 | - | }; |
|
| 300 | - | let [graph, id, summary] = commit_row(slot, graph); |
|
| 301 | - | let [author, age, branches, progress, diffstat] = |
|
| 291 | + | for slot in commits { |
|
| 292 | + | let [state, id, summary] = commit_row(slot, palette); |
|
| 293 | + | let [author, age, branches, diffstat] = |
|
| 302 | 294 | commit_row_suffix(slot, palette, now, largest_change_count, diffstat_width); |
|
| 303 | - | table.push([ |
|
| 304 | - | graph, id, summary, author, age, branches, progress, diffstat, |
|
| 305 | - | ]); |
|
| 295 | + | table.push([state, id, summary, author, age, branches, diffstat]); |
|
| 306 | 296 | } |
|
| 307 | 297 | table |
|
| 308 | 298 | } |
|
| 309 | 299 | ||
| 310 | 300 | /// Commit-local hunk location used by acceptance and undo state. |
| 697 | 687 | if self.error.is_some() { |
|
| 698 | 688 | return Ok(()); |
|
| 699 | 689 | } |
|
| 700 | 690 | let commit = self.commits[index].commit.id; |
|
| 701 | 691 | self.brain.toggle_commit_rejected(commit)?; |
|
| 702 | - | self.reconcile_state(); |
|
| 692 | + | self.reconcile_reviews()?; |
|
| 703 | 693 | Ok(()) |
|
| 704 | 694 | } |
|
| 705 | 695 | ||
| 706 | 696 | /// Toggles the dropped state of one commit after pending persistence settles. |
|
| 707 | 697 | fn toggle_commit_dropped(&mut self, index: usize) -> Result<(), Error> { |
| 709 | 699 | if self.error.is_some() { |
|
| 710 | 700 | return Ok(()); |
|
| 711 | 701 | } |
|
| 712 | 702 | let commit = self.commits[index].commit.id; |
|
| 713 | 703 | self.brain.toggle_commit_dropped(commit)?; |
|
| 714 | - | self.reconcile_state(); |
|
| 704 | + | self.reconcile_reviews()?; |
|
| 715 | 705 | Ok(()) |
|
| 716 | 706 | } |
|
| 717 | 707 | ||
| 718 | 708 | /// Toggles acceptance of the focused hunk. |
|
| 719 | 709 | fn toggle_focused_hunk(&mut self, area: Rect) -> Result<(), Error> { |
| 1361 | 1351 | ||
| 1362 | 1352 | /// Reconciles review state and refreshes the active viewer when needed. |
|
| 1363 | 1353 | fn reconcile_reviews(&mut self) -> Result<(), Error> { |
|
| 1364 | 1354 | self.reconcile_state(); |
|
| 1365 | 1355 | self.history_status = None; |
|
| 1366 | - | if matches!(self.hunk_visibility, HunkVisibility::Pending) |
|
| 1367 | - | && !matches!(self.mode, Mode::Commits) |
|
| 1368 | - | { |
|
| 1356 | + | if matches!(self.mode, Mode::Commits) { |
|
| 1357 | + | self.ensure_history_status()?; |
|
| 1358 | + | } else if matches!(self.hunk_visibility, HunkVisibility::Pending) { |
|
| 1369 | 1359 | self.refresh_visibility()?; |
|
| 1370 | 1360 | } |
|
| 1371 | 1361 | Ok(()) |
|
| 1372 | 1362 | } |
|
| 1373 | 1363 |
a.rs
+0 -0
crates/brain/src/session/status.rs
+46 -32
| 2 | 2 | ||
| 3 | 3 | use std::cmp::Ordering; |
|
| 4 | 4 | use std::time::{SystemTime, UNIX_EPOCH}; |
|
| 5 | 5 | ||
| 6 | 6 | use rustik_diff::{ |
|
| 7 | - | DiffPalette, ReviewProgress, diffstat, file_count, full_progress_bar, progress_bar, |
|
| 8 | - | recoverable_error, |
|
| 7 | + | DiffPalette, ReviewProgress, diffstat, file_count, progress_bar, recoverable_error, |
|
| 9 | 8 | }; |
|
| 10 | 9 | use rustik_repo::DiffStat; |
|
| 11 | 10 | use rustik_tui::{ |
|
| 12 | 11 | Border, Buffer, Color, Constraint, HStack, Label, Line, Rect, Size, Style, Table, TableOptions, |
|
| 13 | 12 | Widget, colors, |
| 51 | 50 | pub(super) const SELECTED_COMMIT_BG: Color = Color::Fixed(235); |
|
| 52 | 51 | /// Marker shown beside a commit whose hunks have all been accepted: ✔. |
|
| 53 | 52 | const REVIEWED_MARK: char = '✔'; |
|
| 54 | 53 | /// Marker shown beside a rejected commit: ✗. |
|
| 55 | 54 | const REJECTED_MARK: char = '✗'; |
|
| 55 | + | /// Marker shown beside a dropped commit. |
|
| 56 | + | const DROPPED_MARK: char = '-'; |
|
| 57 | + | /// Marker shown beside a commit that has not been reviewed. |
|
| 58 | + | const PENDING_MARK: char = '○'; |
|
| 59 | + | /// Marker shown beside a commit whose review is in progress. |
|
| 60 | + | const IN_PROGRESS_MARK: char = '◐'; |
|
| 56 | 61 | /// Marker highlighted when all hunks are visible in the footer: ✔. |
|
| 57 | 62 | const ALL_HUNKS_MODE_ICON: &str = "✔"; |
|
| 58 | 63 | /// Marker shown when full-file mode is visible in the footer: ↕. |
|
| 59 | 64 | const FULL_FILE_MODE_ICON: &str = "↕"; |
|
| 60 | 65 | /// Separator shown between footer status segments: ·. |
| 339 | 344 | /// Returns the viewer area above the footer chrome. |
|
| 340 | 345 | pub(super) fn viewer_area(area: Rect) -> Rect { |
|
| 341 | 346 | Chrome::areas(area).0 |
|
| 342 | 347 | } |
|
| 343 | 348 | ||
| 344 | - | /// Returns the leading columns for one commit-table row. |
|
| 345 | - | pub(super) fn commit_row(slot: &CommitSlot, graph: &str) -> [Line; 3] { |
|
| 349 | + | /// Returns the state and leading columns for one commit-table row. |
|
| 350 | + | pub(super) fn commit_row(slot: &CommitSlot, palette: DiffPalette) -> [Line; 3] { |
|
| 346 | 351 | let dropped = matches!(slot.state, CommitReviewState::Dropped); |
|
| 347 | 352 | let row_style = if dropped { |
|
| 348 | 353 | Style::default().dim() |
|
| 349 | 354 | } else { |
|
| 350 | 355 | Style::default() |
|
| 351 | 356 | }; |
|
| 357 | + | let state = match slot.state { |
|
| 358 | + | CommitReviewState::Accepted => Label::from_char(REVIEWED_MARK).fg(palette.positive_fg), |
|
| 359 | + | CommitReviewState::Rejected => Label::from_char(REJECTED_MARK).fg(palette.negative_fg), |
|
| 360 | + | CommitReviewState::Dropped => Label::from_char(DROPPED_MARK).fg(colors::fixed::MUTED), |
|
| 361 | + | CommitReviewState::Pending if slot.progress.accepted > 0 => { |
|
| 362 | + | Label::from_char(IN_PROGRESS_MARK).fg(colors::rgb::ORANGE) |
|
| 363 | + | } |
|
| 364 | + | CommitReviewState::Pending => Label::from_char(PENDING_MARK).fg(colors::fixed::MUTED), |
|
| 365 | + | }; |
|
| 352 | 366 | [ |
|
| 353 | - | Line::new(Label::new(graph).fg(colors::fixed::MUTED)).style(row_style), |
|
| 367 | + | Line::new(state).style(row_style), |
|
| 354 | 368 | Line::new(Label::new(&slot.commit.id.short()).fg(colors::rgb::ORANGE)).style(row_style), |
|
| 355 | 369 | Line::new(slot.commit.summary.as_str()).style(if dropped { |
|
| 356 | 370 | Style::default().dim().strikethrough() |
|
| 357 | 371 | } else { |
|
| 358 | 372 | Style::default() |
| 361 | 375 | } |
|
| 362 | 376 | ||
| 363 | 377 | /// Returns the optional right-side columns for one commit-table row. |
|
| 364 | 378 | /// |
|
| 365 | 379 | /// Columns are ordered by their wide-layout position: author, age, branches, |
|
| 366 | - | /// review progress, and diffstat. |
|
| 380 | + | /// and diffstat. |
|
| 367 | 381 | pub(super) fn commit_row_suffix( |
|
| 368 | 382 | slot: &CommitSlot, |
|
| 369 | 383 | palette: DiffPalette, |
|
| 370 | 384 | now: u64, |
|
| 371 | 385 | largest_change_count: usize, |
|
| 372 | 386 | max_graph_width: usize, |
|
| 373 | - | ) -> [Line; 5] { |
|
| 387 | + | ) -> [Line; 4] { |
|
| 374 | 388 | let stats = slot.remaining_stats(); |
|
| 375 | 389 | let diffstat = match slot.state { |
|
| 376 | 390 | CommitReviewState::Pending => { |
|
| 377 | 391 | history_diffstat(stats, largest_change_count, max_graph_width, palette) |
|
| 378 | 392 | } |
|
| 379 | 393 | CommitReviewState::Accepted | CommitReviewState::Rejected | CommitReviewState::Dropped => { |
|
| 380 | 394 | Line::blank() |
|
| 381 | 395 | } |
|
| 382 | 396 | }; |
|
| 383 | - | let (status, progress) = match slot.state { |
|
| 384 | - | CommitReviewState::Accepted => ( |
|
| 385 | - | Label::from_char(REVIEWED_MARK).fg(palette.positive_fg), |
|
| 386 | - | progress_bar(slot.progress, palette, FOOTER_FG), |
|
| 387 | - | ), |
|
| 388 | - | CommitReviewState::Rejected => ( |
|
| 389 | - | Label::from_char(REJECTED_MARK).fg(palette.negative_fg), |
|
| 390 | - | full_progress_bar(palette.negative_fg), |
|
| 391 | - | ), |
|
| 392 | - | CommitReviewState::Dropped => (Label::space(), Line::blank()), |
|
| 393 | - | CommitReviewState::Pending => ( |
|
| 394 | - | Label::space(), |
|
| 395 | - | progress_bar(slot.progress, palette, FOOTER_FG), |
|
| 396 | - | ), |
|
| 397 | - | }; |
|
| 398 | - | let progress = if matches!(slot.state, CommitReviewState::Dropped) { |
|
| 399 | - | Line::blank() |
|
| 400 | - | } else { |
|
| 401 | - | Line::new(status).item(Label::space()).extend(progress) |
|
| 402 | - | }; |
|
| 403 | 397 | ||
| 404 | 398 | let row_style = if matches!(slot.state, CommitReviewState::Dropped) { |
|
| 405 | 399 | Style::default().dim() |
|
| 406 | 400 | } else { |
|
| 407 | 401 | Style::default() |
| 422 | 416 | .fg(colors::fixed::MUTED), |
|
| 423 | 417 | ) |
|
| 424 | 418 | .style(identity_style), |
|
| 425 | 419 | Line::new(Label::new(&slot.commit.branches.join(", ")).fg(colors::rgb::TEAL)) |
|
| 426 | 420 | .style(row_style), |
|
| 427 | - | progress.style(row_style), |
|
| 428 | 421 | diffstat.style(row_style), |
|
| 429 | 422 | ] |
|
| 430 | 423 | } |
|
| 431 | 424 | ||
| 432 | 425 | /// Returns a change count and proportional addition and deletion graph. |
| 695 | 688 | document: None, |
|
| 696 | 689 | identities: None, |
|
| 697 | 690 | loaded: None, |
|
| 698 | 691 | }; |
|
| 699 | 692 | ||
| 700 | - | for state in [CommitReviewState::Accepted, CommitReviewState::Rejected] { |
|
| 693 | + | for (state, marker) in [ |
|
| 694 | + | (CommitReviewState::Accepted, REVIEWED_MARK), |
|
| 695 | + | (CommitReviewState::Rejected, REJECTED_MARK), |
|
| 696 | + | ] { |
|
| 701 | 697 | slot.state = state; |
|
| 698 | + | assert_eq!( |
|
| 699 | + | commit_row(&slot, DiffPalette::default())[0].to_string(), |
|
| 700 | + | marker.to_string() |
|
| 701 | + | ); |
|
| 702 | 702 | assert!( |
|
| 703 | 703 | commit_row_suffix( |
|
| 704 | 704 | &slot, |
|
| 705 | 705 | DiffPalette::default(), |
|
| 706 | 706 | now as u64, |
|
| 707 | 707 | stats.insertions + stats.deletions, |
|
| 708 | 708 | 8, |
|
| 709 | - | )[4] |
|
| 709 | + | )[3] |
|
| 710 | 710 | .to_string() |
|
| 711 | 711 | .is_empty() |
|
| 712 | 712 | ); |
|
| 713 | 713 | } |
|
| 714 | 714 | ||
| 715 | 715 | slot.state = CommitReviewState::Dropped; |
|
| 716 | - | let [mut author, mut age, _, progress, diffstat] = commit_row_suffix( |
|
| 716 | + | let [mut author, mut age, _, diffstat] = commit_row_suffix( |
|
| 717 | 717 | &slot, |
|
| 718 | 718 | DiffPalette::default(), |
|
| 719 | 719 | now as u64, |
|
| 720 | 720 | stats.insertions + stats.deletions, |
|
| 721 | 721 | 8, |
|
| 722 | 722 | ); |
|
| 723 | - | assert!(progress.to_string().is_empty()); |
|
| 723 | + | assert_eq!( |
|
| 724 | + | commit_row(&slot, DiffPalette::default())[0].to_string(), |
|
| 725 | + | DROPPED_MARK.to_string() |
|
| 726 | + | ); |
|
| 724 | 727 | assert!(diffstat.to_string().is_empty()); |
|
| 725 | 728 | ||
| 726 | 729 | let mut author_buffer = Buffer::empty(Rect::new(0, 0, slot.commit.author.len(), 1)); |
|
| 727 | 730 | let mut age_buffer = Buffer::empty(Rect::new(0, 0, 16, 1)); |
|
| 728 | 731 | author.render(author_buffer.area(), &mut author_buffer); |
| 737 | 740 | Style::default() |
|
| 738 | 741 | .fg(colors::fixed::MUTED) |
|
| 739 | 742 | .dim() |
|
| 740 | 743 | .strikethrough() |
|
| 741 | 744 | ); |
|
| 745 | + | ||
| 746 | + | slot.state = CommitReviewState::Pending; |
|
| 747 | + | assert_eq!( |
|
| 748 | + | commit_row(&slot, DiffPalette::default())[0].to_string(), |
|
| 749 | + | PENDING_MARK.to_string() |
|
| 750 | + | ); |
|
| 751 | + | slot.progress.accepted = 1; |
|
| 752 | + | assert_eq!( |
|
| 753 | + | commit_row(&slot, DiffPalette::default())[0].to_string(), |
|
| 754 | + | IN_PROGRESS_MARK.to_string() |
|
| 755 | + | ); |
|
| 742 | 756 | } |
|
| 743 | 757 | ||
| 744 | 758 | #[test] |
|
| 745 | 759 | fn history_diffstat_scales_against_largest_commit() { |
|
| 746 | 760 | let palette = DiffPalette::default(); |