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

Copy slice before appending #522

Closed
wants to merge 1 commit into from
Closed

Conversation

acumino
Copy link

@acumino acumino commented Apr 23, 2022

Fixes: #500

@acumino
Copy link
Author

acumino commented Apr 23, 2022

/cc @mcuadros

@TopherIsSwell
Copy link

I'm not associated with this repository or this MR, but as a third-party, I can confirm that this patch improved my issue.

With upstream go-git in a repo with a 350M folder that was listed in the .gitignore, worktree.Status() returned in ~ 1.6s at best.
With this patch, in the same situation, worktree.Status() returns in <500ms at worst.

@mcuadros
Copy link
Member

mcuadros commented May 2, 2022

can you provide a test?

@acumino
Copy link
Author

acumino commented May 3, 2022

can you provide a test?

There is no new functionality, so no need for a new unit test.

subps, err = ReadPatterns(fs, append(path, fi.Name()))
tempPath := make([]string, len(path))
copy(tempPath, path)
subps, err = ReadPatterns(fs, append(tempPath, fi.Name()))

Choose a reason for hiding this comment

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

Think it would be cleaner to have the copy done by ParsePattern(), the object that takes ownership of the slice. Or in the readIgnoreFile func to share ownership. Here you would still get bugs if calling ReadPatterns incorrectly, e.g:

path := []string{"a", "b"}
ps, _ := ReadPatterns(fs, path)
path[1] = "change" // ps now corrupted

jcronk pushed a commit to jcronk/go-git that referenced this pull request Oct 4, 2022
@AriehSchneier
Copy link
Contributor

@acumino a test is not only needed for new functionality, a test is useful for fixes like this for multiple reasons include:

  • ensure that in future there is no regression (ie someone can't cause the same bug to come up later)
  • prove that there was a bug and that it is now fixed (the test should fail without the fix, but pass with the fix)

@acumino
Copy link
Author

acumino commented May 29, 2023

/close

@acumino acumino closed this May 29, 2023
@acumino acumino deleted the bug/git-tree branch May 29, 2023 14:13
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.

worktree.Status() not respecting .gitignore
5 participants