1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
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
}
|