Repository navigation
Skip a branch whose name is not UTF-8 instead of failing every ref listing [patch] - #118
Merged
Merged
Conversation
…sting [patch] RefResolver.ListAsync read for-each-ref output through GitRunner's strict UTF-8 decoding, so one ref name git allows but UTF-8 cannot read failed the whole listing, and every /state and /branches request for that repository returned 502 refs-unreadable until the branch was deleted. GitInvocation.ReadStandardOutputAsBytes now returns stdout one character per byte. RefResolver decodes each line on its own, skips a line that is not UTF-8, and logs a warning with the hex of the ref name. Every other branch is still served. Fixes #114 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW24ManL6mVAsf34qvT
Keeps it clear of the lines #117 adds, so the two PRs merge in either order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW24ManL6mVAsf34qvT
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #114
What changes
RefResolver.ListAsyncreadfor-each-refoutput throughGitRunner's strict UTF-8 decoding. Git allows a ref name that isn't valid UTF-8, such as a Latin-1caf\xe9, and one of those failed the whole listing. Every/stateand/branchesrequest for the repository then returned 502refs-unreadableuntil someone deleted the branch upstream.GitInvocation.ReadStandardOutputAsBytes(new): when set,GitRunnerdecodes stdout as Latin-1, so each character is the byte git wrote. Every other command keeps strict UTF-8.RefResolversets the flag forfor-each-ref. The newDecodeLinesturns each line back into bytes and decodes it as strict UTF-8 on its own. A line that doesn't decode is dropped, and the rest go to the existingParse.RefLog.UndecodableRefSkipped, event 4000). The log names the mirror directory and the hex bytes of the ref name.RefResolvertakes an optionalILogger<RefResolver>, which DI supplies, and existing constructions keep working.A ref is skipped rather than served with a replacement character because the name can't be written into a JSON response faithfully. It would look fine and match nothing the client has.
Tests
RealRepositoryTests.RefResolver_ABranchNameThatIsNotUtf8_IsSkippeduses the realGitRunneragainst a bare mirror. The mirror hasrefs/heads/feature/caf\xe9written intopacked-refs, next tomainandfeature/ui. The listing must succeed, keep the other branches, leave out the bad one, and log exactly one warning carrying its hex.StateFlowTests.ABranchNameThatIsNotUtf8_IsSkipped_AndEveryOtherBranchIsStillServed:/branches?pattern=origin/*returns 200 with only the UTF-8 branches, and/statefororigin/mainreturns 200.ScriptedGitnow fails strict-modefor-each-refthe wayGitRunnerdoes when it holds a non-UTF-8 ref.RefResolverTests.DecodeLines_DropsOnlyTheLineThatIsNotUtf8: drops a lone 0xE9 and keeps a correctly encodedé.With the flag turned off in
RefResolver, the real-git test and the end-to-end test both fail. With it on, the fullGitBranchStateCache.Testssuite passes (288/288, net10.0).This branch is independent of #117. The end-to-end test goes at the end of
StateFlowTests, away from the lines #117 adds, andgit merge-treeconfirms the two branches merge cleanly in either order.🤖 Generated with Claude Code
https://claude.ai/code/session_017vfJW24ManL6mVAsf34qvT