2024-11-27 14:41:57 -06:00
|
|
|
package gitpb
|
|
|
|
|
|
|
|
import (
|
2024-11-27 21:40:06 -06:00
|
|
|
"errors"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
2024-11-27 14:41:57 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// scans in a new git repo. If it detects the repo is a golang project,
|
|
|
|
// then it parses the go.mod/go.sum files
|
|
|
|
// TODO: try adding python, rails, perl, rust, other language things?
|
|
|
|
// I probably will never have time to try that, but I'd take patches for anyone
|
|
|
|
// that might see this note and feel so inclined.
|
2024-12-17 00:00:49 -06:00
|
|
|
// todo: use Repos.Lock() ?
|
|
|
|
func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) {
|
2024-12-03 00:35:50 -06:00
|
|
|
if gopath == "" {
|
|
|
|
return nil, errors.New("blank gopath")
|
|
|
|
}
|
2024-11-27 14:55:39 -06:00
|
|
|
if r := all.FindByGoPath(gopath); r != nil {
|
2024-12-15 08:48:42 -06:00
|
|
|
log.Info("gitpb.NewGoPath() already has gopath", r.GoPath)
|
|
|
|
log.Info("gitpb.NewGoPath() already has FullPath", r.FullPath)
|
2024-11-27 14:41:57 -06:00
|
|
|
// already had this gopath
|
2024-12-07 16:50:26 -06:00
|
|
|
return r, errors.New("gitpb.NewGoPath() duplicate gopath " + gopath)
|
2024-11-27 21:40:06 -06:00
|
|
|
}
|
|
|
|
|
2024-11-27 14:41:57 -06:00
|
|
|
// add a new one here
|
|
|
|
newr := Repo{
|
2024-12-17 00:00:49 -06:00
|
|
|
FullPath: fullpath,
|
2024-12-16 00:21:08 -06:00
|
|
|
}
|
2024-12-17 01:15:31 -06:00
|
|
|
newr.Times = new(GitTimes)
|
|
|
|
|
2024-12-17 00:00:49 -06:00
|
|
|
newr.GoInfo = new(GoInfo)
|
|
|
|
newr.GoInfo.GoPath = gopath
|
2024-12-16 00:21:08 -06:00
|
|
|
|
2024-12-03 00:35:50 -06:00
|
|
|
if all.AppendUniqueGoPath(&newr) {
|
|
|
|
// worked
|
|
|
|
return &newr, nil
|
2024-12-16 00:21:08 -06:00
|
|
|
} else {
|
|
|
|
// this is dumb, probably never happens. todo: use Repos.Lock()
|
|
|
|
if r := all.FindByGoPath(gopath); r != nil {
|
|
|
|
// already had this gopath
|
|
|
|
return r, errors.New("gitpb.NewGoPath() AppendUnique() failed but Find() worked" + gopath)
|
|
|
|
}
|
2024-11-27 21:40:06 -06:00
|
|
|
}
|
2024-12-16 00:21:08 -06:00
|
|
|
// todo: use Repos.Lock()
|
2024-12-07 16:50:26 -06:00
|
|
|
return nil, errors.New("repo gitpb.NewGoPath() should never have gotten here " + gopath)
|
2024-11-29 21:51:30 -06:00
|
|
|
}
|