Commit fae1d37
Eric Bower
·
2023-08-07 10:20:29 -0400 EDT
parent 134e2ae
wrap
3 files changed,
+66,
-46
+3,
-0
| ... | ... | @@ -5,11 +5,14 @@ repos: | |
| 5 | 5 | - main | |
| 6 | 6 | - v1.0.0 | |
| 7 | 7 | desc: pico services - prose.sh, lists.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh | |
| 8 | + | hide_tree_last_commit: true | |
| 8 | 9 | - path: /home/erock/dev/pico/pico-ops | |
| 9 | 10 | refs: | |
| 10 | 11 | - main | |
| 11 | 12 | desc: infra for pico services | |
| 13 | + | hide_tree_last_commit: true | |
| 12 | 14 | - path: /home/erock/dev/app-ui | |
| 13 | 15 | refs: | |
| 14 | 16 | - main | |
| 17 | + | - v50 | |
| 15 | 18 | desc: aptible's paas web application |
+3,
-0
| ... | ... | @@ -13,9 +13,12 @@ | |
| 13 | 13 | </div> | |
| 14 | 14 | ||
| 15 | 15 | <div class="flex items-center gap"> | |
| 16 | + | {{if $.Repo.HideTreeLastCommit}} | |
| 17 | + | {{else}} | |
| 16 | 18 | <div class="flex-1"> | |
| 17 | 19 | <a href="{{.CommitURL}}" title="{{.Summary}}">{{.When}}</a> | |
| 18 | 20 | </div> | |
| 21 | + | {{end}} | |
| 19 | 22 | <div class="tree-size"> | |
| 20 | 23 | {{if .IsTextFile}}{{.NumLines}} L{{else}}{{.Size}}{{end}} | |
| 21 | 24 | </div> |
M
main.go
+60,
-46
| ... | ... | @@ -32,16 +32,17 @@ type IndexPage struct { | |
| 32 | 32 | } | |
| 33 | 33 | ||
| 34 | 34 | type RepoData struct { | |
| 35 | - | Name string | |
| 36 | - | Desc string | |
| 37 | - | SummaryURL string | |
| 38 | - | TreeURL string | |
| 39 | - | LogURL string | |
| 40 | - | RefsURL string | |
| 41 | - | CloneURL string | |
| 42 | - | MaxCommits int | |
| 43 | - | RevName string | |
| 44 | - | Readme string | |
| 35 | + | Name string | |
| 36 | + | Desc string | |
| 37 | + | SummaryURL string | |
| 38 | + | TreeURL string | |
| 39 | + | LogURL string | |
| 40 | + | RefsURL string | |
| 41 | + | CloneURL string | |
| 42 | + | MaxCommits int | |
| 43 | + | RevName string | |
| 44 | + | Readme string | |
| 45 | + | HideTreeLastCommit bool | |
| 45 | 46 | } | |
| 46 | 47 | ||
| 47 | 48 | type CommitData struct { |
| ... | ... | @@ -129,11 +130,12 @@ type BranchOutput struct { | |
| 129 | 130 | } | |
| 130 | 131 | ||
| 131 | 132 | type RepoConfig struct { | |
| 132 | - | Path string `mapstructure:"path"` | |
| 133 | - | Refs []string `mapstructure:"refs"` | |
| 134 | - | Desc string `mapstructure:"desc"` | |
| 135 | - | MaxCommits int `mapstructure:"max_commits"` | |
| 136 | - | Readme string `mapstructure:"readme"` | |
| 133 | + | Path string `mapstructure:"path"` | |
| 134 | + | Refs []string `mapstructure:"refs"` | |
| 135 | + | Desc string `mapstructure:"desc"` | |
| 136 | + | MaxCommits int `mapstructure:"max_commits"` | |
| 137 | + | Readme string `mapstructure:"readme"` | |
| 138 | + | HideTreeLastCommit bool `mapstructure:"hide_tree_last_commit"` | |
| 137 | 139 | } | |
| 138 | 140 | ||
| 139 | 141 | type Config struct { |
| ... | ... | @@ -454,18 +456,6 @@ func (c *Config) writeRepo(config *RepoConfig) *BranchOutput { | |
| 454 | 456 | } | |
| 455 | 457 | _, revName := filepath.Split(rev.Refspec) | |
| 456 | 458 | ||
| 457 | - | repoData := &RepoData{ | |
| 458 | - | Name: name, | |
| 459 | - | Desc: config.Desc, | |
| 460 | - | MaxCommits: config.MaxCommits, | |
| 461 | - | SummaryURL: fmt.Sprintf("/%s/index.html", name), | |
| 462 | - | TreeURL: fmt.Sprintf("/%s/tree/%s/index.html", name, revName), | |
| 463 | - | LogURL: fmt.Sprintf("/%s/logs/%s/index.html", name, revName), | |
| 464 | - | RefsURL: fmt.Sprintf("/%s/refs.html", name), | |
| 465 | - | CloneURL: fmt.Sprintf("https://%s/%s.git", c.URL, name), | |
| 466 | - | RevName: revName, | |
| 467 | - | } | |
| 468 | - | ||
| 469 | 459 | refInfoMap := map[string]*RefInfo{} | |
| 470 | 460 | var mainOutput *BranchOutput | |
| 471 | 461 | claimed := false |
| ... | ... | @@ -481,15 +471,17 @@ func (c *Config) writeRepo(config *RepoConfig) *BranchOutput { | |
| 481 | 471 | } | |
| 482 | 472 | ||
| 483 | 473 | branchRepo := &RepoData{ | |
| 484 | - | Name: name, | |
| 485 | - | Desc: config.Desc, | |
| 486 | - | MaxCommits: config.MaxCommits, | |
| 487 | - | SummaryURL: fmt.Sprintf("/%s/index.html", name), | |
| 488 | - | TreeURL: fmt.Sprintf("/%s/tree/%s/index.html", name, revn), | |
| 489 | - | LogURL: fmt.Sprintf("/%s/logs/%s/index.html", name, revn), | |
| 490 | - | RefsURL: fmt.Sprintf("/%s/refs.html", name), | |
| 491 | - | CloneURL: fmt.Sprintf("https://%s/%s.git", c.URL, name), | |
| 492 | - | RevName: revn, | |
| 474 | + | Name: name, | |
| 475 | + | Desc: config.Desc, | |
| 476 | + | MaxCommits: config.MaxCommits, | |
| 477 | + | Readme: config.Readme, | |
| 478 | + | HideTreeLastCommit: config.HideTreeLastCommit, | |
| 479 | + | SummaryURL: fmt.Sprintf("/%s/index.html", name), | |
| 480 | + | TreeURL: fmt.Sprintf("/%s/tree/%s/index.html", name, revn), | |
| 481 | + | LogURL: fmt.Sprintf("/%s/logs/%s/index.html", name, revn), | |
| 482 | + | RefsURL: fmt.Sprintf("/%s/refs.html", name), | |
| 483 | + | CloneURL: fmt.Sprintf("https://%s/%s.git", c.URL, name), | |
| 484 | + | RevName: revn, | |
| 493 | 485 | } | |
| 494 | 486 | ||
| 495 | 487 | data := &PageData{ |
| ... | ... | @@ -531,6 +523,17 @@ func (c *Config) writeRepo(config *RepoConfig) *BranchOutput { | |
| 531 | 523 | return urlI > urlJ | |
| 532 | 524 | }) | |
| 533 | 525 | ||
| 526 | + | repoData := &RepoData{ | |
| 527 | + | Name: name, | |
| 528 | + | Desc: config.Desc, | |
| 529 | + | SummaryURL: fmt.Sprintf("/%s/index.html", name), | |
| 530 | + | TreeURL: fmt.Sprintf("/%s/tree/%s/index.html", name, revName), | |
| 531 | + | LogURL: fmt.Sprintf("/%s/logs/%s/index.html", name, revName), | |
| 532 | + | RefsURL: fmt.Sprintf("/%s/refs.html", name), | |
| 533 | + | CloneURL: fmt.Sprintf("https://%s/%s.git", c.URL, name), | |
| 534 | + | RevName: revName, | |
| 535 | + | } | |
| 536 | + | ||
| 534 | 537 | data := &PageData{ | |
| 535 | 538 | Rev: rev, | |
| 536 | 539 | RevName: revName, |
| ... | ... | @@ -544,6 +547,8 @@ func (c *Config) writeRepo(config *RepoConfig) *BranchOutput { | |
| 544 | 547 | } | |
| 545 | 548 | ||
| 546 | 549 | func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOutput { | |
| 550 | + | fmt.Printf("compiling (%s) branch (%s)\n", pageData.Repo.Name, pageData.Repo.RevName) | |
| 551 | + | ||
| 547 | 552 | output := &BranchOutput{} | |
| 548 | 553 | pageSize := pageData.Repo.MaxCommits | |
| 549 | 554 | if pageSize == 0 { |
| ... | ... | @@ -576,18 +581,25 @@ func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOu | |
| 576 | 581 | for _, entry := range treeEntries { | |
| 577 | 582 | entry.Path = strings.TrimPrefix(entry.Path, "/") | |
| 578 | 583 | ||
| 579 | - | lastCommits, err := repo.RevList([]string{pageData.Rev.Refspec}, git.RevListOptions{ | |
| 580 | - | Path: entry.Path, | |
| 581 | - | }) | |
| 582 | - | bail(err) | |
| 584 | + | var lastCommits []*git.Commit | |
| 585 | + | // `git rev-list` is pretty expensive here, so we have a flag to disable | |
| 586 | + | if pageData.Repo.HideTreeLastCommit { | |
| 587 | + | fmt.Println("skipping finding last commit for each file") | |
| 588 | + | } else { | |
| 589 | + | lastCommits, err = repo.RevList([]string{pageData.Rev.Refspec}, git.RevListOptions{ | |
| 590 | + | Path: entry.Path, | |
| 591 | + | CommandOptions: git.CommandOptions{Args: []string{"-1"}}, | |
| 592 | + | }) | |
| 593 | + | bail(err) | |
| 583 | 594 | ||
| 584 | - | var lc *git.Commit | |
| 585 | - | if len(lastCommits) > 0 { | |
| 586 | - | lc = lastCommits[0] | |
| 595 | + | var lc *git.Commit | |
| 596 | + | if len(lastCommits) > 0 { | |
| 597 | + | lc = lastCommits[0] | |
| 598 | + | } | |
| 599 | + | entry.CommitURL = commitURL(pageData.Repo.Name, lc.ID.String()) | |
| 600 | + | entry.Summary = lc.Summary() | |
| 601 | + | entry.When = timediff.TimeDiff(lc.Author.When) | |
| 587 | 602 | } | |
| 588 | - | entry.CommitURL = commitURL(pageData.Repo.Name, lc.ID.String()) | |
| 589 | - | entry.Summary = lc.Summary() | |
| 590 | - | entry.When = timediff.TimeDiff(lc.Author.When) | |
| 591 | 603 | entry.URL = filepath.Join( | |
| 592 | 604 | "/", | |
| 593 | 605 | pageData.Repo.Name, |
| ... | ... | @@ -601,6 +613,8 @@ func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOu | |
| 601 | 613 | pageData.Log = logs | |
| 602 | 614 | pageData.Tree = treeEntries | |
| 603 | 615 | ||
| 616 | + | fmt.Printf("compilation complete (%s) branch (%s)", pageData.Repo.Name, pageData.Repo.RevName) | |
| 617 | + | ||
| 604 | 618 | writeLog(pageData) | |
| 605 | 619 | readme := writeHTMLTreeFiles(pageData) | |
| 606 | 620 | c.writeLogDiffs(repo, pageData) |