Repository navigation
Add Subsections and Subsection for Git-style section names - #436
Merged
Merged
Conversation
Read [name "sub"] headers, such as [forge "github.com"], without parsing section names by hand. Names are parsed when read, so the lexer and stored section names are unchanged.
Subsections captured the section list when called, so sections added afterwards were missed. The docstrings now also say that only spacing between the parts matches Git, that name case merges sections under the case-insensitive options, and that Subsection writes a lowercased header with those options.
Subsections and Subsection now follow Git's header rules at read time: both [name "sub"] and [name.sub] forms, Git's name characters, no spaces around the parts, and headers Git takes as the same subsection merged into one read-only Subsection, with keys read from the last section that has them. CaseInsensitive lowercasing the sub is documented as a difference from Git.
A merged read-only Subsection could not keep Git's last value when the loader had already merged same-spelled headers, and lost MapTo, %(name)s references and shadows. Subsections and Subsection now return the *Section of each header, keeping Git's header rules, and document that headers spelled differently for the same sub are not merged. An empty name, as in [ "x"], is read as Git reads it.
Drop Git's name character check so names such as for_ge are read, and document it as a difference from Git. The Subsection docstring now says an added header is lowercased with the case-insensitive options.
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.
Describe the pull request
Adds
File.Subsections(name)andFile.Subsection(name, sub)for Git config-style section names such as[forge "github.com"], so callers like git-lfs-server no longer cut prefixes and quotes offSection.Name()by hand.Both return the
*Sectionof each header, soMapTo,%(name)sreferences and shadows work as usual. Section headers are read as Git reads them:[name "sub"]and the older[name.sub]both count, with a dotted sub lowercased. The name matches in any case. A dot in the name moves the rest into the sub, so[forge.a "b"]has suba.b. Spaces and tabs are allowed between the parts but not around them. In a quoted sub,\"and\\read as"and\, and a backslash before another character is dropped.[ forge "x"]or[forge "x" ], are skipped without an error.Subsectionsreads the sections each time it is ranged over.Subsectionreturns the section written as[name "sub"], or else the first match. If there is none, it returns a section that reads as empty, likeSectiondoes, and a change adds it with"and\in the sub escaped, lowercased under the case-insensitive options.Section names are parsed when they are read, not by the lexer, so parsing and stored section names are unchanged. That leaves three differences from Git, all documented:
", so[for_ge "x"]is read where Git rejects it.[forge "x"],[Forge "x"]and[forge.x], are separate sections, andSubsectionsyields the sub once for each, so callers can detect them. Headers spelled the same are one section, as they are forSection.CaseInsensitiveorCaseInsensitiveSections, the loader lowercases whole section names, so[forge "X"]and[forge "x"]are one section with subx, where Git keeps them separate.Link to the issue: n/a
Checklist
AI usage
Written with Amp (Claude), reviewed by the author.