Skip to content

Avoid exposing internal tuple in CommitList.marked #2638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
11 changes: 2 additions & 9 deletions src/components/commitlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub struct CommitList {
items: ItemBatch,
highlights: Option<Rc<IndexSet<CommitId>>>,
commits: IndexSet<CommitId>,
/// Commits that are marked. The .0 is used to provide a sort order.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First half is obvious, second half is its usage, not a description of .0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think usage is important in this case.

The .0 was really strange to me when I discovered it in code. After seeing that it was the index in the commit list, it made even less sense to me. It was not until I saw it being sorted in fn mark() that I figured why it was added - to make the list order stable to insertions and deletions, so I think the motivation for having it there is important.

I considered changing it to m̀arked: Vec<CommitId> (no pair) which would be easier to understand. The sorting would then have to look up the index using self.commits.get_index_of() but I expected somebody to argue that it would be some clock cycles slower.

I also wanted to keep the comment condensed - as few non-obvious parts as possible. The usage of .0 was the only thing not obvious to me.

If you prefer a more verbose comment that puts the "what" (description of content) before the "why" (description of function), how about this:

/// The marked commits.
/// .0 holds the commit index into self.items.items - used for ordering the list
/// .1 is the commit id of the marked commit

/// It contains an index into self.items.items
marked: Vec<(usize, CommitId)>,
scroll_state: (Instant, f32),
tags: Option<Tags>,
Expand Down Expand Up @@ -114,15 +116,6 @@ impl CommitList {
self.marked.len()
}

///
#[expect(
clippy::missing_const_for_fn,
reason = "as of 1.86.0 clippy wants this to be const even though that breaks"
)]
pub fn marked(&self) -> &[(usize, CommitId)] {
&self.marked
}

///
pub fn clear_marked(&mut self) {
self.marked.clear();
Expand Down
8 changes: 4 additions & 4 deletions src/tabs/revlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,19 +586,19 @@ impl Component for Revlog {
self.queue.push(InternalEvent::OpenPopup(
StackablePopupOpen::CompareCommits(
InspectCommitOpen::new(
self.list.marked()[0].1,
self.list.marked_commits()[0],
),
),
));
return Ok(EventState::Consumed);
} else if self.list.marked_count() == 2 {
//compare two marked commits
let marked = self.list.marked();
let marked = self.list.marked_commits();
self.queue.push(InternalEvent::OpenPopup(
StackablePopupOpen::CompareCommits(
InspectCommitOpen {
commit_id: marked[0].1,
compare_id: Some(marked[1].1),
commit_id: marked[0],
compare_id: Some(marked[1]),
tags: None,
},
),
Expand Down
Loading