summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--argv.go1
-rw-r--r--doFix.deleteuser.go22
-rw-r--r--doNormal.go4
-rw-r--r--doPull.go16
-rw-r--r--doReload.go3
-rw-r--r--doStats.go41
-rw-r--r--doTag.go16
-rw-r--r--find.go2
-rw-r--r--main.go84
10 files changed, 150 insertions, 42 deletions
diff --git a/README.md b/README.md
index 30a0796..36ed337 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,6 @@
# forge
-forge is a GUI front end for 'git' designed with the
-intent of simplifying federated git development.
+forge is tool to help maintain multiple git repos
## Install:
diff --git a/argv.go b/argv.go
index a2e80ea..4183238 100644
--- a/argv.go
+++ b/argv.go
@@ -67,6 +67,7 @@ type VerifyCmd struct {
type StatsCmd struct {
All *EmptyCmd `arg:"subcommand:all" help:"run on all the repos"`
Reload bool `arg:"--reload" help:"reload refs"`
+ ReloadClean bool `arg:"--reload-clean" help:"clean out all .git/ .pb files"`
CheckRefs bool `arg:"--check-refs" help:"load & check refs"`
CheckRemote bool `arg:"--check-remote" help:"load & check remote log"`
CheckRemoteRefs bool `arg:"--check-remote-refs" help:"load & check remote refs"`
diff --git a/doFix.deleteuser.go b/doFix.deleteuser.go
index f9878d4..da8bb11 100644
--- a/doFix.deleteuser.go
+++ b/doFix.deleteuser.go
@@ -58,12 +58,12 @@ func doFixPrint(s string, path string, cmd string) {
log.Printf("%-13.13s %-55.55s %s\n", s, path, cmd)
}
-func doFixDeleteUserBranches(repo *gitpb.Repo, remoteRef *gitpb.GitTag) *notesList {
+func doFixDeleteUserBranches(repo *gitpb.Repo, remoteRef *gitpb.Stat) *notesList {
// log.Info("delete remote user", repo.FullPath)
localTag := repo.IsBranchLocal(repo.GetUserBranchName())
if localTag != nil {
- // log.Info("THERE IS local user", repo.FullPath, localTag.Refname)
- doFixPrint("LOCAL USER", repo.FullPath, localTag.Refname+" local branch exists")
+ // log.Info("THERE IS local user", repo.FullPath, localTag.Name)
+ doFixPrint("LOCAL USER", repo.FullPath, localTag.Name+" local branch exists")
err, notes := doFixDeleteUserLocalBranch(repo, remoteRef, localTag)
if err != nil {
log.Printf("%-13.13s %-55.55s %v noteslen(%d)\n", "need --fix", repo.FullPath, err, len(notes.all))
@@ -77,10 +77,10 @@ func doFixDeleteUserBranches(repo *gitpb.Repo, remoteRef *gitpb.GitTag) *notesLi
}
// notes.addNote("SAFE", repo, remoteUser, line)
-func (notes *notesList) addNote(note string, repo *gitpb.Repo, ref *gitpb.GitTag, cmd []string, line string) {
+func (notes *notesList) addNote(note string, repo *gitpb.Repo, ref *gitpb.Stat, cmd []string, line string) {
newnote := new(DeleteBranchNotes)
newnote.Note = note
- newnote.Refname = ref.Refname
+ newnote.Name = ref.Name
newnote.Fullpath = repo.FullPath
newnote.Cmd = cmd
parts := strings.Split(line, "%00") // git log doesn't actually convert %00 to NULL
@@ -100,7 +100,7 @@ func (notes *notesList) addNote(note string, repo *gitpb.Repo, ref *gitpb.GitTag
func (notes *notesList) addTextNote(note string, repo *gitpb.Repo, refname string, cmd []string, line string) {
newnote := new(DeleteBranchNotes)
newnote.Note = note
- newnote.Refname = refname
+ newnote.Name = refname
newnote.Fullpath = repo.FullPath
newnote.Cmd = cmd
parts := strings.Split(line, "%00") // git log doesn't actually convert %00 to NULL
@@ -123,7 +123,7 @@ type notesList struct {
type DeleteBranchNotes struct {
Note string
- Refname string
+ Name string
Fullpath string
Cmd []string
// git log variable names
@@ -135,7 +135,7 @@ type DeleteBranchNotes struct {
// git branch -D refs/heads/jcarr
// git update-ref -d refs/heads/jcarr
-func doFixDeleteUserLocalBranch(repo *gitpb.Repo, remoteRef *gitpb.GitTag, localRef *gitpb.GitTag) (error, *notesList) {
+func doFixDeleteUserLocalBranch(repo *gitpb.Repo, remoteRef *gitpb.Stat, localRef *gitpb.Stat) (error, *notesList) {
notes := new(notesList)
// get local user, remote user & local devel branches
@@ -209,7 +209,7 @@ func doFixDeleteUserLocalBranch(repo *gitpb.Repo, remoteRef *gitpb.GitTag, local
// git push --delete origin jcarr
// git push origin :refs/remotes/origin/jcarr
-func doFixDeleteRemoteUserBranch(repo *gitpb.Repo, remoteRef *gitpb.GitTag) (error, *notesList) {
+func doFixDeleteRemoteUserBranch(repo *gitpb.Repo, remoteRef *gitpb.Stat) (error, *notesList) {
notes := new(notesList)
// get remote user & local devel branches
@@ -250,7 +250,7 @@ func doFixDeleteRemoteUserBranch(repo *gitpb.Repo, remoteRef *gitpb.GitTag) (err
}
// deletes local user branch if it's entirely in devel
-func doFixDeleteLocalUserByDevel(repo *gitpb.Repo, localRef *gitpb.GitTag) (error, *notesList) {
+func doFixDeleteLocalUserByDevel(repo *gitpb.Repo, localRef *gitpb.Stat) (error, *notesList) {
notes := new(notesList)
localUser := repo.NewCompareRef(localRef)
@@ -292,7 +292,7 @@ func doFixDeleteLocalUserByDevel(repo *gitpb.Repo, localRef *gitpb.GitTag) (erro
}
// deletes local user branch if it's entirely in master
-func doFixDeleteLocalUserByMaster(repo *gitpb.Repo, localRef *gitpb.GitTag) (error, *notesList) {
+func doFixDeleteLocalUserByMaster(repo *gitpb.Repo, localRef *gitpb.Stat) (error, *notesList) {
notes := new(notesList)
localUser := repo.NewCompareRef(localRef)
diff --git a/doNormal.go b/doNormal.go
index aed713a..e649731 100644
--- a/doNormal.go
+++ b/doNormal.go
@@ -205,10 +205,10 @@ func checkNormalRepoState(repo *gitpb.Repo) error {
return ErrorLocalMasterBranch
}
- if repo.Tags.Master == nil {
+ if repo.MasterStat == nil {
if found := repo.GetRemoteTag(repo.GetMasterBranchName()); found != nil {
// log.Info("found master tag ", repo.FullPath, found)
- repo.Tags.Master = proto.Clone(found).(*gitpb.GitTag)
+ repo.MasterStat = proto.Clone(found).(*gitpb.Stat)
config.SetChanged("repos", true)
} else {
log.Info("not found master tag (Reload() ?)", repo.FullPath)
diff --git a/doPull.go b/doPull.go
index a2e8026..7392749 100644
--- a/doPull.go
+++ b/doPull.go
@@ -17,7 +17,7 @@ func needToUpdateRepo(repo *gitpb.Repo) (*gitpb.Repo, error) {
if repo.Tags == nil {
return nil, nil
}
- if repo.Tags.Master == nil {
+ if repo.MasterStat == nil {
return nil, nil
}
found := me.forge.Repos.FindByNamespace(repo.Namespace)
@@ -27,12 +27,12 @@ func needToUpdateRepo(repo *gitpb.Repo) (*gitpb.Repo, error) {
if found.Tags == nil {
return nil, nil
}
- if found.Tags.Master == nil {
+ if found.MasterStat == nil {
return nil, nil
}
- newtime := repo.Tags.Master.Creatordate.AsTime()
- ourtime := found.Tags.Master.Creatordate.AsTime()
+ newtime := repo.MasterStat.CommitTime.AsTime()
+ ourtime := found.MasterStat.CommitTime.AsTime()
dur := newtime.Sub(ourtime)
if dur < time.Minute {
@@ -41,7 +41,7 @@ func needToUpdateRepo(repo *gitpb.Repo) (*gitpb.Repo, error) {
log.Infof("checking for updates %s %s\n", cobol.FormatDuration(dur), found.Namespace)
/*
dur := time.Since(repo.Tags.Master.Authordate.AsTime())
- when := repo.Tags.Master.Creatordate.AsTime()
+ when := repo.Tags.Master.CommitTime.AsTime()
dur = time.Since(when)
log.Infof("stuff %s age=%s %v\n", repo.Namespace, cobol.FormatDuration(dur), when)
*/
@@ -130,14 +130,14 @@ func doPull() (string, error) {
}
-func findGitTag(repo *gitpb.Repo, hash string) *gitpb.GitTag {
- for _, tag := range repo.Tags.GitTags {
+func findGitTag(repo *gitpb.Repo, hash string) *gitpb.Stat {
+ for _, tag := range repo.Tags.Stats {
if tag.Hash == hash {
return tag
}
// log.Info(i, tag.Hash, tag.Refname, tag)
}
- for i, tag := range repo.Tags.GitTags {
+ for i, tag := range repo.Tags.Stats {
log.Info(hash, i, tag)
}
okExit("")
diff --git a/doReload.go b/doReload.go
index ac57d3c..d5245df 100644
--- a/doReload.go
+++ b/doReload.go
@@ -158,7 +158,8 @@ func makeAllGitStats(r *gitpb.Repo) error {
remoterefs, err := r.MakeRemoteRefs(rmote.Name)
if err != nil {
- return errors.Join(err, errors.New("MakeRemoteRefs() failed"))
+ // return errors.Join(err, errors.New("MakeRemoteRefs() failed"))
+ // return nil // ignore make remote refs errors for now
}
if env.True("resort") {
remoterefs.SaveByHash()
diff --git a/doStats.go b/doStats.go
index e932fc1..d875880 100644
--- a/doStats.go
+++ b/doStats.go
@@ -5,6 +5,9 @@ package main
import (
"errors"
+ "fmt"
+ "os"
+ "path/filepath"
"go.wit.com/lib/env"
"go.wit.com/lib/protobuf/gitpb"
@@ -22,16 +25,36 @@ import (
func doStats(cmd *StatsCmd) (string, error) {
if cmd.All != nil {
- fixed := me.forge.RunOnRepos(me.forge.Repos, doReload)
- if fixed.Len() == 0 {
- return "no git config changes", nil
- }
+ if cmd.Reload {
+ fixed := me.forge.RunOnRepos(me.forge.Repos, doReload)
+ if fixed.Len() == 0 {
+ return "no git config changes", nil
+ }
- // show the changed repos & save cache .pb file
- fixed = fixed.SortActual()
- footer := me.forge.PrintErrorsTB(fixed)
- me.forge.Repos.SaveVerbose()
- return ".git/config problems: " + footer, nil
+ // show the changed repos & save cache .pb file
+ fixed = fixed.SortActual()
+ footer := me.forge.PrintErrorsTB(fixed)
+ me.forge.Repos.SaveVerbose()
+ return ".git/config problems: " + footer, nil
+ }
+ if cmd.ReloadClean {
+ var counter int
+ for repo := range me.forge.Repos.IterAll() {
+ os.Chdir(repo.FullPath)
+ globPattern := ".git/*.pb"
+ files, err := filepath.Glob(globPattern)
+ if err != nil {
+ log.Info("glob error", err, files)
+ continue
+ }
+ for _, filename := range files {
+ log.Info("DELETE", filename)
+ counter += 1
+ os.Remove(filename)
+ }
+ }
+ return fmt.Sprintf("cleaned %d pb files", counter), nil
+ }
}
repo := workingDirToRepo()
diff --git a/doTag.go b/doTag.go
index 0d8bed2..09c22a6 100644
--- a/doTag.go
+++ b/doTag.go
@@ -83,15 +83,15 @@ func doTag() error {
return nil
}
-func makeTagTablePB(repo *gitpb.Repo, pb *gitpb.GitTags) *gitpb.GitTagsTable {
+func makeTagTablePB(repo *gitpb.Repo, pb *gitpb.Stats) *gitpb.StatsTable {
t := pb.NewTable("tagList")
t.NewUuid()
col := t.AddHash()
col.Width = 12
- col = t.AddStringFunc("bashash", func(tag *gitpb.GitTag) string {
- _, base := filepath.Split(tag.Refname)
+ col = t.AddStringFunc("bashash", func(tag *gitpb.Stat) string {
+ _, base := filepath.Split(tag.Name)
cmd, err := repo.RunStrict([]string{"git", "log", "-1", base, "--format=%H"})
if err != nil {
return "err"
@@ -103,20 +103,20 @@ func makeTagTablePB(repo *gitpb.Repo, pb *gitpb.GitTags) *gitpb.GitTagsTable {
})
col.Width = 12
- col = t.AddTimeFunc("ctime", func(tag *gitpb.GitTag) time.Time {
+ col = t.AddTimeFunc("ctime", func(tag *gitpb.Stat) time.Time {
// todo
- return tag.Creatordate.AsTime()
+ return tag.CommitTime.AsTime()
})
col.Width = 4
- col = t.AddTimeFunc("age", func(repo *gitpb.GitTag) time.Time {
+ col = t.AddTimeFunc("age", func(repo *gitpb.Stat) time.Time {
// todo
return time.Now()
})
col.Width = 4
- col = t.AddStringFunc("Ref Name", func(r *gitpb.GitTag) string {
- _, ref := filepath.Split(r.GetRefname())
+ col = t.AddStringFunc("Ref Name", func(r *gitpb.Stat) string {
+ _, ref := filepath.Split(r.GetName())
return ref
})
col.Width = 16
diff --git a/find.go b/find.go
index f3c84a4..44e100f 100644
--- a/find.go
+++ b/find.go
@@ -245,7 +245,7 @@ func cloneReposWithPatches() *gitpb.Repos {
stop += 1
if stop < 5 {
for t := range repo.Tags.IterAll() {
- log.Info("pb thinks it has:", repo.Namespace, t.Refname)
+ log.Info("pb thinks it has:", repo.Namespace, t.Name)
}
} else {
if argv.Fix {
diff --git a/main.go b/main.go
index 49eefc9..cc3d81b 100644
--- a/main.go
+++ b/main.go
@@ -7,9 +7,12 @@ package main
import (
"embed"
+ "errors"
+ "path/filepath"
"go.wit.com/lib/protobuf/argvpb"
"go.wit.com/lib/protobuf/forgepb"
+ "go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
@@ -18,6 +21,76 @@ import (
//go:embed resources/*
var resources embed.FS
+func findTagname(stats *gitpb.Stats, brname string) *gitpb.Stat {
+ ref := stats.FindByName(brname)
+ if ref != nil {
+ return ref
+ }
+ ref = stats.FindByName(filepath.Join("refs/heads", brname))
+ if ref != nil {
+ return ref
+ }
+ // for r := range stats.IterAll() {
+ // if strings.HasPrefix(r.Name, "refs/tags/") {
+ // continue
+ // }
+ // log.Printf("brname(%s) ref(%s)\n", brname, r.Name)
+ // }
+ return nil
+}
+
+// true if something changed
+func setStats(repo *gitpb.Repo) error {
+ var err error
+ stats, err := repo.LoadRefs()
+ if err != nil {
+ log.Printf("%s LoadRefs() err(%v)\n", stats.Filename, err)
+ return err
+ }
+ // log.Printf("%s LoadRefs() len(%d)\n", stats.Filename, stats.Len())
+
+ var brname string
+ var ref *gitpb.Stat
+ // brname = me.forge.Config.FindMasterBranch(repo.Namespace)
+ brname = repo.GetMasterBranchName()
+ ref = findTagname(stats, brname)
+ if repo.MasterStat == nil {
+ if ref != nil {
+ err = errors.New("master stat was nil")
+ }
+ }
+ repo.MasterStat = ref
+
+ // brname = me.forge.Config.FindDevelBranch(repo.Namespace)
+ brname = repo.GetDevelBranchName()
+ ref = findTagname(stats, brname)
+ if repo.DevelStat == nil {
+ if ref != nil {
+ err = errors.New("devel stat was nil")
+ }
+ }
+ repo.DevelStat = ref
+
+ // brname = me.forge.Config.FindUserBranch(repo.Namespace)
+ brname = repo.GetUserBranchName()
+ ref = findTagname(stats, brname)
+ if repo.UserStat == nil {
+ if ref != nil {
+ err = errors.New("user stat was nil")
+ }
+ }
+ repo.UserStat = ref
+ if repo.Tags.Len() != stats.Len() {
+ log.Printf("tags Tags.len(%d) vs stats.Len(%d)\n", repo.Tags.Len(), stats.Len())
+ repo.Tags = stats
+ err = errors.New("adding stats to repo.Tags")
+ } else {
+ // log.Printf("tags already here with len(%d)\n", repo.Tags.Len())
+ }
+
+ return err
+}
+
func doCoreChecks() {
me.forge.RescanRepos() // looks for new dirs, checks existing repos for changes
@@ -38,6 +111,17 @@ func doCoreChecks() {
dumpDebug()
}
}
+
+ var trip bool
+ for repo := range me.forge.Repos.IterAll() {
+ if err := setStats(repo); err != nil {
+ log.Printf("%s err(%v)\n", repo.Namespace, err)
+ trip = true
+ }
+ }
+ if trip {
+ me.forge.Repos.SaveVerbose()
+ }
}
func main() {