package site import ( "net/http" "strings" "gsg/internal/core" ) // CompareRequest parses {range} into the base and head refs. The refs are // still resolved by core through gitx.Repo.Resolve; this only splits text. func CompareRequest(r *http.Request) (core.Request, error) { rng := r.PathValue("range") // Check three dots first: "a...b" also contains "..". if base, head, ok := strings.Cut(rng, "..."); ok { return core.Request{ Ref: head, Range: &core.Range{Base: base, ThreeDot: true}, }, nil } if base, head, ok := strings.Cut(rng, ".."); ok { return core.Request{ Ref: head, Range: &core.Range{Base: base}, }, nil } return core.Request{}, core.Errorf(http.StatusBadRequest, "compare needs base..head") }