Commit 8e1573e
Eric Bower
·
2026-05-16 09:26:14 -0400 EDT
parent ac17667
style: show total commit in log when truncated
2 files changed,
+37,
-8
+6,
-1
| ... | ... | @@ -7,7 +7,12 @@ | |
| 7 | 7 | <div class="group-2"> | |
| 8 | 8 | <div class="box sticky flex items-center gap border-visited" style="margin: 0 !important;"> | |
| 9 | 9 | <code>{{.RevData.Name}}</code> | |
| 10 | - | <div><span class="font-bold">{{.NumCommits}}</span> commits</div> | |
| 10 | + | <div> | |
| 11 | + | <span class="font-bold">{{.NumCommits}}</span> commits | |
| 12 | + | {{if and .TotalCommits (ne .NumCommits .TotalCommits)}} | |
| 13 | + | <span class="text-sm">({{.NumCommits}} out of {{.TotalCommits}} generated)</span> | |
| 14 | + | {{end}} | |
| 15 | + | </div> | |
| 11 | 16 | </div> | |
| 12 | 17 | ||
| 13 | 18 | {{range .Logs}} |
M
main.go
+31,
-7
| ... | ... | @@ -10,8 +10,10 @@ import ( | |
| 10 | 10 | "io" | |
| 11 | 11 | "log/slog" | |
| 12 | 12 | "os" | |
| 13 | + | "os/exec" | |
| 13 | 14 | "path/filepath" | |
| 14 | 15 | "sort" | |
| 16 | + | "strconv" | |
| 15 | 17 | "strings" | |
| 16 | 18 | "sync" | |
| 17 | 19 | "time" |
| ... | ... | @@ -191,8 +193,9 @@ type TreePageData struct { | |
| 191 | 193 | ||
| 192 | 194 | type LogPageData struct { | |
| 193 | 195 | *PageData | |
| 194 | - | NumCommits int | |
| 195 | - | Logs []*CommitData | |
| 196 | + | NumCommits int | |
| 197 | + | TotalCommits int | |
| 198 | + | Logs []*CommitData | |
| 196 | 199 | } | |
| 197 | 200 | ||
| 198 | 201 | type FilePageData struct { |
| ... | ... | @@ -484,7 +487,7 @@ func (c *Config) writeTree(data PageData, tree *TreeRoot) { | |
| 484 | 487 | }) | |
| 485 | 488 | } | |
| 486 | 489 | ||
| 487 | - | func (c *Config) writeLog(data PageData, logs []*CommitData) { | |
| 490 | + | func (c *Config) writeLog(data PageData, logs []*CommitData, totalCommits int) { | |
| 488 | 491 | data.ActivePage = "commits" | |
| 489 | 492 | c.Logger.Info("writing log file", "revision", data.RevData.Name()) | |
| 490 | 493 | c.writeHtml(&WriteData{ |
| ... | ... | @@ -492,9 +495,10 @@ func (c *Config) writeLog(data PageData, logs []*CommitData) { | |
| 492 | 495 | Subdir: getLogBaseDir(data.RevData), | |
| 493 | 496 | Template: "html/log.page.tmpl", | |
| 494 | 497 | Data: &LogPageData{ | |
| 495 | - | PageData: &data, | |
| 496 | - | NumCommits: len(logs), | |
| 497 | - | Logs: logs, | |
| 498 | + | PageData: &data, | |
| 499 | + | NumCommits: len(logs), | |
| 500 | + | TotalCommits: totalCommits, | |
| 501 | + | Logs: logs, | |
| 498 | 502 | }, | |
| 499 | 503 | }) | |
| 500 | 504 | } |
| ... | ... | @@ -701,6 +705,23 @@ func getShortID(id string) string { | |
| 701 | 705 | return id[:7] | |
| 702 | 706 | } | |
| 703 | 707 | ||
| 708 | + | // countCommits returns the total number of commits reachable from the given ref | |
| 709 | + | func countCommits(repo *git.Repository, ref string) int { | |
| 710 | + | // git rev-list --count is the most efficient way to get total commit count | |
| 711 | + | cmd := exec.Command("git", "rev-list", "--count", ref) | |
| 712 | + | cmd.Dir = repo.Path() // run in the repo directory | |
| 713 | + | out, err := cmd.CombinedOutput() | |
| 714 | + | if err != nil { | |
| 715 | + | // fallback: if git command fails, return 0 | |
| 716 | + | return 0 | |
| 717 | + | } | |
| 718 | + | count, err := strconv.Atoi(strings.TrimSpace(string(out))) | |
| 719 | + | if err != nil { | |
| 720 | + | return 0 | |
| 721 | + | } | |
| 722 | + | return count | |
| 723 | + | } | |
| 724 | + | ||
| 704 | 725 | func (c *Config) writeRepo() *BranchOutput { | |
| 705 | 726 | c.Logger.Info("writing repo", "repoPath", c.RepoPath) | |
| 706 | 727 | repo, err := git.Open(c.RepoPath) |
| ... | ... | @@ -1041,6 +1062,9 @@ func (c *Config) writeRevision(repo *git.Repository, pageData *PageData, refs [] | |
| 1041 | 1062 | if pageSize == 0 { | |
| 1042 | 1063 | pageSize = 5000 | |
| 1043 | 1064 | } | |
| 1065 | + | // get total commit count (unlimited) for display | |
| 1066 | + | totalCommits := countCommits(repo, pageData.RevData.ID()) | |
| 1067 | + | ||
| 1044 | 1068 | commits, err := repo.CommitsByPage(pageData.RevData.ID(), 0, pageSize) | |
| 1045 | 1069 | bail(err) | |
| 1046 | 1070 |