← Back to Pull requests

gcfg: Report subsections through ReadWithOptions #19

Closed
unknown closed this pull request without merging on Nov 18, 2026 13:00 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 02:50 UTC
Author

ReadWithCallback passes "" as the subsection for both [x] and [x ""], so a consumer cannot tell Git's x.key from x..key (git config -l prints x.a and x..a for the two headers). go-git folds protocol..allow onto protocol.allow because of this, so a key Git never consults for the protocol policy takes effect as protocol.allow (go-git/go-git#2403).

Changes

  • ReadWithOptions takes ReadOption values and reports each section header and option as an Event. Event.HasSubsection is true for [x ""] and for a legacy [x.y] header, false for [x]. It describes the header being read, so option lines carry it as well, and it resets at every header. A consumer rebuilds Git's key as x..key or x.key from it.

  • Event.Position is a token.Position, the module's existing position type, with the 1-based Line and Column of the header's [ or of the option key, so a consumer can report where it refused something.

  • WithCallback sets the callback. It is optional: without it ReadWithOptions only parses the data, reports no events and returns the same errors as a callback that ignores them, which checks syntax.

  • ReadWithCallback keeps its signature and wraps ReadWithOptions. ReadInto and the other Read*Into functions behave as before.

  • Shape. An earlier version of this PR added ReadWithSubsectionCallback, which took six positional arguments, two of them bool, so a caller could swap them and still compile. The named fields of Event fix that, and options leave room to add more without another signature change. That function was never released, so it is gone.

  • Docs. ReadWithCallback says that [x ""] reports like [x] and points to ReadWithOptions. ReadInto says it keeps folding [sec ""] onto [sec], because a struct target cannot represent sec..key, and that a caller applying a policy keyed on a subsection must use ReadWithOptions. doc.go is updated to match.
  • Behaviour changes

    None for existing callers. This adds exported API, so it needs a minor release. ReadInto still folds [sec ""] onto [sec]. That is not new, and it is a conscious choice: refusing it would break v2 callers, and the fold is now documented.

    Dependencies

    #18, which handles the legacy [section.subsection] header, is merged. go-git/go-git#2558 (open) adds go-git's own use of it in plumbing/format/config/legacy.go, which is not on go-git main yet. go-git/go-git#2403 uses ReadWithOptions to refuse [protocol ""] and needs this released before it can drop a temporary replace.

    For go-git

    go-git can refuse a header with HasSubsection && Subsection == "" in its decoder, instead of the rewrite and fail-closed trick. Its Section and Subsection types carry only a name, so that check stays in go-git's decoder.

    Testing

    Table tests cover [a.b], [a "b"], [a ""] and [a], the flag on option lines, the reset ([x "y"], then [z], then [x]; the test fails without the reset), the old callbacks being unchanged, and [x.] still being refused. TestReadWithOptionsPosition covers a header and keys on several lines, indented ones, comments and blank lines, and a legacy header. TestReadWithOptionsWithoutCallback compares a read without options to one with a no-op callback on valid and invalid input. Output was checked against git config -l. go vet and go test ./... pass.

    Release note

    gcfg: add ReadWithOptions and WithCallback. The callback receives an Event that reports, via HasSubsection, whether a header had a subsection, so [x] and [x ""] can be told apart, and, via Position, where the header or option is.

    Diff: 461 lines (+345 / -116) across 5 files Reviewer: pjbgf Review duration: 610m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.46) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 461 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.367
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #19"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.6% (MEDIUM) · Higher = larger blast radius
    45.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.7% · Safe to merge
    19.7%
    Repository