repos / pgit

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

commit
de8062b
parent
a41a46b
author
Eric Bower
date
2023-08-04 19:47:29 +0000 UTC
progress
2 files changed,  +22, -23
M Makefile
+4, -0
1@@ -9,3 +9,7 @@ build:
2 static: build clean
3 	./pgit
4 .PHONY:
5+
6+deploy:
7+	scp -R ./public/* erock@pgs.sh:/git
8+.PHONY: deploy
M main.go
+18, -23
 1@@ -187,7 +187,7 @@ func writeRootSummary(data *PageData) {
 2 func writeSummary(data *PageData) {
 3 	writeHtml(&WriteData{
 4 		Name:     "index.html",
 5-		Subdir: filepath.Join("tree", data.RevName),
 6+		Subdir:   filepath.Join("tree", data.RevName),
 7 		Template: "./html/summary.page.tmpl",
 8 		Data:     data,
 9 		RepoName: data.Repo.Name,
10@@ -197,7 +197,7 @@ func writeSummary(data *PageData) {
11 func writeTree(data *PageData) {
12 	writeHtml(&WriteData{
13 		Name:     "index.html",
14-		Subdir: filepath.Join("tree", data.RevName),
15+		Subdir:   filepath.Join("tree", data.RevName),
16 		Template: "./html/tree.page.tmpl",
17 		Data:     data,
18 		RepoName: data.Repo.Name,
19@@ -207,7 +207,7 @@ func writeTree(data *PageData) {
20 func writeLog(data *PageData) {
21 	writeHtml(&WriteData{
22 		Name:     "index.html",
23-		Subdir: filepath.Join("logs", data.RevName),
24+		Subdir:   filepath.Join("logs", data.RevName),
25 		Template: "./html/log.page.tmpl",
26 		Data:     data,
27 		RepoName: data.Repo.Name,
28@@ -247,13 +247,7 @@ func writeHTMLTreeFiles(data *PageData) {
29 }
30 
31 func writeLogDiffs(project string, repo *git.Repository, data *PageData, cache map[string]bool) {
32-	var lastCommit *CommitData
33 	for _, commit := range data.Log {
34-		if lastCommit == nil {
35-			lastCommit = commit
36-			continue
37-		}
38-
39 		commitID := commit.ID.String()
40 
41 		if cache[commitID] {
42@@ -262,25 +256,27 @@ func writeLogDiffs(project string, repo *git.Repository, data *PageData, cache m
43 			cache[commitID] = true
44 		}
45 
46-		diff, err := repo.Diff(
47-			lastCommit.ID.String(),
48-			0,
49-			0,
50-			0,
51-			git.DiffOptions{Base: commitID},
52-		)
53-		bail(err)
54-
55 		ancestors, err := commit.Ancestors()
56 		bail(err)
57 
58-		parentID := ""
59+		// if no ancestors exist then we are at initial commit
60+		parent := commit
61 		if len(ancestors) > 0 {
62-			parent := ancestors[0]
63-			if parent != nil {
64-				parentID = parent.ID.String()
65+			pt := ancestors[0]
66+			parent = &CommitData{
67+				Commit: pt,
68+				URL:    CommitURL(project, pt.ID.String()),
69 			}
70 		}
71+		parentID := parent.ID.String()
72+
73+		diff, err := repo.Diff(
74+			parentID,
75+			0,
76+			0,
77+			0,
78+			git.DiffOptions{Base: commitID},
79+		)
80 
81 		commitData := &CommitPageData{
82 			Commit:    commit,
83@@ -299,7 +295,6 @@ func writeLogDiffs(project string, repo *git.Repository, data *PageData, cache m
84 			Subdir:   "commits",
85 			Repo:     data.Repo,
86 		})
87-		lastCommit = commit
88 	}
89 }
90