repos / pgit

static site generator for git
git clone https://github.com/picosh/pgit.git

commit
fae1d37
parent
134e2ae
author
Eric Bower
date
2023-08-07 14:20:29 +0000 UTC
wrap
3 files changed,  +66, -46
M config.yaml
+3, -0
 1@@ -5,11 +5,14 @@ repos:
 2       - main
 3       - v1.0.0
 4     desc: pico services - prose.sh, lists.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
 5+    hide_tree_last_commit: true
 6   - path: /home/erock/dev/pico/pico-ops
 7     refs:
 8       - main
 9     desc: infra for pico services
10+    hide_tree_last_commit: true
11   - path: /home/erock/dev/app-ui
12     refs:
13       - main
14+      - v50
15     desc: aptible's paas web application
M html/tree.page.tmpl
+3, -0
 1@@ -13,9 +13,12 @@
 2       </div>
 3 
 4       <div class="flex items-center gap">
 5+        {{if $.Repo.HideTreeLastCommit}}
 6+        {{else}}
 7         <div class="flex-1">
 8           <a href="{{.CommitURL}}" title="{{.Summary}}">{{.When}}</a>
 9         </div>
10+        {{end}}
11         <div class="tree-size">
12           {{if .IsTextFile}}{{.NumLines}} L{{else}}{{.Size}}{{end}}
13         </div>
M main.go
+60, -46
  1@@ -32,16 +32,17 @@ type IndexPage struct {
  2 }
  3 
  4 type RepoData struct {
  5-	Name       string
  6-	Desc       string
  7-	SummaryURL string
  8-	TreeURL    string
  9-	LogURL     string
 10-	RefsURL    string
 11-	CloneURL   string
 12-	MaxCommits int
 13-	RevName    string
 14-	Readme     string
 15+	Name               string
 16+	Desc               string
 17+	SummaryURL         string
 18+	TreeURL            string
 19+	LogURL             string
 20+	RefsURL            string
 21+	CloneURL           string
 22+	MaxCommits         int
 23+	RevName            string
 24+	Readme             string
 25+	HideTreeLastCommit bool
 26 }
 27 
 28 type CommitData struct {
 29@@ -129,11 +130,12 @@ type BranchOutput struct {
 30 }
 31 
 32 type RepoConfig struct {
 33-	Path       string   `mapstructure:"path"`
 34-	Refs       []string `mapstructure:"refs"`
 35-	Desc       string   `mapstructure:"desc"`
 36-	MaxCommits int      `mapstructure:"max_commits"`
 37-	Readme     string   `mapstructure:"readme"`
 38+	Path               string   `mapstructure:"path"`
 39+	Refs               []string `mapstructure:"refs"`
 40+	Desc               string   `mapstructure:"desc"`
 41+	MaxCommits         int      `mapstructure:"max_commits"`
 42+	Readme             string   `mapstructure:"readme"`
 43+	HideTreeLastCommit bool     `mapstructure:"hide_tree_last_commit"`
 44 }
 45 
 46 type Config struct {
 47@@ -454,18 +456,6 @@ func (c *Config) writeRepo(config *RepoConfig) *BranchOutput {
 48 	}
 49 	_, revName := filepath.Split(rev.Refspec)
 50 
 51-	repoData := &RepoData{
 52-		Name:       name,
 53-		Desc:       config.Desc,
 54-		MaxCommits: config.MaxCommits,
 55-		SummaryURL: fmt.Sprintf("/%s/index.html", name),
 56-		TreeURL:    fmt.Sprintf("/%s/tree/%s/index.html", name, revName),
 57-		LogURL:     fmt.Sprintf("/%s/logs/%s/index.html", name, revName),
 58-		RefsURL:    fmt.Sprintf("/%s/refs.html", name),
 59-		CloneURL:   fmt.Sprintf("https://%s/%s.git", c.URL, name),
 60-		RevName:    revName,
 61-	}
 62-
 63 	refInfoMap := map[string]*RefInfo{}
 64 	var mainOutput *BranchOutput
 65 	claimed := false
 66@@ -481,15 +471,17 @@ func (c *Config) writeRepo(config *RepoConfig) *BranchOutput {
 67 			}
 68 
 69 			branchRepo := &RepoData{
 70-				Name:       name,
 71-				Desc:       config.Desc,
 72-				MaxCommits: config.MaxCommits,
 73-				SummaryURL: fmt.Sprintf("/%s/index.html", name),
 74-				TreeURL:    fmt.Sprintf("/%s/tree/%s/index.html", name, revn),
 75-				LogURL:     fmt.Sprintf("/%s/logs/%s/index.html", name, revn),
 76-				RefsURL:    fmt.Sprintf("/%s/refs.html", name),
 77-				CloneURL:   fmt.Sprintf("https://%s/%s.git", c.URL, name),
 78-				RevName:    revn,
 79+				Name:               name,
 80+				Desc:               config.Desc,
 81+				MaxCommits:         config.MaxCommits,
 82+				Readme:             config.Readme,
 83+				HideTreeLastCommit: config.HideTreeLastCommit,
 84+				SummaryURL:         fmt.Sprintf("/%s/index.html", name),
 85+				TreeURL:            fmt.Sprintf("/%s/tree/%s/index.html", name, revn),
 86+				LogURL:             fmt.Sprintf("/%s/logs/%s/index.html", name, revn),
 87+				RefsURL:            fmt.Sprintf("/%s/refs.html", name),
 88+				CloneURL:           fmt.Sprintf("https://%s/%s.git", c.URL, name),
 89+				RevName:            revn,
 90 			}
 91 
 92 			data := &PageData{
 93@@ -531,6 +523,17 @@ func (c *Config) writeRepo(config *RepoConfig) *BranchOutput {
 94 		return urlI > urlJ
 95 	})
 96 
 97+	repoData := &RepoData{
 98+		Name:       name,
 99+		Desc:       config.Desc,
100+		SummaryURL: fmt.Sprintf("/%s/index.html", name),
101+		TreeURL:    fmt.Sprintf("/%s/tree/%s/index.html", name, revName),
102+		LogURL:     fmt.Sprintf("/%s/logs/%s/index.html", name, revName),
103+		RefsURL:    fmt.Sprintf("/%s/refs.html", name),
104+		CloneURL:   fmt.Sprintf("https://%s/%s.git", c.URL, name),
105+		RevName:    revName,
106+	}
107+
108 	data := &PageData{
109 		Rev:     rev,
110 		RevName: revName,
111@@ -544,6 +547,8 @@ func (c *Config) writeRepo(config *RepoConfig) *BranchOutput {
112 }
113 
114 func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOutput {
115+	fmt.Printf("compiling (%s) branch (%s)\n", pageData.Repo.Name, pageData.Repo.RevName)
116+
117 	output := &BranchOutput{}
118 	pageSize := pageData.Repo.MaxCommits
119 	if pageSize == 0 {
120@@ -576,18 +581,25 @@ func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOu
121 	for _, entry := range treeEntries {
122 		entry.Path = strings.TrimPrefix(entry.Path, "/")
123 
124-		lastCommits, err := repo.RevList([]string{pageData.Rev.Refspec}, git.RevListOptions{
125-			Path: entry.Path,
126-		})
127-		bail(err)
128+		var lastCommits []*git.Commit
129+		// `git rev-list` is pretty expensive here, so we have a flag to disable
130+		if pageData.Repo.HideTreeLastCommit {
131+			fmt.Println("skipping finding last commit for each file")
132+		} else {
133+			lastCommits, err = repo.RevList([]string{pageData.Rev.Refspec}, git.RevListOptions{
134+				Path:           entry.Path,
135+				CommandOptions: git.CommandOptions{Args: []string{"-1"}},
136+			})
137+			bail(err)
138 
139-		var lc *git.Commit
140-		if len(lastCommits) > 0 {
141-			lc = lastCommits[0]
142+			var lc *git.Commit
143+			if len(lastCommits) > 0 {
144+				lc = lastCommits[0]
145+			}
146+			entry.CommitURL = commitURL(pageData.Repo.Name, lc.ID.String())
147+			entry.Summary = lc.Summary()
148+			entry.When = timediff.TimeDiff(lc.Author.When)
149 		}
150-		entry.CommitURL = commitURL(pageData.Repo.Name, lc.ID.String())
151-		entry.Summary = lc.Summary()
152-		entry.When = timediff.TimeDiff(lc.Author.When)
153 		entry.URL = filepath.Join(
154 			"/",
155 			pageData.Repo.Name,
156@@ -601,6 +613,8 @@ func (c *Config) writeBranch(repo *git.Repository, pageData *PageData) *BranchOu
157 	pageData.Log = logs
158 	pageData.Tree = treeEntries
159 
160+	fmt.Printf("compilation complete (%s) branch (%s)", pageData.Repo.Name, pageData.Repo.RevName)
161+
162 	writeLog(pageData)
163 	readme := writeHTMLTreeFiles(pageData)
164 	c.writeLogDiffs(repo, pageData)