ideas on code structure
This commit is contained in:
parent
cedd7ea6f1
commit
c51b8c96b1
|
@ -1,7 +1,6 @@
|
||||||
package gitpb
|
package gitpb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -11,21 +10,17 @@ import (
|
||||||
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
|
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// this is becoming a standard format
|
// Update repo.Refs from .git/
|
||||||
// todo: autogenerate this from the .proto file?
|
func (repo *Repo) UpdateGit() error {
|
||||||
|
|
||||||
// Update version and timestamp.
|
|
||||||
// returns ok (ok == true if not found)
|
|
||||||
func (r *Repo) Update() error {
|
|
||||||
// delete the old hash
|
// delete the old hash
|
||||||
// r.DeleteByHash(hash)
|
// r.DeleteByHash(hash)
|
||||||
r.Refs = nil
|
repo.Refs = nil
|
||||||
|
|
||||||
tags := []string{"%(objectname)", "%(creatordate)", "%(*authordate)", "%(refname)", "%(subject)"}
|
tags := []string{"%(objectname)", "%(creatordate)", "%(*authordate)", "%(refname)", "%(subject)"}
|
||||||
format := strings.Join(tags, "_,,,_")
|
format := strings.Join(tags, "_,,,_")
|
||||||
cmd := []string{"git", "for-each-ref", "--sort=taggerdate", "--format", format}
|
cmd := []string{"git", "for-each-ref", "--sort=taggerdate", "--format", format}
|
||||||
// log.Info("RUNNING:", strings.Join(cmd, " "))
|
// log.Info("RUNNING:", strings.Join(cmd, " "))
|
||||||
result := shell.PathRunQuiet(r.FullPath, cmd)
|
result := shell.PathRunQuiet(repo.FullPath, cmd)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
log.Warn("git for-each-ref error:", result.Error)
|
log.Warn("git for-each-ref error:", result.Error)
|
||||||
return result.Error
|
return result.Error
|
||||||
|
@ -63,7 +58,7 @@ func (r *Repo) Update() error {
|
||||||
Ctime: timestamppb.New(ctime),
|
Ctime: timestamppb.New(ctime),
|
||||||
}
|
}
|
||||||
|
|
||||||
r.AppendRef(&newr)
|
repo.AppendRef(&newr)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,24 +74,3 @@ func getGitDateStamp(gitdefault string) time.Time {
|
||||||
}
|
}
|
||||||
return tagTime
|
return tagTime
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
|
||||||
func (r *Repos) InitNewGoPath(basepath string, gopath string) *Repo {
|
|
||||||
if oldr := r.FindByPath(gopath); oldr != nil {
|
|
||||||
// already had this gopath
|
|
||||||
return oldr
|
|
||||||
}
|
|
||||||
// add a new one here
|
|
||||||
newr := Repo{
|
|
||||||
FullPath: filepath.Join(basepath, gopath),
|
|
||||||
GoPath: gopath,
|
|
||||||
}
|
|
||||||
newr.Update()
|
|
||||||
|
|
||||||
r.Append(&newr)
|
|
||||||
return &newr
|
|
||||||
}
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package gitpb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
func (r *Repos) InitNewGoPath(basepath string, gopath string) *Repo {
|
||||||
|
if oldr := r.FindByPath(gopath); oldr != nil {
|
||||||
|
// already had this gopath
|
||||||
|
return oldr
|
||||||
|
}
|
||||||
|
// add a new one here
|
||||||
|
newr := Repo{
|
||||||
|
FullPath: filepath.Join(basepath, gopath),
|
||||||
|
GoPath: gopath,
|
||||||
|
}
|
||||||
|
newr.UpdateGit()
|
||||||
|
|
||||||
|
r.Append(&newr)
|
||||||
|
return &newr
|
||||||
|
}
|
Loading…
Reference in New Issue