diff --git a/util.go b/util.go index 5c6e41e..abb0a68 100644 --- a/util.go +++ b/util.go @@ -6,12 +6,10 @@ import ( "encoding/hex" "fmt" "io" - "log/slog" "math/rand" "regexp" "strconv" "strings" - "time" "github.com/bluekeyes/go-gitdiff/gitdiff" "github.com/charmbracelet/ssh" @@ -211,112 +209,3 @@ func calcContentSha(diffFiles []*gitdiff.File, header *gitdiff.PatchHeader) stri shaStr := hex.EncodeToString(sha[:]) return shaStr } - -func AuthorDateToTime(date string, logger *slog.Logger) time.Time { - // TODO: convert sql column to DATETIME - ds, err := time.Parse("2006-01-02T15:04:05Z", date) - if err != nil { - logger.Error( - "cannot parse author date for patch", - "datetime", date, - "err", err, - ) - return time.Now() - } - return ds -} - -/* func filterPatches(ranger *Ranger, patches []*Patch) []*Patch { - if ranger.Left == ranger.Right { - return []*Patch{patches[ranger.Left]} - } - return patches[ranger.Left:ranger.Right] -} - -type Ranger struct { - Left int - Right int -} - -func parseRange(rnge string, sliceLen int) (*Ranger, error) { - items := strings.Split(rnge, ":") - left := 0 - var err error - if items[0] != "" { - left, err = strconv.Atoi(items[0]) - if err != nil { - return nil, fmt.Errorf("first value before `:` must provide number") - } - } - - if left < 0 { - return nil, fmt.Errorf("first value must be >= 0") - } - - if left >= sliceLen { - return nil, fmt.Errorf("first value must be less than number of patches") - } - - if len(items) == 1 { - return &Ranger{ - Left: left, - Right: left, - }, nil - } - - if items[1] == "" { - return &Ranger{Left: left, Right: sliceLen - 1}, nil - } - - right, err := strconv.Atoi(items[1]) - if err != nil { - return nil, fmt.Errorf("second value after `:` must provide number") - } - - if left > right { - return nil, fmt.Errorf("second value must be greater than first value") - } - - if right >= sliceLen { - return nil, fmt.Errorf("second value must be less than number of patches") - } - - return &Ranger{ - Left: left, - Right: right, - }, nil -} */ - -/* func gitServiceCommands(sesh ssh.Session, be *Backend, cmd, repoName string) error { - name := utils.SanitizeRepo(repoName) - // git bare repositories should end in ".git" - // https://git-scm.com/docs/gitrepository-layout - repoID := be.RepoID(name) - reposDir := be.ReposDir() - err := git.EnsureWithin(reposDir, repoID) - if err != nil { - return err - } - repoPath := filepath.Join(reposDir, repoID) - serviceCmd := git.ServiceCommand{ - Stdin: sesh, - Stdout: sesh, - Stderr: sesh.Stderr(), - Dir: repoPath, - Env: sesh.Environ(), - } - - if cmd == "git-receive-pack" { - err := git.ReceivePack(sesh.Context(), serviceCmd) - if err != nil { - return err - } - } else if cmd == "git-upload-pack" { - err := git.UploadPack(sesh.Context(), serviceCmd) - if err != nil { - return err - } - } - - return nil -} */