Commit fe38cd8

Eric Bower  ·  2023-08-06 12:00:45 -0400 EDT
parent c0b0fe0
progress
6 files changed,  +105, -49
+1, -0
......@@ -3,6 +3,7 @@ repos:
33 - path: /home/erock/dev/pico/pico
44 refs:
55 - main
6+ - v1.0.0
67 desc: pico services - prose.sh, lists.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
78 - path: /home/erock/dev/pico/pico-ops
89 refs:
+3, -2
......@@ -6,9 +6,10 @@
66
77 <div class="text-lg">
88 <a href="{{.Repo.SummaryURL}}">summary</a> |
9+ <a href="{{.Repo.RefsURL}}">refs</a> |
10+ <span class="font-bold">{{.Repo.RevName}}</span> |
911 <a href="{{.Repo.TreeURL}}">tree</a> |
10- <a href="{{.Repo.LogURL}}">log</a> |
11- <a href="{{.Repo.RefsURL}}">refs</a>
12+ <a href="{{.Repo.LogURL}}">log</a>
1213 </div>
1314
1415 <div class="my">
+12, -3
......@@ -5,9 +5,18 @@
55 {{define "content"}}
66 {{template "header" .}}
77
8+ <div>
89 {{range .Data.Log}}
9- <p>
10- {{.Author.When}} <a href="{{.URL}}">{{.Summary}}</a> {{.Author.Name}}
11- </p>
10+ <div class="box">
11+ <div>
12+ <a href="{{.URL}}">{{.SummaryStr}}</a>
13+ </div>
14+ <div>
15+ <span>{{.AuthorStr}}</span>
16+ <span>&nbsp;committed&nbsp;</span>
17+ <span>{{.WhenStr}}</span>
18+ </div>
19+ </div>
1220 {{end}}
21+ </div>
1322 {{end}}
+8, -11
......@@ -5,17 +5,14 @@
55 {{define "content"}}
66 {{template "header" .}}
77
8- <h2 class="text-md">branches</h2>
9- <ol>
10- {{range .Data.Branches}}
11- <li>{{.Refspec}}</li>
12- {{end}}
13- </ol>
14-
15- <h2 class="text-md">tags</h2>
16- <ol>
17- {{range .Data.Tags}}
18- <li>{{.Refspec}}</li>
8+ <h2 class="text-md font-bold">refs</h2>
9+ <ul>
10+ {{range .Data.Refs}}
11+ {{if .URL}}
12+ <li><a href="{{.URL}}">{{.Refspec}}</a></li>
13+ {{else}}
14+ <li>{{.Refspec}}</li>
15+ {{end}}
1916 {{end}}
2017 </ol>
2118 {{end}}
+17, -19
......@@ -5,24 +5,22 @@
55 {{define "content"}}
66 {{template "header" .}}
77
8- <table>
9- <tbody>
10- {{range .Data.Tree}}
11- <tr>
12- <td>
13- <a href="{{.URL}}">{{.Path}}</a>
14- </td>
15- <td>
16- <a href="{{.CommitURL}}">{{.Desc}}</a>
17- </td>
18- <td>
19- {{.When}}
20- </td>
21- <td class="mono font-bold">
8+ <div>
9+ {{range .Data.Tree}}
10+ <div class="flex justify-between">
11+ <div class="flex-1">
12+ <a href="{{.URL}}">{{.Path}}</a>
13+ </div>
14+
15+ <div class="flex">
16+ <div>
17+ <a href="{{.CommitURL}}">{{.When}}</a>
18+ </div>
19+ <div class="mono font-bold">
2220 L{{.NumLines}}
23- </td>
24- </tr>
25- {{end}}
26- </tbody>
27- </table>
21+ </div>
22+ </div>
23+ </div>
24+ {{end}}
25+ </div>
2826 {{end}}
+64, -14
......@@ -38,10 +38,14 @@ type RepoData struct {
3838 RefsURL string
3939 CloneURL string
4040 MaxCommits int
41+ RevName string
4142 }
4243
4344 type CommitData struct {
45+ SummaryStr string
4446 URL string
47+ WhenStr string
48+ AuthorStr string
4549 *git.Commit
4650 }
4751
......@@ -58,12 +62,11 @@ type TreeItem struct {
5862 type PageData struct {
5963 Repo *RepoData
6064 Log []*CommitData
61- Branches []*git.Reference
62- Tags []*git.Reference
6365 Tree []*TreeItem
6466 Readme template.HTML
6567 Rev *git.Reference
6668 RevName string
69+ Refs []*RefInfo
6770 }
6871
6972 type CommitPageData struct {
......@@ -378,16 +381,21 @@ func (c *Config) writeLogDiffs(repo *git.Repository, pageData *PageData) {
378381 }
379382 }
380383
384+type RefInfo struct {
385+ Refspec string
386+ URL template.URL
387+}
388+
381389 func (c *Config) writeRepo(config *RepoConfig) *BranchOutput {
382390 repo, err := git.Open(config.Path)
383391 bail(err)
384392
385393 name := repoName(config.Path)
386394
387- heads, err := repo.ShowRef(git.ShowRefOptions{Heads: true, Tags: false})
395+ refs, err := repo.ShowRef(git.ShowRefOptions{Heads: true, Tags: true})
388396 bail(err)
389397
390- rev := findDefaultBranch(config, heads)
398+ rev := findDefaultBranch(config, refs)
391399 if rev == nil {
392400 bail(fmt.Errorf("no default branch found"))
393401 }
......@@ -402,24 +410,39 @@ func (c *Config) writeRepo(config *RepoConfig) *BranchOutput {
402410 LogURL: fmt.Sprintf("/%s/logs/%s/index.html", name, revName),
403411 RefsURL: fmt.Sprintf("/%s/refs.html", name),
404412 CloneURL: fmt.Sprintf("https://%s/%s.git", c.URL, name),
413+ RevName: revName,
405414 }
406415
407- tags, _ := repo.ShowRef(git.ShowRefOptions{Heads: false, Tags: true})
408-
416+ refInfoMap := map[string]*RefInfo{}
409417 var mainOutput *BranchOutput
410418 claimed := false
411419 for _, revn := range config.Refs {
412- for _, head := range heads {
420+ for _, head := range refs {
413421 _, headName := filepath.Split(head.Refspec)
414422 if revn != headName {
415423 continue
416424 }
425+ refInfoMap[head.ID] = &RefInfo{
426+ Refspec: strings.TrimPrefix(head.Refspec, "refs/"),
427+ URL: template.URL(fmt.Sprintf("/%s/tree/%s/index.html", name, revn)),
428+ }
429+
430+ branchRepo := &RepoData{
431+ Name: name,
432+ Desc: config.Desc,
433+ MaxCommits: config.MaxCommits,
434+ SummaryURL: fmt.Sprintf("/%s/index.html", name),
435+ TreeURL: fmt.Sprintf("/%s/tree/%s/index.html", name, revn),
436+ LogURL: fmt.Sprintf("/%s/logs/%s/index.html", name, revn),
437+ RefsURL: fmt.Sprintf("/%s/refs.html", name),
438+ CloneURL: fmt.Sprintf("https://%s/%s.git", c.URL, name),
439+ RevName: revn,
440+ }
441+
417442 data := &PageData{
418- Branches: heads,
419- Tags: tags,
420- Rev: head,
421- RevName: headName,
422- Repo: repoData,
443+ Rev: head,
444+ RevName: headName,
445+ Repo: branchRepo,
423446 }
424447
425448 branchOutput := c.writeBranch(repo, data)
......@@ -430,13 +453,37 @@ func (c *Config) writeRepo(config *RepoConfig) *BranchOutput {
430453 }
431454 }
432455
456+ for _, ref := range refs {
457+ if refInfoMap[ref.ID] != nil {
458+ continue
459+ }
460+
461+ refInfoMap[ref.ID] = &RefInfo{
462+ Refspec: strings.TrimPrefix(ref.Refspec, "refs/"),
463+ }
464+ }
465+
466+ refInfoList := []*RefInfo{}
467+ for _, val := range refInfoMap {
468+ refInfoList = append(refInfoList, val)
469+ }
470+ sort.Slice(refInfoList, func(i, j int) bool {
471+ urlI := refInfoList[i].URL
472+ urlJ := refInfoList[j].URL
473+ refI := refInfoList[i].Refspec
474+ refJ := refInfoList[j].Refspec
475+ if urlI == urlJ {
476+ return refI < refJ
477+ }
478+ return urlI > urlJ
479+ })
480+
433481 data := &PageData{
434- Branches: heads,
435- Tags: tags,
436482 Rev: rev,
437483 RevName: revName,
438484 Repo: repoData,
439485 Readme: template.HTML(mainOutput.Readme),
486+ Refs: refInfoList,
440487 }
441488 writeRefs(data)
442489 writeRootSummary(data)
......@@ -466,6 +513,9 @@ func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOu
466513
467514 logs = append(logs, &CommitData{
468515 URL: commitURL(pageData.Repo.Name, commit.ID.String()),
516+ SummaryStr: commit.Summary(),
517+ AuthorStr: commit.Author.Name,
518+ WhenStr: timediff.TimeDiff(commit.Author.When),
469519 Commit: commit,
470520 })
471521 }