From b0662fb61a824b39c9a11b3bbc05b2543841ae74 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 5 Jan 2025 04:54:31 -0600 Subject: [PATCH] add commit hash and diff file list to the protobuf --- patch.Make.go | 22 ++++++++++++++++++++++ patch.proto | 1 + 2 files changed, 23 insertions(+) diff --git a/patch.Make.go b/patch.Make.go index 0920fdf..f43d9be 100644 --- a/patch.Make.go +++ b/patch.Make.go @@ -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) diff --git a/patch.proto b/patch.proto index 4c8de21..0c5fd62 100644 --- a/patch.proto +++ b/patch.proto @@ -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`