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

Use showFileAtRefBase64 to read per-commit file contents #3744

Merged
merged 7 commits into from
Feb 24, 2025

Conversation

grahamc
Copy link
Contributor

@grahamc grahamc commented Feb 20, 2025

Closes #3743

@grahamc
Copy link
Contributor Author

grahamc commented Feb 20, 2025

Thanks @gustavderdrache (note: a colleague of mine) for the code review and fixups!

@grahamc

This comment was marked as outdated.

Comment on lines -360 to +394
const stdout: string[] = []
const stderr: string[] = []
const stdout: Buffer[] = []
let stdoutLength = 0
const stderr: Buffer[] = []
let stderrLength = 0

const options = {
cwd: this.workingDirectory,
env,
ignoreReturnCode: allowAllExitCodes,
listeners: {
stdout: (data: Buffer) => {
stdout.push(data.toString())
stdout.push(data)
stdoutLength += data.length
},
stderr: (data: Buffer) => {
stderr.push(data.toString())
stderr.push(data)
stderrLength += data.length
}
}
}

result.exitCode = await exec.exec(`"${this.gitPath}"`, args, options)
result.stdout = stdout.join('')
result.stderr = stderr.join('')
result.stdout = Buffer.concat(stdout, stdoutLength).toString(encoding)
result.stderr = Buffer.concat(stderr, stderrLength).toString(encoding)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note these changes are necessary to avoid accidentally incorrectly handling split chunks. In utf-8 this is a problem if the chunk is in the middle of a code point, corrupting the data. In base64 this is a problem because it can end up with padding in the middle of the stream, which effectively truncates the file early.

Reading it all into a single buffer and then converting retains the correct behavior, without letting the executing child process block on a full output stream.

@peter-evans
Copy link
Owner

@grahamc @gustavderdrache Thank you both for your effort to fix this! ❤️

The fix looks good to me. Not super happy about having to call git commands in the pushSignedCommits code path, but I think it can't be helped to have a performant solution.

I have a test suite that includes a large file and 1000 small files, so let's see what the performance is like.

@peter-evans
Copy link
Owner

peter-evans commented Feb 21, 2025

/test repository=DeterminateSystems/create-pull-request ref=showFileAtRef sign-commits=true

Command run output

@peter-evans
Copy link
Owner

peter-evans commented Feb 21, 2025

/test repository=DeterminateSystems/create-pull-request ref=showFileAtRef sign-commits=true perf=true

Command run output

@peter-evans
Copy link
Owner

If you can, it would be helpful if you could you run npm run format and commit the result. I don't have permission to push to your branch.

@grahamc
Copy link
Contributor Author

grahamc commented Feb 21, 2025

All set, thank you @peter-evans!

@peter-evans peter-evans merged commit dd2324f into peter-evans:main Feb 24, 2025
5 checks passed
@grahamc grahamc deleted the showFileAtRef branch February 24, 2025 14:38
@grahamc
Copy link
Contributor Author

grahamc commented Feb 24, 2025

Thank you again, @peter-evans!

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.

Commits that edit the same file squash into the first
3 participants