package web
import (
"context"
"encoding/json"
"errors"
"fmt"
"html/template"
"net/http"
"strings"
"github.com/go-chi/chi/v5"
"github.com/sirupsen/logrus"
"sourcecraft.dev/bigbes/sr-ht-ecore/chrome"
"sourcecraft.dev/bigbes/sr-ht-compare/authz"
"sourcecraft.dev/bigbes/sr-ht-compare/core"
"sourcecraft.dev/bigbes/sr-ht-compare/gitx"
)
// recentCommitLimit bounds the first-parent history shown on the repo page.
const recentCommitLimit = 20
// compareLogLimit bounds the commit list on the compare page.
const compareLogLimit = 50
// ---- JSON transport (consumed by the front-end bundle) --------------------
// jsonFile mirrors one gitx.FileChange for the browser. path is the plain repo
// path with NO a/ or b/ prefix.
type jsonFile struct {
Path string `json:"path"`
OldPath string `json:"oldPath"`
Status string `json:"status"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
Binary bool `json:"binary"`
}
type jsonSpec struct {
Base string `json:"base"`
Head string `json:"head"`
ThreeDot bool `json:"threeDot"`
}
type compareData struct {
Mode string `json:"mode"`
Patch string `json:"patch"`
Truncated bool `json:"truncated"`
Files []jsonFile `json:"files"`
Spec jsonSpec `json:"spec"`
}
// buildCompareJSON marshals the browser payload. json.Marshal escapes <, > and &
// (Go's default HTML-safe mode), so the result is safe to drop verbatim inside a
// ". The bytes are
// returned as template.JS: any