package gitpb import ( "errors" "go.wit.com/log" ) // 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. // todo: use Repos.Lock() ? func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) { if gopath == "" { return nil, errors.New("blank gopath") } if r := all.FindByGoPath(gopath); r != nil { log.Info("gitpb.NewGoPath() already has gopath", r.GoPath) log.Info("gitpb.NewGoPath() already has FullPath", r.FullPath) // already had this gopath return r, errors.New("gitpb.NewGoPath() duplicate gopath " + gopath) } // add a new one here newr := Repo{ FullPath: fullpath, } newr.Times = new(GitTimes) newr.GoInfo = new(GoInfo) newr.GoInfo.GoPath = gopath if all.AppendUniqueGoPath(&newr) { // worked return &newr, nil } 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) } } // todo: use Repos.Lock() return nil, errors.New("repo gitpb.NewGoPath() should never have gotten here " + gopath) }