Author | Jakob Wakeling <[email protected]> |
Date | 2023-12-17 07:18:15 |
Commit | 54be405223f1437c7715f9d6d407539e6eaf3ef6 |
Parent | 4cb95cba0828c4184cdfb5a942014fb4e43b2b3b |
Cache DiffStats by commit hash
Diffstat
M | src/goit/git.go | | | 8 | ++++++++ |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/goit/git.go b/src/goit/git.go index 6db44a9..4c3b040 100644 --- a/src/goit/git.go +++ b/src/goit/git.go @@ -15,6 +15,7 @@ import ( "strings" "github.com/go-chi/chi/v5" + "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/format/diff" "github.com/go-git/go-git/v5/plumbing/object" ) @@ -226,7 +227,13 @@ type DiffStat struct { IsBinary bool } +var diffs = map[plumbing.Hash][]DiffStat{} + func DiffStats(c *object.Commit) ([]DiffStat, error) { + if stats, ok := diffs[c.Hash]; ok { + return stats, nil + } + from, err := c.Tree() if err != nil { return nil, err @@ -303,5 +310,6 @@ func DiffStats(c *object.Commit) ([]DiffStat, error) { stats = append(stats, stat) } + diffs[c.Hash] = stats return stats, nil }