Migration
This is my new public git source viewer. Source coming soon. Please contact with concerns/bugs.
Contact me
internal/site/request.go
cb5a7c7c656de5a381e0234208c552c0856e43e3
· 748 B · 28 lines
raw
| 1 | package site |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "strings" |
| 6 | |
| 7 | "gsg/internal/core" |
| 8 | ) |
| 9 | |
| 10 | // CompareRequest parses {range} into the base and head refs. The refs are |
| 11 | // still resolved by core through gitx.Repo.Resolve; this only splits text. |
| 12 | func CompareRequest(r *http.Request) (core.Request, error) { |
| 13 | rng := r.PathValue("range") |
| 14 | // Check three dots first: "a...b" also contains "..". |
| 15 | if base, head, ok := strings.Cut(rng, "..."); ok { |
| 16 | return core.Request{ |
| 17 | Ref: head, |
| 18 | Range: &core.Range{Base: base, ThreeDot: true}, |
| 19 | }, nil |
| 20 | } |
| 21 | if base, head, ok := strings.Cut(rng, ".."); ok { |
| 22 | return core.Request{ |
| 23 | Ref: head, |
| 24 | Range: &core.Range{Base: base}, |
| 25 | }, nil |
| 26 | } |
| 27 | return core.Request{}, core.Errorf(http.StatusBadRequest, "compare needs base..head") |
| 28 | } |