summaryrefslogtreecommitdiff
path: root/doPatchsets.go
diff options
context:
space:
mode:
Diffstat (limited to 'doPatchsets.go')
-rw-r--r--doPatchsets.go39
1 files changed, 27 insertions, 12 deletions
diff --git a/doPatchsets.go b/doPatchsets.go
index 7a22c0a..a3630d8 100644
--- a/doPatchsets.go
+++ b/doPatchsets.go
@@ -11,6 +11,7 @@ import (
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
+ "google.golang.org/protobuf/proto"
)
func doSendPatchsets(w http.ResponseWriter) {
@@ -135,23 +136,17 @@ func listPatchsets(w http.ResponseWriter) {
}
}
-func savePatchset(w http.ResponseWriter, msg []byte) {
- log.Info("proto.Unmarshal() try message len", len(msg))
+func savePatchset(w http.ResponseWriter, msg []byte) error {
+ // log.Info("proto.Unmarshal() try message len", len(msg))
var m *forgepb.Patchset
m = new(forgepb.Patchset)
if err := m.Unmarshal(msg); err != nil {
log.Info("proto.Unmarshal() failed on wire message len", len(msg))
log.Info("error =", err)
- return
+ return err
}
log.Info("GOT patchset:", len(msg))
- fmt.Fprintln(w, "GOT patchset:", len(msg))
- all := m.Patches.SortByFilename()
- for all.Scan() {
- repo := all.Next()
- log.Info("filename:", repo.Filename)
- fmt.Fprintln(w, "filename:", repo.Filename)
- }
+ // fmt.Fprintln(w, "GOT patchset:", len(msg))
now := time.Now()
// timestamp := now.Format("2022.07.18.190545") // 50yr shout out to K&R
timestamp := now.Format("2006.01.02.150405") // bummer. other date doesn't work?
@@ -159,11 +154,31 @@ func savePatchset(w http.ResponseWriter, msg []byte) {
regfile, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
log.Info("filename open error:", filename, err)
- fmt.Fprintln(w, "filename open error:", filename, err)
- return
+ // fmt.Fprintln(w, "filename open error:", filename, err)
+ return err
}
regfile.Write(msg)
regfile.Close()
+
+ response := forgepb.NewPatches() // this sets the proper handshake protobuf UUID
+ all := m.Patches.SortByFilename()
+ for all.Scan() {
+ p := all.Next()
+ log.Info("filename:", p.Filename)
+ var newp *forgepb.Patch
+ newp = p
+ newp = proto.Clone(p).(*forgepb.Patch)
+ // fmt.Fprintln(w, "filename:", repo.Filename)
+ response.Append(newp)
+ }
+ data, err := response.Marshal()
+ if err != nil {
+ log.Infof("savePatchset() proto.Marshal() error %v\n", err)
+ return err
+ }
+ log.Infof("savePatchset() proto.Unmarshal() try to send len(msg)=%d back to the client forge\n", len(data))
+ w.Write(data)
+ return nil
}
func lookupRepos(msg []byte) (*gitpb.Repos, error) {