diff options
| author | Jeff Carr <[email protected]> | 2024-12-17 00:00:49 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-12-17 00:00:49 -0600 |
| commit | c53da5a9a1da1b29db24d4e1ce2b294514d99ac2 (patch) | |
| tree | c39b33f43d5be87313b3c0aa0c7bb7c58b2f72b6 /repo.new.go | |
| parent | a115ba144b00dc0339a8cf7eae6bdf2aab5fb4b5 (diff) | |
smarter and faster mtime logic
Diffstat (limited to 'repo.new.go')
| -rw-r--r-- | repo.new.go | 78 |
1 files changed, 5 insertions, 73 deletions
diff --git a/repo.new.go b/repo.new.go index fa1d258..10b5fcb 100644 --- a/repo.new.go +++ b/repo.new.go @@ -2,12 +2,8 @@ package gitpb import ( "errors" - "os" - "path/filepath" - "time" "go.wit.com/log" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) // scans in a new git repo. If it detects the repo is a golang project, @@ -15,52 +11,24 @@ import ( // 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. -func (all *Repos) NewGoPath(basepath string, gopath string, url string) (*Repo, error) { +// 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) - log.Info("gitpb.NewGoPath() already has URL", r.URL) // already had this gopath return r, errors.New("gitpb.NewGoPath() duplicate gopath " + gopath) } - log.Info("gitpb.NewGoPath() Attempting to add new path", basepath, gopath) - - // if .git doesn't exist, error out here - gitpath := filepath.Join(basepath, gopath, ".git") - _, err := os.Stat(gitpath) - if err != nil { - log.Warn("gitpb.NewGoPath() not a git directory", gitpath) - return nil, err - } // add a new one here newr := Repo{ - FullPath: filepath.Join(basepath, gopath), - GoPath: gopath, - URL: url, - } - newr.Tags = new(GitTags) - newr.UpdateGitTags() - newr.GoDeps = new(GoDeps) - - switch newr.goListRepoType() { - case "plugin": - newr.GoPlugin = true - case "protobuf": - newr.GoProtobuf = true - case "library": - newr.GoLibrary = true - case "binary": - newr.GoBinary = true - } - - lastpull, err := newr.LastGitPull() - if err == nil { - newr.LastPull = timestamppb.New(lastpull) + FullPath: fullpath, } + newr.GoInfo = new(GoInfo) + newr.GoInfo.GoPath = gopath if all.AppendUniqueGoPath(&newr) { // worked @@ -75,39 +43,3 @@ func (all *Repos) NewGoPath(basepath string, gopath string, url string) (*Repo, // todo: use Repos.Lock() return nil, errors.New("repo gitpb.NewGoPath() should never have gotten here " + gopath) } - -func (repo *Repo) SetDevelBranchName(bname string) { - repo.DevelBranchName = bname -} - -func (repo *Repo) SetUserBranchName(bname string) { - repo.UserBranchName = bname -} - -func (repo *Repo) GitChanged() bool { - fullfile := filepath.Join(repo.FullPath, ".git/FETCH_HEAD") - lasttime, err := repo.LastGitPull() - if err == nil { - // if error, something is wrong, assume true - log.Info("gitpb:", fullfile, "changed") - return true - } - newtime := repo.LastPull.AsTime() - - if lasttime == newtime { - return false - } - log.Info("gitpb:", fullfile, "changed") - return true -} - -func (repo *Repo) GitPullAge() time.Duration { - lastpull, err := repo.LastGitPull() - if err == nil { - // if error, something is wrong, assume true - ltime := repo.LastPull.AsTime() - return time.Since(ltime) - } - - return time.Since(lastpull) -} |
