add commit hash and diff file list to the protobuf

This commit is contained in:
Jeff Carr 2025-01-05 04:54:31 -06:00
parent ac57825c10
commit b0662fb61a
2 changed files with 23 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
@ -136,6 +137,7 @@ func (p *Patchs) addPatchFiles(repo *gitpb.Repo) error {
patch := new(Patch)
patch.Filename, _ = filepath.Rel(p.TmpDir, path)
patch.Data = data
patch.parseData()
patch.StartHash = repo.DevelHash()
p.Patchs = append(p.Patchs, patch)
log.Info("ADDED PATCH FILE", path)
@ -144,6 +146,26 @@ func (p *Patchs) addPatchFiles(repo *gitpb.Repo) error {
return baderr
}
// looks at the git format-patch output
// saves the commit Hash
// saves the diff lines
func (p *Patch) parseData() string {
lines := strings.Split(string(p.Data), "\n")
for _, line := range lines {
fields := strings.Fields(line)
if len(fields) < 2 {
continue
}
switch fields[0] {
case "From":
p.CommitHash = fields[1]
case "diff":
p.Files = append(p.Files, line)
}
}
return ""
}
// just an example of how to walk only directories
func onlyWalkDirs(pDir string) error {
log.Info("DIR", pDir)

View File

@ -13,6 +13,7 @@ message Patch {
google.protobuf.Timestamp ctime = 7; // the git commit timestamp of this patch
string commitHash = 8; // the git commit hash of this patch
string startHash = 9; // the start commit hash
repeated string Files = 10; // the filenames this patch changes
}
message Patchs { // `autogenpb:marshal`