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

Conversation

peso
Copy link
Contributor

@peso peso commented May 12, 2025

This Pull Request is a minor cleanup

It changes the following:

  • Use a different function to avoid exposing the tuple used to sort commit id in CommitList.marked

I followed the checklist:

  • I added unittests
  • I ran make check without errors
  • I tested the overall application
  • I added an appropriate item to the changelog

Copy link
Contributor

@naseschwarz naseschwarz left a comment

Choose a reason for hiding this comment

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

Thank you for your PR. I have one item to pick on - if we add comments, they should be accurate.

@@ -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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants