Compare commits

..

No commits in common. "master" and "v0.0.41" have entirely different histories.

8 changed files with 31 additions and 145 deletions

View File

@ -1,12 +1,10 @@
.PHONY: build
VERSION = $(shell git describe --tags)
# BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
BUILDTIME = $(shell date +%s)
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
all: build
FORGE_VERBOSE=true ./forged clean
# FORGE_VERBOSE=true ./forged list
all: build-verbose
./forged list
build: goimports
GO111MODULE=off go build \

53
argv.go
View File

@ -8,12 +8,6 @@ package main
import (
"fmt"
"os"
"strconv"
"strings"
"time"
"go.wit.com/lib/gui/prep"
"go.wit.com/lib/gui/shell"
)
var argv args
@ -21,7 +15,6 @@ var argv args
type args struct {
Pull *EmptyCmd `arg:"subcommand:pull" help:"'git pull' on the repos"`
List *EmptyCmd `arg:"subcommand:list" help:"list the repos"`
Clean *EmptyCmd `arg:"subcommand:clean" help:"clean the repos"`
Gui *EmptyCmd `arg:"subcommand:gui" help:"show gui"`
Merge *EmptyCmd `arg:"subcommand:merge" help:"merge in new patchsets"`
Init *EmptyCmd `arg:"subcommand:init" help:"init the repo list"`
@ -36,51 +29,17 @@ type args struct {
type EmptyCmd struct {
}
func (args) Appname() string {
return ARGNAME
}
func (args) Version() string {
parts := strings.Split(BUILDTIME, ".")
if len(parts) == 1 {
// The input epoch seconds
// epochSeconds := int64(1758646486)
num, err := strconv.Atoi(BUILDTIME)
epochSeconds := int64(num)
if err == nil {
// 1. Convert the epoch seconds to a time.Time object.
// time.Unix() creates the time in the UTC timezone by default.
t := time.Unix(epochSeconds, 0)
// 2. Convert the UTC time to the computer's local timezone.
localTime := t.Local()
// 3. Print the result. The default format is clear and includes the timezone.
// fmt.Println("Default format:", localTime)
// For a more human-friendly format, use the Format() method.
// Go uses a special reference time for formatting: Mon Jan 2 15:04:05 2006 MST
// You lay out your desired format using these specific numbers.
// formattedString := localTime.Format("Monday, January 2, 2006 at 3:04:05 PM (MST)")
// fmt.Println(" Custom format:", formattedString)
// now := time.Now()
// dur := time.Since(localTime)
BUILDTIME = fmt.Sprintf("%s age(%v)", localTime.String(), shell.FormatDuration(time.Since(localTime)))
}
}
return ARGNAME + " " + VERSION + " Built on " + BUILDTIME
}
func (a args) DoAutoComplete(pb *prep.Auto) {
switch pb.Cmd {
case "list":
pb.Autocomplete2("--missing")
case "clean":
pb.Autocomplete2("")
func (a args) DoAutoComplete(argv []string) {
// argv.doBashHelp()
switch argv[0] {
case "merge":
fmt.Println("--force")
default:
pb.Autocomplete2("list clean")
fmt.Println("list merge repos")
}
os.Exit(0)
}

View File

@ -6,27 +6,15 @@ import (
)
func doList() error {
log.Infof("do list here. Patchsets.Len()=%d\n", me.forge.Patchsets.Len())
for pset := range me.forge.Patchsets.IterAll() {
pset.PrintTable()
}
return nil
}
log.Info("do list here")
func doClean() error {
log.Infof("clean Patchsets.Len()=%d\n", me.forge.Patchsets.Len())
// show all the patchsets with Names
for pset := range me.forge.Patchsets.IterAll() {
for patch := range pset.Patches.IterAll() {
if patch.PatchId == "" {
log.Info("Delete", patch.CommitHash, patch.PatchId, patch.Namespace)
pset.Patches.Delete(patch)
} else {
log.Info("\t", patch.CommitHash, patch.PatchId, patch.Namespace)
}
log.Info("Info", pset.Name, pset.Uuid)
for i, patch := range pset.Patches.Patches {
log.Info("\t", i, patch.CommitHash, patch.Namespace)
}
}
me.forge.SavePatchsets()
return nil
}

View File

@ -21,7 +21,7 @@ func doMerge() error {
return nil
}
func findAutoPatchset() *forgepb.Set {
func findAutoPatchset() *forgepb.Patchset {
for pset := range me.forge.Patchsets.IterAll() {
if pset.Name == "forge auto commit" {
return pset
@ -29,14 +29,14 @@ func findAutoPatchset() *forgepb.Set {
}
}
var fauto *forgepb.Set
var fauto *forgepb.Patchset
log.Warn("findAutoPatchset() had to create 'forge auto commit'")
if fauto == nil {
fauto = new(forgepb.Set)
fauto = new(forgepb.Patchset)
fauto.Name = "forge auto commit"
fauto.Patches = forgepb.NewPatches()
fauto.Uuid = uuid.New().String()
me.forge.Patchsets.Append(fauto)
me.forge.Patchsets.Patchsets = append(me.forge.Patchsets.Patchsets, fauto)
}
return fauto
}
@ -63,7 +63,7 @@ func addRandomPatch(patch *forgepb.Patch) error {
/*
// adds a patchset or just the patches
func addPatchset(filename string, pb *forgepb.Set) {
func addPatchset(filename string, pb *forgepb.Patchset) {
// if the name of the patchset is "forge auto commit"
// then just add all the patches
if pb.Name == "forge auto commit" {
@ -96,8 +96,8 @@ func addPatchset(filename string, pb *forgepb.Set) {
}
// Clone() this protobuf into me.forge.Patchsets
var newpb *forgepb.Set
newpb = proto.Clone(pb).(*forgepb.Set)
var newpb *forgepb.Patchset
newpb = proto.Clone(pb).(*forgepb.Patchset)
if newpb != nil {
me.forge.Patchsets.Patchsets = append(me.forge.Patchsets.Patchsets, newpb)
}
@ -122,8 +122,8 @@ func mergePatchsets() {
fmt.Println(entry.Name(), err)
continue
}
var p *forgepb.Set
p = new(forgepb.Set)
var p *forgepb.Patchset
p = new(forgepb.Patchset)
err = p.Unmarshal(bytes)
if err != nil {
fmt.Println(entry.Name(), err)

View File

@ -38,8 +38,8 @@ func sendPendingPatches(pb *forgepb.Patches, reqPB *httppb.HttpRequest) *forgepb
return allPatchesPB
}
func sendPendingPatchsets(pb *forgepb.Sets, reqPB *httppb.HttpRequest) *forgepb.Sets {
allPatchsetsPB := new(forgepb.Sets)
func sendPendingPatchsets(pb *forgepb.Patchsets, reqPB *httppb.HttpRequest) *forgepb.Patchsets {
allPatchsetsPB := new(forgepb.Patchsets)
for pset := range me.forge.Patchsets.IterAll() {
allPatchsetsPB.Append(pset)
}
@ -54,8 +54,8 @@ func makePatchesPB(reqPB *httppb.HttpRequest) (*forgepb.Patches, error) {
}
*/
func makePatchsetsPB(reqPB *httppb.HttpRequest) (*forgepb.Sets, error) {
pb := forgepb.NewSets()
func makePatchsetsPB(reqPB *httppb.HttpRequest) (*forgepb.Patchsets, error) {
pb := forgepb.NewPatchsets()
err := pb.Unmarshal(reqPB.ServerData)
return pb, err
}

49
http.go
View File

@ -63,53 +63,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return
}
if strings.HasPrefix(route, "/set/") {
pb := new(forgepb.Set)
if err := pb.Unmarshal(reqPB.ClientData); err != nil {
reqPB.Logf("Patches Unmarshal() len(data)=%d err=%v", len(reqPB.ClientData), err)
logReqPB(reqPB)
return
}
reqPB.Logf("Patches Unmarshal() len=%d", pb.Patches.Len())
result := new(forgepb.Set)
switch route {
case "/set/new":
me.forge.Patchsets.Append(pb)
reqPB.Logf("addNewPatches() pb.Patches.Len()=%d Patchsets.Len()=%d", pb.Patches.Len(), me.forge.Patchsets.Len())
me.forge.SavePatchsets()
result.Uuid = pb.Uuid
default:
}
if err := result.SendReply(w, reqPB); err != nil {
reqPB.Logf("Oh well, Send to client failed. err=%v", err)
}
// todo: logReq(reqPB)
logReqPB(reqPB)
return
}
if strings.HasPrefix(route, "/sets/") {
pb := forgepb.NewSets()
if err := pb.Unmarshal(reqPB.ClientData); err != nil {
reqPB.Logf("Patches Unmarshal() len(data)=%d err=%v", len(reqPB.ClientData), err)
logReqPB(reqPB)
return
}
reqPB.Logf("Patches Unmarshal() len=%d", pb.Len())
switch route {
case "/sets/get":
if err := me.forge.Patchsets.SendReply(w, reqPB); err != nil {
reqPB.Logf("Oh well, Send to client failed. err=%v", err)
} else {
reqPB.Logf("SendReply() worked")
}
default:
}
// todo: logReq(reqPB)
logReqPB(reqPB)
return
}
if strings.HasPrefix(route, "/patches/") {
pb := forgepb.NewPatches()
if err := pb.Unmarshal(reqPB.ClientData); err == nil {
@ -147,7 +100,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
reqPB.Logf("%v", err)
}
result := forgepb.NewSets()
result := forgepb.NewPatchsets()
switch route {
case "/patches/get":
result = sendPendingPatchsets(pb, reqPB)

19
main.go
View File

@ -6,7 +6,7 @@ import (
"net/http"
"time"
"go.wit.com/lib/fhelp"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/gui/prep"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log"
@ -26,32 +26,21 @@ var LIBDIR string = "/var/lib/forged/" // need to deprecate this
func main() {
me = new(mainType)
me.myGui = prep.Gui() // prepares the GUI package for go-args
me.auto = prep.Bash3(&argv) // this line should be: prep.Bash(&argv)
prep.Bash(ARGNAME, argv.DoAutoComplete) // todo: this line should be: prep.Bash(argv)
me.myGui = prep.Gui() // prepares the GUI package for go-args
me.pp = arg.MustParse(&argv)
me.forge = forgepb.InitByAppname(ARGNAME)
if err := me.forge.InitPatchsets(); err != nil {
log.Info("patches failed to open", err)
badExit(err)
}
if argv.List != nil {
log.Printf("forge.Init() %s len()=%d\n", me.forge.Config.Filename, me.forge.Repos.Len())
fhelp.DumpENV("finit:")
me.forge.Config.DumpENV()
doList()
okExit("")
}
if argv.Clean != nil {
log.Printf("forge.Init() %s len()=%d\n", me.forge.Config.Filename, me.forge.Repos.Len())
fhelp.DumpENV("finit:")
me.forge.Config.DumpENV()
doClean()
okExit("")
}
if argv.Merge != nil {
if err := doMerge(); err != nil {
badExit(err)

View File

@ -16,6 +16,5 @@ type mainType struct {
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
forge *forgepb.Forge // for holding the forge protobuf files
myGui *prep.GuiPrep // the gui toolkit handle
auto *prep.Auto // more experiments for bash handling
configs *forgepb.ForgeConfigs // for holding the forge protobuf files
}