- commit
- aedcf3c
- parent
- ec17d58
- author
- Eric Bower
- date
- 2025-03-23 23:23:14 -0400 EDT
chore: comments and cleanup
M
Makefile
+8,
-0
1@@ -21,6 +21,14 @@ fmt:
2 go fmt ./...
3 .PHONY: fmt
4
5+lint:
6+ golangci-lint run -E goimports -E godot --timeout 10m
7+.PHONY: lint
8+
9+test:
10+ go test ./...
11+.PHONY: test
12+
13 static: build clean
14 ./pgit \
15 --out ./public \
M
main.go
+14,
-11
1@@ -75,7 +75,6 @@ type RevInfo interface {
2 Name() string
3 }
4
5-// revision data
6 type RevData struct {
7 id string
8 name string
9@@ -239,7 +238,7 @@ func diffFileType(_type git.DiffFileType) string {
10 return ""
11 }
12
13-// converts contents of files in git tree to pretty formatted code
14+// converts contents of files in git tree to pretty formatted code.
15 func (c *Config) parseText(filename string, text string) (string, error) {
16 lexer := lexers.Match(filename)
17 if lexer == nil {
18@@ -344,7 +343,8 @@ func (c *Config) copyStatic(dir string) error {
19 bail(err)
20 fp := filepath.Join(c.Outdir, e.Name())
21 c.Logger.Info("writing", "filepath", fp)
22- os.WriteFile(fp, w, 0644)
23+ err = os.WriteFile(fp, w, 0644)
24+ bail(err)
25 }
26
27 return nil
28@@ -522,8 +522,8 @@ func (c *Config) getRefsURL() template.URL {
29 }
30
31 // controls the url for trees and logs
32-// /logs/getRevIDForURL()/index.html
33-// /tree/getRevIDForURL()/item/file.x.html
34+// - /logs/getRevIDForURL()/index.html
35+// - /tree/getRevIDForURL()/item/file.x.html.
36 func getRevIDForURL(info RevInfo) string {
37 return info.Name()
38 }
39@@ -625,7 +625,6 @@ func (c *Config) writeRepo() *BranchOutput {
40 }
41
42 refInfoMap := map[string]*RefInfo{}
43- mainOutput := &BranchOutput{}
44 for _, revData := range revs {
45 refInfoMap[revData.Name()] = &RefInfo{
46 ID: revData.ID(),
47@@ -664,6 +663,9 @@ func (c *Config) writeRepo() *BranchOutput {
48 return urlI > urlJ
49 })
50
51+ // we assume the first revision in the list is the "main" revision which mostly
52+ // means that's the README we use for the default summary page.
53+ mainOutput := &BranchOutput{}
54 var wg sync.WaitGroup
55 for i, revData := range revs {
56 c.Logger.Info("writing revision", "revision", revData.Name())
57@@ -758,7 +760,7 @@ func (tw *TreeWalker) calcBreadcrumbs(curpath string) []*Breadcrumb {
58 return crumbs
59 }
60
61-func FilenameToDevIcon(filename string) string {
62+func filenameToDevIcon(filename string) string {
63 ext := filepath.Ext(filename)
64 extMappr := map[string]string{
65 ".html": "html5",
66@@ -831,7 +833,7 @@ func (tw *TreeWalker) NewTreeItem(entry *git.TreeEntry, curpath string, crumbs [
67 "index.html",
68 )
69 } else if typ == git.ObjectBlob {
70- item.Icon = FilenameToDevIcon(item.Name)
71+ item.Icon = filenameToDevIcon(item.Name)
72 }
73 item.URL = fpath
74
75@@ -1056,8 +1058,8 @@ func main() {
76 var revsFlag = flag.String("revs", "HEAD", "list of revs to generate logs and tree (e.g. main,v1,c69f86f,HEAD)")
77 var themeFlag = flag.String("theme", "dracula", "theme to use for site")
78 var labelFlag = flag.String("label", "", "pretty name for the subdir where we create the repo, default is last folder in --repo")
79- var cloneFlag = flag.String("clone-url", "", "git clone URL")
80- var homeFlag = flag.String("home-url", "", "URL for breadcumbs to get to list of repositories")
81+ var cloneFlag = flag.String("clone-url", "", "git clone URL for upstream")
82+ var homeFlag = flag.String("home-url", "", "URL for breadcumbs to go to root page, hidden if empty")
83 var descFlag = flag.String("desc", "", "description for repo")
84 var rootRelativeFlag = flag.String("root-relative", "/", "html root relative")
85 var maxCommitsFlag = flag.Int("max-commits", 0, "maximum number of commits to generate")
86@@ -1113,7 +1115,8 @@ func main() {
87 }
88
89 config.writeRepo()
90- config.copyStatic("static")
91+ err = config.copyStatic("static")
92+ bail(err)
93
94 styles := style(*theme)
95 fmt.Println(styles)