Commit 5b50e23
Eric Bower
·
2023-08-09 23:46:05 -0400 EDT
parent ea6d2bf
progress
3 files changed,
+65,
-52
+9,
-1
| ... | ... | @@ -12,8 +12,16 @@ | |
| 12 | 12 | <div> | |
| 13 | 13 | <a href="{{.URL}}">{{.SummaryStr}}</a> | |
| 14 | 14 | </div> | |
| 15 | - | <div> | |
| 15 | + | <div class="flex gap"> | |
| 16 | 16 | {{.ShortID}} | |
| 17 | + | ||
| 18 | + | {{range .Refs}} | |
| 19 | + | {{if .URL}} | |
| 20 | + | <a href="{{.URL}}">({{.Refspec}})</a> | |
| 21 | + | {{else}} | |
| 22 | + | ({{.Refspec}}) | |
| 23 | + | {{end}} | |
| 24 | + | {{end}} | |
| 17 | 25 | </div> | |
| 18 | 26 | </div> | |
| 19 | 27 |
+2,
-1
| ... | ... | @@ -6,6 +6,7 @@ | |
| 6 | 6 | {{template "header" .}} | |
| 7 | 7 | ||
| 8 | 8 | <h2 class="text-md font-bold">refs</h2> | |
| 9 | + | ||
| 9 | 10 | <ul> | |
| 10 | 11 | {{range .Refs}} | |
| 11 | 12 | {{if .URL}} |
| ... | ... | @@ -14,5 +15,5 @@ | |
| 14 | 15 | <li>{{.Refspec}}</li> | |
| 15 | 16 | {{end}} | |
| 16 | 17 | {{end}} | |
| 17 | - | </ol> | |
| 18 | + | </ul> | |
| 18 | 19 | {{end}} |
M
main.go
+54,
-50
| ... | ... | @@ -34,8 +34,6 @@ type Config struct { | |
| 34 | 34 | RepoPath string | |
| 35 | 35 | ||
| 36 | 36 | // optional params | |
| 37 | - | // generate logs and trees based on the git references provided | |
| 38 | - | Refs []string | |
| 39 | 37 | // generate logs anad tree based on the git revisions provided | |
| 40 | 38 | Revs []string | |
| 41 | 39 | // description of repo used in the header of site |
| ... | ... | @@ -73,12 +71,18 @@ type RevData struct { | |
| 73 | 71 | LogURL template.URL | |
| 74 | 72 | } | |
| 75 | 73 | ||
| 74 | + | type TagData struct { | |
| 75 | + | Name string | |
| 76 | + | URL template.URL | |
| 77 | + | } | |
| 78 | + | ||
| 76 | 79 | type CommitData struct { | |
| 77 | 80 | SummaryStr string | |
| 78 | 81 | URL template.URL | |
| 79 | 82 | WhenStr string | |
| 80 | 83 | AuthorStr string | |
| 81 | 84 | ShortID string | |
| 85 | + | Refs []*RefInfo | |
| 82 | 86 | *git.Commit | |
| 83 | 87 | } | |
| 84 | 88 |
| ... | ... | @@ -113,6 +117,7 @@ type DiffRenderFile struct { | |
| 113 | 117 | } | |
| 114 | 118 | ||
| 115 | 119 | type RefInfo struct { | |
| 120 | + | ID string | |
| 116 | 121 | Refspec string | |
| 117 | 122 | URL template.URL | |
| 118 | 123 | } |
| ... | ... | @@ -408,6 +413,7 @@ func (c *Config) writeLogDiffs(repo *git.Repository, pageData *PageData, logs [] | |
| 408 | 413 | commitID := commit.ID.String() | |
| 409 | 414 | ||
| 410 | 415 | if c.Cache[commitID] { | |
| 416 | + | c.Logger.Infof("(%s) commit file already generated, skipping", getShortID(commitID)) | |
| 411 | 417 | continue | |
| 412 | 418 | } else { | |
| 413 | 419 | c.Cache[commitID] = true |
| ... | ... | @@ -469,9 +475,9 @@ func (c *Config) writeLogDiffs(repo *git.Repository, pageData *PageData, logs [] | |
| 469 | 475 | commitData := &CommitPageData{ | |
| 470 | 476 | PageData: pageData, | |
| 471 | 477 | Commit: commit, | |
| 472 | - | CommitID: commit.ID.String()[:7], | |
| 478 | + | CommitID: getShortID(commitID), | |
| 473 | 479 | Diff: rnd, | |
| 474 | - | Parent: parentID[:7], | |
| 480 | + | Parent: getShortID(parentID), | |
| 475 | 481 | CommitURL: c.getCommitURL(commitID), | |
| 476 | 482 | ParentURL: c.getCommitURL(parentID), | |
| 477 | 483 | } |
| ... | ... | @@ -537,31 +543,19 @@ func (c *Config) writeRepo() *BranchOutput { | |
| 537 | 543 | ||
| 538 | 544 | var first *RevData | |
| 539 | 545 | revs := []*RevData{} | |
| 540 | - | for _, refStr := range c.Refs { | |
| 541 | - | for _, ref := range refs { | |
| 542 | - | refName := git.RefShortName(ref.Refspec) | |
| 543 | - | if refName != refStr { | |
| 544 | - | continue | |
| 545 | - | } | |
| 546 | - | ||
| 547 | - | data := &RevData{ | |
| 548 | - | ID: ref.ID, | |
| 549 | - | RevName: refName, | |
| 550 | - | TreeURL: c.getTreeUrl(refName), | |
| 551 | - | LogURL: c.getLogsUrl(refName), | |
| 552 | - | } | |
| 553 | - | if first == nil { | |
| 554 | - | first = data | |
| 555 | - | } | |
| 556 | - | revs = append(revs, data) | |
| 557 | - | } | |
| 558 | - | } | |
| 559 | - | ||
| 560 | 546 | for _, revStr := range c.Revs { | |
| 561 | 547 | fullRevID, err := repo.RevParse(revStr) | |
| 562 | 548 | bail(err) | |
| 563 | 549 | ||
| 564 | 550 | revName := getShortID(fullRevID) | |
| 551 | + | // if it's a reference then label it as such | |
| 552 | + | for _, ref := range refs { | |
| 553 | + | if revStr == git.RefShortName(ref.Refspec) || revStr == ref.Refspec { | |
| 554 | + | revName = revStr | |
| 555 | + | break | |
| 556 | + | } | |
| 557 | + | } | |
| 558 | + | ||
| 565 | 559 | data := &RevData{ | |
| 566 | 560 | ID: fullRevID, | |
| 567 | 561 | RevName: revName, |
| ... | ... | @@ -582,33 +576,24 @@ func (c *Config) writeRepo() *BranchOutput { | |
| 582 | 576 | mainOutput := &BranchOutput{} | |
| 583 | 577 | claimed := false | |
| 584 | 578 | for _, revData := range revs { | |
| 585 | - | refInfoMap[revData.ID] = &RefInfo{ | |
| 579 | + | refInfoMap[revData.RevName] = &RefInfo{ | |
| 580 | + | ID: revData.ID, | |
| 586 | 581 | Refspec: revData.RevName, | |
| 587 | 582 | URL: revData.TreeURL, | |
| 588 | 583 | } | |
| 589 | - | ||
| 590 | - | data := &PageData{ | |
| 591 | - | Repo: c, | |
| 592 | - | RevData: revData, | |
| 593 | - | SiteURLs: c.getURLs(), | |
| 594 | - | } | |
| 595 | - | ||
| 596 | - | branchOutput := c.writeBranch(repo, data) | |
| 597 | - | if !claimed { | |
| 598 | - | mainOutput = branchOutput | |
| 599 | - | claimed = true | |
| 600 | - | } | |
| 601 | 584 | } | |
| 602 | 585 | ||
| 603 | 586 | // loop through ALL refs that don't have URLs | |
| 604 | 587 | // and add them to the map | |
| 605 | 588 | for _, ref := range refs { | |
| 606 | - | if refInfoMap[ref.ID] != nil { | |
| 589 | + | refspec := git.RefShortName(ref.Refspec) | |
| 590 | + | if refInfoMap[refspec] != nil { | |
| 607 | 591 | continue | |
| 608 | 592 | } | |
| 609 | 593 | ||
| 610 | - | refInfoMap[ref.ID] = &RefInfo{ | |
| 611 | - | Refspec: strings.TrimPrefix(ref.Refspec, "refs/"), | |
| 594 | + | refInfoMap[refspec] = &RefInfo{ | |
| 595 | + | ID: ref.ID, | |
| 596 | + | Refspec: refspec, | |
| 612 | 597 | } | |
| 613 | 598 | } | |
| 614 | 599 |
| ... | ... | @@ -628,6 +613,20 @@ func (c *Config) writeRepo() *BranchOutput { | |
| 628 | 613 | return urlI > urlJ | |
| 629 | 614 | }) | |
| 630 | 615 | ||
| 616 | + | for _, revData := range revs { | |
| 617 | + | data := &PageData{ | |
| 618 | + | Repo: c, | |
| 619 | + | RevData: revData, | |
| 620 | + | SiteURLs: c.getURLs(), | |
| 621 | + | } | |
| 622 | + | ||
| 623 | + | branchOutput := c.writeBranch(repo, data, refInfoList) | |
| 624 | + | if !claimed { | |
| 625 | + | mainOutput = branchOutput | |
| 626 | + | claimed = true | |
| 627 | + | } | |
| 628 | + | } | |
| 629 | + | ||
| 631 | 630 | // use the first revision in our list to generate | |
| 632 | 631 | // the root summary, logs, and tree the user can click | |
| 633 | 632 | revData := &RevData{ |
| ... | ... | @@ -646,7 +645,7 @@ func (c *Config) writeRepo() *BranchOutput { | |
| 646 | 645 | return mainOutput | |
| 647 | 646 | } | |
| 648 | 647 | ||
| 649 | - | func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOutput { | |
| 648 | + | func (c *Config) writeBranch(repo *git.Repository, pageData *PageData, refs []*RefInfo) *BranchOutput { | |
| 650 | 649 | fmt.Printf("compiling (%s) branch (%s)\n", c.RepoName, pageData.RevData.RevName) | |
| 651 | 650 | ||
| 652 | 651 | output := &BranchOutput{} |
| ... | ... | @@ -664,13 +663,21 @@ func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOu | |
| 664 | 663 | output.LastCommit = commit | |
| 665 | 664 | } | |
| 666 | 665 | ||
| 666 | + | tags := []*RefInfo{} | |
| 667 | + | for _, ref := range refs { | |
| 668 | + | if commit.ID.String() == ref.ID { | |
| 669 | + | tags = append(tags, ref) | |
| 670 | + | } | |
| 671 | + | } | |
| 672 | + | ||
| 667 | 673 | logs = append(logs, &CommitData{ | |
| 668 | 674 | URL: c.getCommitURL(commit.ID.String()), | |
| 669 | - | ShortID: commit.ID.String()[:7], | |
| 675 | + | ShortID: getShortID(commit.ID.String()), | |
| 670 | 676 | SummaryStr: commit.Summary(), | |
| 671 | 677 | AuthorStr: commit.Author.Name, | |
| 672 | 678 | WhenStr: timediff.TimeDiff(commit.Author.When), | |
| 673 | 679 | Commit: commit, | |
| 680 | + | Refs: tags, | |
| 674 | 681 | }) | |
| 675 | 682 | } | |
| 676 | 683 |
| ... | ... | @@ -729,8 +736,7 @@ func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOu | |
| 729 | 736 | func main() { | |
| 730 | 737 | var outdir = flag.String("out", "./public", "output directory") | |
| 731 | 738 | var rpath = flag.String("repo", ".", "path to git repo") | |
| 732 | - | var refsFlag = flag.String("refs", "", "list of refs to generate logs and tree (e.g. main,v1)") | |
| 733 | - | var revsFlag = flag.String("revs", "HEAD", "list of revs to generate logs and tree (e.g. c69f86f,7415be1") | |
| 739 | + | var revsFlag = flag.String("revs", "HEAD", "list of revs to generate logs and tree (e.g. main,v1,c69f86f,HEAD") | |
| 734 | 740 | var themeFlag = flag.String("theme", "dracula", "theme to use for site") | |
| 735 | 741 | ||
| 736 | 742 | flag.Parse() |
| ... | ... | @@ -740,16 +746,15 @@ func main() { | |
| 740 | 746 | repoPath, err := filepath.Abs(*rpath) | |
| 741 | 747 | bail(err) | |
| 742 | 748 | ||
| 743 | - | refs := strings.Split(*refsFlag, ",") | |
| 744 | - | if len(refs) == 1 && refs[0] == "" { | |
| 745 | - | refs = []string{} | |
| 746 | - | } | |
| 747 | - | ||
| 748 | 749 | revs := strings.Split(*revsFlag, ",") | |
| 749 | 750 | if len(revs) == 1 && revs[0] == "" { | |
| 750 | 751 | revs = []string{} | |
| 751 | 752 | } | |
| 752 | 753 | ||
| 754 | + | if len(revs) == 0 { | |
| 755 | + | bail(fmt.Errorf("you must provide --revs")) | |
| 756 | + | } | |
| 757 | + | ||
| 753 | 758 | theme := styles.Get(*themeFlag) | |
| 754 | 759 | ||
| 755 | 760 | lg, err := zap.NewProduction() |