-
Notifications
You must be signed in to change notification settings - Fork 803
utils: merkletrie, Fix diff on sparse-checkout index. Fixes #1406 #1492
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@onee-only thanks for resolving this issue, just found two small nits. Otherwise, LGTM. Please rebase.
6a62b0c
to
af58bc3
Compare
af58bc3
to
9dc151a
Compare
@pjbgf rebased and applied the suggestions. But the CI is failing on code that's unrelated to my changes. Could you please re-run it? |
Just found out that we don't need to call AddRecursiveXXX when the node has to be skipped. |
@onee-only thanks for rebasing. 🙇
Please add a comment explaining the reasons behind that change, so that it is easier for future contributors to understand it. |
I don't think the comment in the code is necessary. Because the code before was more difficult to understand. Instead I'll leave a comment on the commit explaining why this change was made. |
When node.Skip() == true, it means the node and all its descendants should be skipped. Previously, we were still calling AddRecursiveDelete() on such nodes, which is redundant, since addRecursive() skips the entire subtree. This change removes those unnecessary AddRecursiveDelete() calls, and also adds a missing check to skip the 'from' node in the 'onlyFromRemains' case. Additionally, prettified the if-else structure in the switch case for better readability.
cebe050
to
e8c9fcd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@onee-only fair point, LGTM. Thanks for working on this. 🙇
utils: merkletrie, Fix diff on sparse-checkout index. Fixes go-git#1406
utils: merkletrie, Fix diff on sparse-checkout index. Fixes go-git#1406
utils: merkletrie, Fix diff on sparse-checkout index. Fixes go-git#1406
Fixes #1406
This PR depends on #1484, as it partially fixes a diff issue in the sparse-checkout index.
Building on top of that, I’ve added a small check in the early return of addRecursive() to handle an edge case where the skipped node is a first-level node.
Please let me know if this check should instead be introduced in #1484. I'm not sure where it belongs.
There's a case where two trees are not the same, and one of them has nodes with skip == true, such as in comparisons between a sparse-checkout index and the worktree.
In this case, we shouldn't call ii.nextBoth(), since we might be comparing different nodes. So I added a check for that as well.
go-git/utils/merkletrie/difftree.go
Lines 319 to 341 in 4e67bbe
Since this PR depends on #1484, I'll rebase this after that one is merged.