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

Improve git walking #439

Merged
merged 2 commits into from
Oct 15, 2024
Merged

Improve git walking #439

merged 2 commits into from
Oct 15, 2024

Conversation

brianmcgee
Copy link
Member

@brianmcgee brianmcgee commented Oct 12, 2024

Replaces the use of go-git with a simple git ls-file for traversing the git index.

TODO

@brianmcgee brianmcgee force-pushed the feat/improve-git-walker branch from 5580ac3 to 73e6f78 Compare October 12, 2024 11:30
@brianmcgee brianmcgee mentioned this pull request Oct 12, 2024
2 tasks
@brianmcgee brianmcgee force-pushed the feat/improve-git-walker branch from 73e6f78 to 93f25f8 Compare October 12, 2024 11:32
@brianmcgee brianmcgee changed the title feat/improve git walker Improve git walking Oct 12, 2024
@brianmcgee brianmcgee force-pushed the feat/improve-git-walker branch from 9fd3d11 to 8123351 Compare October 12, 2024 13:38
@brianmcgee brianmcgee marked this pull request as ready for review October 12, 2024 13:40
@brianmcgee brianmcgee requested a review from zimbatm October 12, 2024 13:40
@brianmcgee brianmcgee force-pushed the feat/improve-git-walker branch from 8123351 to 4877ea1 Compare October 12, 2024 14:09
@brianmcgee
Copy link
Member Author

@jfly wouldn't mind your eye on this too 🙏

walk/git.go Outdated Show resolved Hide resolved
walk/git.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@jfly jfly left a comment

Choose a reason for hiding this comment

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

This is a neat idea! It'll be cool to see it in action.

I tried to give you a thorough review, but I'm a total beginner with go, and don't really have treefmt's architecture in my head.

That said, I think I understand enough of this PR to know that either something is missing, or I'm even more confused than I realize. Perhaps I'm just misunderstanding what this feature is meant to do.

I would have expected that if I ask treefmt to format my staged files, it would do some git acrobatics to only format the staged changes of those staged files. (You'll see this expectation reflected in at least one of my inline code comments). Now that I've read the whole diff, that doesn't seem to be the case: this really only affects which files we walk over, it doesn't do anything clever to separate the staged vs unstaged changes. Doing this right is tricky and is why writing a pre-commit hook correctly is so damn annoying.

If I understand correctly, this also doesn't seem to implement the thing asked for in #311. But maybe the goal changed since June? I'm also a little skeptical about the thing being described in #311. I'll leave a comment over there about that.

cmd/root_test.go Outdated Show resolved Hide resolved
cmd/root_test.go Outdated Show resolved Hide resolved
walk/filesystem.go Outdated Show resolved Hide resolved
walk/git_test.go Outdated Show resolved Hide resolved
cmd/root_test.go Show resolved Hide resolved
walk/git.go Outdated Show resolved Hide resolved
walk/git.go Outdated Show resolved Hide resolved
@brianmcgee
Copy link
Member Author

If I understand correctly, this also doesn't seem to implement the thing asked for in #311. But maybe the goal changed since June? I'm also a little skeptical about the thing being described in #311. I'll leave a comment over there about that.

I tagged that issue as I thought I was solving the same problem. But you're right; I seem to have drifted.

@brianmcgee brianmcgee marked this pull request as draft October 13, 2024 13:58
@brianmcgee
Copy link
Member Author

On reflection and continuing the discussion in #311, I will simplify this PR to just replacing go-git with git ls-files.

@brianmcgee brianmcgee force-pushed the feat/improve-git-walker branch from 4877ea1 to 8a719ff Compare October 13, 2024 15:11
@jfly
Copy link
Collaborator

jfly commented Oct 13, 2024

I will simplify this PR to just replacing go-git with git ls-files

Just curious, why are we dropping go-git? Coincidently, I had a conversation with @traxys a few weeks ago about an issue he was running into with some experimental git feature (core.fsmonitor, I think?) that (maybe?) isn't by go-git. I suspect that switching to git ls-files would have made that problem go away.

@brianmcgee
Copy link
Member Author

Just curious, why are we dropping go-git?

Originally, this was motivated by the status in go-git being very slow on large repos, so when I was trying to implement the git_staged walk type, it was a non-starter as Nixpkgs is my reference. From there, if I was going to just shell out to git anyway, it felt like overkill to use go-git.

Having seen how clean and simple it looks just shelling out versus using go-git (which I could have optimized a bit more I guess), I decided to remove an extra dependency and keep things simple. We did get burned previously by a bug in go-git nix-community/infra#1266 (comment).

TLDR; less dependencies, less indirection, less code 🙂

@brianmcgee
Copy link
Member Author

I'll rebase this once #447 is merged and then mark it ready for review.

@brianmcgee brianmcgee force-pushed the feat/improve-git-walker branch from 8a719ff to d51e247 Compare October 14, 2024 09:55
@brianmcgee brianmcgee marked this pull request as ready for review October 14, 2024 09:55
@brianmcgee brianmcgee requested a review from jfly October 14, 2024 09:55
cmd/root_test.go Show resolved Hide resolved
config/config.go Outdated Show resolved Hide resolved
walk/filesystem.go Show resolved Hide resolved
walk/git.go Show resolved Hide resolved
walk/git.go Show resolved Hide resolved
cmd/root_test.go Show resolved Hide resolved
@brianmcgee brianmcgee force-pushed the feat/improve-git-walker branch from d51e247 to 349abb9 Compare October 14, 2024 14:25
Replaces the use of `go-git` with a simple `git ls-file` for traversing the git index.

Signed-off-by: Brian McGee <[email protected]>
@brianmcgee brianmcgee force-pushed the feat/improve-git-walker branch from 349abb9 to 844f3fd Compare October 14, 2024 14:43
@brianmcgee brianmcgee requested a review from jfly October 14, 2024 14:45
@brianmcgee brianmcgee merged commit 7b6fc1b into main Oct 15, 2024
27 checks passed
@brianmcgee brianmcgee deleted the feat/improve-git-walker branch October 15, 2024 06:42
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