Skip to content

fix(tree): deduplicate entry-finding logic#2459

Open
datdenkikniet wants to merge 2 commits intoGitoxideLabs:mainfrom
datdenkikniet:unify-traversal
Open

fix(tree): deduplicate entry-finding logic#2459
datdenkikniet wants to merge 2 commits intoGitoxideLabs:mainfrom
datdenkikniet:unify-traversal

Conversation

@datdenkikniet
Copy link

I was poking around in the tree iteration code and saw an opportunity for some deduplication.

I'm not sure if the end result is worth it: a lot of generics and fairly opaque logic (looking at the direct implementation of Tree::peel_to_entry is... Not very satisfying :P), but I figured I'd put this here in case it is something that can be merged.

I'm not sure if the pub fn lookup_entry adheres to the style guide, but I'm more than willing to find a better solution if that is all that is in the way of fixing this.

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d0859a9f00

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +102 to +103
self.id = oid;
self.repo.find(&oid, buf).map(Some)
Copy link
Contributor

Choose a reason for hiding this comment

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

P2 Badge Update tree id only after loading next object succeeds

Setting self.id before self.repo.find() means peel_to_entry() mutates the tree state even when loading the next component returns an error (for example, a missing/corrupt intermediate object). In that error path self.data is still from the previous tree while self.id now points at an object that was never loaded, so callers that recover from the error can observe an inconsistent tree and get misleading follow-up behavior.

Useful? React with 👍 / 👎.

Copy link
Author

@datdenkikniet datdenkikniet Mar 6, 2026

Choose a reason for hiding this comment

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

I don't disagree, but I'm not looking to fix bugs with this implementation at this point in time (if this even is a bug, that's not entirely clear. That's effectively the answer to #2456)

@datdenkikniet
Copy link
Author

I just remembered that std::ops::ControlFlow exists and have rewritten it using that instead. It's ever so slightly more verbose, but has none of the horrible missing clarity shortcomings that the callback-based function has. Still looking for feedback.

I'm keeping both commits for posterity, but if we're going to merge it I can squash them :)

I will write sensible docs for iter_next if/when this is deemed mergeable.

The logic for finding entries is duplicated 3 times.

With an (unhealthy) smothering of generics, the common
functionality can be extracted into a single function
that can be reused in all places.
Instead of doing some messed up callback stuff, we can
also use std::ops::ControlFlow.

It is slightly more verbose, but definitely easier to
read.
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.

1 participant