75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
|
|
"go.wit.com/lib/protobuf/forgepb"
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
func doList() error {
|
|
log.Info("do list here")
|
|
|
|
if err := LoadPatchsets(); err != nil {
|
|
badExit(err)
|
|
}
|
|
|
|
// first show the general patchset protobuf
|
|
for pb := range me.all.IterAll() {
|
|
if pb.Name == "forge auto commit" {
|
|
showPatchsets(pb)
|
|
}
|
|
}
|
|
|
|
// show all the patchsets with Names
|
|
for pset := range me.all.IterAll() {
|
|
if pset.Name == "forge auto commit" {
|
|
continue
|
|
}
|
|
showPatchsets(pset)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func cleanSubject(line string) string {
|
|
// Regular expression to remove "Subject:" and "[PATCH...]" patterns
|
|
re := regexp.MustCompile(`(?i)^Subject:\s*(\[\s*PATCH[^\]]*\]\s*)?`)
|
|
cleaned := re.ReplaceAllString(line, "")
|
|
return strings.TrimSpace(cleaned)
|
|
}
|
|
|
|
func showPatchsets(pb *forgepb.Patchset) error {
|
|
author := "Author: " + pb.GitAuthorName
|
|
author += " <" + pb.GitAuthorEmail + ">"
|
|
log.Printf("%-16s %s %s %s\n", string(pb.Uuid)[0:8], pb.Name, pb.Comment, author)
|
|
for _, patch := range pb.Patches.Patches {
|
|
comment := cleanSubject(patch.Comment)
|
|
log.Printf("\t%-8s %-50s %-50s\n", string(patch.CommitHash)[0:8], patch.Namespace, comment)
|
|
}
|
|
/*
|
|
for patch := range pb.IterAll() {
|
|
comment := cleanSubject(patch.Comment)
|
|
log.Info("\tnew patch:", patch.NewHash, "commithash:", patch.CommitHash, patch.Namespace, comment)
|
|
}
|
|
*/
|
|
return nil
|
|
}
|
|
|
|
// returns true if the patch already exists in the protobuf
|
|
func findPatch(newpatch *forgepb.Patch) bool {
|
|
// log.Info("\tlook for patch:", newpatch.CommitHash, newpatch.Namespace)
|
|
|
|
for pset := range me.all.IterAll() {
|
|
for _, patch := range pset.Patches.Patches {
|
|
if patch.CommitHash == newpatch.CommitHash {
|
|
// log.Info("\tfound pset!!!!!!", pset.Uuid, patch.Namespace)
|
|
return true
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|