Skip to content
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

tools/internal/parser: add diff support #2071

Merged
merged 3 commits into from
Jul 25, 2024

Conversation

danderson
Copy link
Contributor

List.SetBaseVersion takes an older base List, and makes Block.Changed()
reflect whether or not each block has changed compared to that base.

2 commits: one is the refactor to introduce the blockInfo struct, the other is diff.go and tests.

This is a building block that sets change information on a parsed list, which validations can then use to ignore unchanged elements. Generalized tree diff is an open academic research problem, so instead of doing that, this implementation takes some shortcuts by exploiting some special properties of the PSL, and by accepting some false positives (we mark as changed some things that didn't change, or changed in a way doesn't matter for validation) in exchange for simpler code and no false negatives.

I ran this logic against the last 50 PSL changes, here are the git diffs vs. changed parse tree nodes. Some noteworthy illustrations of the semantics:

@simon-friedberger
Copy link
Contributor

I merged your other PR. What is this conflict with and without toolchain?

As part of that, refactor slightly to hide fields that should not be
editable outside of the package, and provide read-only accessors instead.
List.SetBaseVersion takes an older base List, and makes Block.Changed()
reflect whether or not each block has changed compared to that base.
Some stdlib features require Go 1.22, we don't need to mandate a specific
minimum version of 1.22.
@danderson
Copy link
Contributor Author

That's an odd conflict, it seems like git should be able to resolve that without help. 🤷 I rebased this PR onto master and the conflict disappeared.

But actually looking at it more closely, I'm not sure why the toolchain directive got added. The code requires Go 1.22 for a few stdlib features, but forcing a minimum patch version of the toolchain is unnecessary. I suspect my emacs/LSP machinery added at some point during an automated edit. I added a commit to this PR to remove the toolchain directive and rely only on the go 1.22 directive.

@simon-friedberger simon-friedberger merged commit a181dd9 into publicsuffix:master Jul 25, 2024
1 check passed
@danderson danderson deleted the push-wxvuuuzpmruy branch July 25, 2024 08:35
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.

None yet

2 participants