work on "forge pull"

This commit is contained in:
Jeff Carr 2025-09-07 12:05:36 -05:00
parent 3df2601f27
commit db758bbed2
6 changed files with 104 additions and 152 deletions

View File

@ -175,11 +175,16 @@ func drawWindow(win *gadgets.GenericWindow) {
}) })
var patchesWin *stdPatchTableWin var patchesWin *stdPatchTableWin
gridM.NewButton("Your patches", func() { var patchButton *gui.Node
patchButton = gridM.NewButton("Your patches", func() {
if patchesWin != nil { if patchesWin != nil {
patchesWin.Toggle() patchesWin.Toggle()
return return
} }
if !isPatchingSafe() {
patchButton.SetLabel("not safe yet")
return
}
// patchesWin = makePatchesWin(me.forge.Patchsets) // patchesWin = makePatchesWin(me.forge.Patchsets)
notdone := new(forgepb.Patches) notdone := new(forgepb.Patches)

View File

@ -33,6 +33,10 @@ func doNormal() bool {
} }
if count > 0 { if count > 0 {
log.Info("Some repos are not in a 'normal' state. error count =", count) log.Info("Some repos are not in a 'normal' state. error count =", count)
log.Info("TODO: list the repos here. forge patch repos?")
configSave = false
me.forge.SetConfigSave(false)
dumpDirtyRepos()
return false return false
} }
return true return true

View File

@ -27,10 +27,21 @@ func doPatchInit() {
} }
} }
func isPatchingSafe() bool {
if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL {
return true
}
log.Info("forge requres a 'normal' state to work with patches")
log.Info("you must run:")
log.Info("")
log.Info("forge normal")
log.Info("")
return false
}
func doPatch() error { func doPatch() error {
if me.forge.Config.Mode != forgepb.ForgeMode_NORMAL { if !isPatchingSafe() {
log.Info("forge requres a 'normal' state to work with patches") return log.Errorf("not safe to work on patches")
return log.Errorf("not in 'normal' forge state")
} }
if argv.Patch.Submit != nil { if argv.Patch.Submit != nil {
@ -194,12 +205,12 @@ func IsValidPatch(p *forgepb.Patch) bool {
log.Info("can not apply patch! repo not found", basepath, filename) log.Info("can not apply patch! repo not found", basepath, filename)
return false return false
} }
if repo.DevelHash() != p.StartHash { if repo.ActualDevelHash() != p.StartHash {
log.Info("can not apply patch! devel hash mismatch", basepath, filename) log.Info("can not apply patch! devel hash mismatch", basepath, filename)
return false return false
} }
if repo.DevelHash() == p.StartHash { if repo.ActualDevelHash() == p.StartHash {
log.Info("local devel hash:", repo.DevelHash(), "matches patch hash", p.StartHash, "and can be applied") log.Info("local devel hash:", repo.ActualDevelHash(), "matches patch hash", p.StartHash, "and can be applied")
} }
log.Info("start:", p.StartHash, "end:", p.CommitHash, "file:", basepath, filename, "devel version", repo.GetDevelVersion()) log.Info("start:", p.StartHash, "end:", p.CommitHash, "file:", basepath, filename, "devel version", repo.GetDevelVersion())
for _, line := range p.Files { for _, line := range p.Files {

162
doPull.go
View File

@ -4,156 +4,38 @@
package main package main
import ( import (
"fmt" "go.wit.com/lib/protobuf/forgepb"
"time"
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/gitpb" "go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log" "go.wit.com/log"
) )
func rillPull(repo *gitpb.Repo) error {
if repo.IsDirty() {
// never do dirty repos
return nil
}
t, _ := repo.LastGitPull()
if time.Since(t) < time.Minute*10 && !argv.Force {
if argv.Verbose {
log.Info(repo.GetFullPath(), "git pulled too recently", shell.FormatDuration(time.Since(t)))
}
return nil
}
cur := repo.GetCurrentBranchName()
if !repo.IsBranchRemote(cur) {
if argv.Verbose {
log.Info(repo.GetFullPath(), "branch is not remote", cur)
}
return nil
}
var cmd []string
cmd = append(cmd, "git", "pull")
err := repo.RunVerbose(cmd)
if err != nil {
log.Info(repo.GetFullPath(), "git pull err:", err)
}
return nil
}
// is every repo on the devel branch? // is every repo on the devel branch?
func doGitPull() error { func doGitPull() error {
if argv.Pull == nil { if me.forge.Config.Mode != forgepb.ForgeMode_MASTER {
return fmt.Errorf("not really 'fetch pull'") if argv.Force == true {
} log.Info("okay. you have forced the issue")
} else {
if argv.Force { log.Info("forge requres being on the master branch")
now := time.Now() log.Info("you must run:")
stats := me.forge.RillFuncError(rillPull) log.Info("")
count := me.forge.RillReload() log.Info("forge checkout master")
if count != 0 { log.Info("")
me.forge.ConfigSave() return nil
} }
total, count, nope, _ := me.forge.IsEverythingOnMaster()
log.Printf("Master branch check. %d total repos. (%d git pulled) (%d not on master branch) (%s) git pull total=FIXME%d\n", total, count, nope, shell.FormatDuration(time.Since(now)), len(stats))
return nil
} }
check := gitpb.NewRepos() // stats := me.forge.RillFuncError(rillPull)
log.Info("TODO: actually git pull here? this is a bad idea. stopping.")
if argv.Pull.Dirty != nil { submit := gitpb.NewRepos()
check = me.forge.FindDirty() for repo := range me.forge.Repos.IterByFullPath() {
} newrepo := new(gitpb.Repo)
newrepo.MasterHash = repo.MasterHash
if argv.Pull.Patches != nil { newrepo.DevelHash = repo.DevelHash
check = findReposWithPatches() newrepo.Namespace = repo.Namespace
} newrepo.URL = repo.URL
submit.Append(newrepo)
if argv.Pull.Check != nil {
// TODO: never wrote this yet
// update, err := me.forge.CheckVersions()
// return err
return nil
}
if check.Len() == 0 {
// check = doFind()
check = findAll()
// check = find50()
// check = findMine()
}
me.forge.PrintHumanTableFull(check)
if argv.Pull.Dirty != nil {
log.Info("dirty count =", check.Len())
return nil
}
found, err := me.forge.LookupPB(check)
if err != nil {
log.Info("LookupPB() failed", err, "len(check)=", check.Len())
return err
}
// me.forge.PrintHumanTableFull(found)
// check to see if the repos need to be updated
update := gitpb.NewRepos()
if found.Len() == 0 {
return nil
}
log.Info("found.Len() ==", found.Len())
for repo := range found.IterAll() {
masterb := repo.GetMasterBranchName()
if masterb == "" {
log.Info(repo.GetNamespace(), "master branch blank")
continue
}
a := repo.GetLocalHash(masterb)
ns := repo.GetNamespace()
repo2 := me.forge.Repos.FindByNamespace(ns)
if repo2 == nil {
log.Info("repo namespace does not exist", a, repo.Namespace)
continue
}
b := repo2.GetLocalHash(repo2.GetMasterBranchName())
if b == a {
continue
}
log.Info(a, "!=", b, repo.Namespace)
update.AppendByNamespace(repo2)
}
if update.Len() == 0 {
// nothing to update
return nil
}
if _, err := me.forge.UpdatePB(update); err != nil {
log.Info("UpdatePB() failed", err, "len(check)=", update.Len())
return err
} }
submit.HttpPost(myServer(), "check")
return nil return nil
} }
// git fetch origin master:master
func rillFetchMaster(repo *gitpb.Repo) error {
if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
// only fetch when branch is on the user branch
return nil
}
branch := repo.GetMasterBranchName()
cmd := []string{"git", "fetch", "origin", branch + ":" + branch}
err := repo.RunVerbose(cmd)
return err
}
func doGitFetch() {
me.forge.RillFuncError(rillFetchMaster)
count := me.forge.RillReload()
if count != 0 {
me.forge.ConfigSave()
}
}

55
doPullOld.go Normal file
View File

@ -0,0 +1,55 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
/*
func rillPull(repo *gitpb.Repo) error {
if repo.IsDirty() {
// never do dirty repos
return nil
}
t, _ := repo.LastGitPull()
if time.Since(t) < time.Minute*10 && !argv.Force {
if argv.Verbose {
log.Info(repo.GetFullPath(), "git pulled too recently", shell.FormatDuration(time.Since(t)))
}
return nil
}
cur := repo.GetCurrentBranchName()
if !repo.IsBranchRemote(cur) {
if argv.Verbose {
log.Info(repo.GetFullPath(), "branch is not remote", cur)
}
return nil
}
var cmd []string
cmd = append(cmd, "git", "pull")
err := repo.RunVerbose(cmd)
if err != nil {
log.Info(repo.GetFullPath(), "git pull err:", err)
}
return nil
}
// git fetch origin master:master
func rillFetchMaster(repo *gitpb.Repo) error {
if repo.GetCurrentBranchName() != repo.GetUserBranchName() {
// only fetch when branch is on the user branch
return nil
}
branch := repo.GetMasterBranchName()
cmd := []string{"git", "fetch", "origin", branch + ":" + branch}
err := repo.RunVerbose(cmd)
return err
}
func doGitFetch() {
me.forge.RillFuncError(rillFetchMaster)
count := me.forge.RillReload()
if count != 0 {
me.forge.ConfigSave()
}
}
*/

View File

@ -186,11 +186,6 @@ func main() {
okExit("") okExit("")
} }
if argv.GitFetch != nil {
doGitFetch()
okExit("")
}
if argv.Merge != nil { if argv.Merge != nil {
if argv.Merge.Devel != nil { if argv.Merge.Devel != nil {
start := time.Now() start := time.Now()