Patrick Georgi has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/68959 )
Change subject: board-status: Use go-git ......................................................................
board-status: Use go-git
Doesn't work yet due to upstream issues with resolving partial hashes
Change-Id: I37fac3caf265fd5591eaa2c04fad8bdee3bf5f84 Signed-off-by: Patrick Georgi patrick@coreboot.org --- M util/docker/coreboot.org-status/board-status.html/logs.go 1 file changed, 31 insertions(+), 7 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/59/68959/1
diff --git a/util/docker/coreboot.org-status/board-status.html/logs.go b/util/docker/coreboot.org-status/board-status.html/logs.go index 21e91f2..f419ad8 100644 --- a/util/docker/coreboot.org-status/board-status.html/logs.go +++ b/util/docker/coreboot.org-status/board-status.html/logs.go @@ -4,11 +4,13 @@ "fmt" "io/fs" "os" - "os/exec" "path/filepath" "sort" "strings" "time" + + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" )
// Color returns a HTML color code between green and yellow based on the @@ -50,6 +52,19 @@ data.VendorBoardReferenced = make(map[string]bool) timeframes := make(map[Timeframe]bool) gitcache := make(map[string]string) + repo, err := git.PlainOpen(cbdir) + if err != nil { + fmt.Fprintf(os.Stderr, "Could not open %s: %v\n", cbdir, err) + return + } + if true { + // Hack to work around issue in go-git + // Adopted from https://github.com/go-git/go-git/issues/148 + hash, _ := repo.ResolveRevision(plumbing.Revision("HEAD")) + commit, _ := repo.CommitObject(*hash) + tree, _ := commit.Tree() + _ = tree + } for dir := range dirs { upstream := "" revB, err := fs.ReadFile(dir.FS, filepath.Join(dir.Name, "revision.txt")) @@ -68,19 +83,16 @@ } if item[0] == "Upstream revision" { upstream = strings.TrimSpace(item[1]) - // tried using go-git, but its resolver - // couldn't expand short hashes despite the - // docs claiming that it can. if val, ok := gitcache[upstream]; ok { upstream = val } else { - res, err := exec.Command("/usr/bin/git", "-C", cbdir, "log", "-n1", "--format=%H", upstream).Output() + res, err := repo.ResolveRevision(plumbing.Revision(upstream)) if err != nil { - fmt.Fprintf(os.Stderr, "revision %s not found \n", upstream) + fmt.Fprintf(os.Stderr, "revision %s not found: %v\n", upstream, err) skipDir = true break } - gitcache[upstream] = strings.TrimSpace(string(res)) + gitcache[upstream] = strings.TrimSpace(res.String()) upstream = gitcache[upstream] } }