diff --git a/README.md b/README.md
index 4ce729e..2de40a4 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ Project heavily inspired by the amazing
- [ ] Add a subcommand to dump the embedded templates so they can be
modified.
- [ ] Take binary files into account.
-- [X] Limit the output for large diffs. Add a "X commits remaining"
+- [ ] Limit the output for large diffs. Add a "X commits remaining"
message if necessary.
- [ ] Generate files in temporal directory and replace the final one
when everything is ready.
diff --git a/cmd.go b/cmd.go
index 5d7ede2..07856d8 100644
--- a/cmd.go
+++ b/cmd.go
@@ -14,7 +14,7 @@ type repoCmd struct {
}
func (r *repoCmd) Run() error {
- return generateRepo(r.Path, r.LogLimit)
+ return generateRepo(r.Path)
}
var cli struct {
diff --git a/gitssg.go b/gitssg.go
index 2e75034..4c4b6a7 100644
--- a/gitssg.go
+++ b/gitssg.go
@@ -3,10 +3,8 @@ package main
import (
"bytes"
"embed"
- "errors"
"fmt"
"html/template"
- "io"
"log/slog"
"os"
"path/filepath"
@@ -44,14 +42,6 @@ type CommitFile struct {
Size int64
}
-type FileStats struct {
- Name string
- Mode string // ToDo: is the name correct here?
- Adds int
- Dels int
- Total int
-}
-
type CommitInfo struct {
Hash string
ParentHash string
@@ -62,7 +52,6 @@ type CommitInfo struct {
Files int
Adds int
Dels int
- FileStats []*FileStats
}
//go:embed templates
@@ -101,9 +90,6 @@ var funcMap = template.FuncMap{
"timeLongFormat": func(t time.Time) string {
return t.Format(timeLongFormatStr)
},
- "repeatStr": func(s string, n int) string {
- return strings.Repeat(s, n)
- },
}
func executeTemplate(name string, data any) ([]byte, error) {
@@ -219,8 +205,8 @@ func generateIndex(args []string) error {
return nil
}
-func generateRepo(path string, logLimit int) error {
- slog.Debug("Generating repository", "path", path, "logLimit", logLimit)
+func generateRepo(path string) error {
+ slog.Debug("Generating repository", "path", path)
repoInfo := &RepoInfo{Name: strings.TrimSuffix(filepath.Base(path), ".git")}
@@ -335,6 +321,7 @@ func generateRepo(path string, logLimit int) error {
}
// generate the files index file
+ // ToDo: bundle execute and write into a function
filesData := map[string]any{"repoInfo": repoInfo, "files": files, "relpath": ""}
filesDstpath := filepath.Join(repoInfo.Name, "files.html")
if err := executeTemplateToFile("files", filesData, filesDstpath); err != nil {
@@ -347,52 +334,23 @@ func generateRepo(path string, logLimit int) error {
return fmt.Errorf("cannot get git log for repository: %w", err)
}
- i := 0
- remaining := 0
commits := []*CommitInfo{}
- for {
- i++
- c, err := cIter.Next()
- if errors.Is(err, io.EOF) {
- break
- }
- if err != nil {
- return fmt.Errorf("cannot get next commit while processing log: %w", err)
- }
-
+ ciErr := cIter.ForEach(func(c *object.Commit) error {
slog.Debug("Processing commit", "hash", c.Hash)
- if i > logLimit {
- remaining++
- slog.Debug("Limit reached while processing log", "iteration", i, "remaining", remaining)
- continue
- }
-
// ToDo: is this the best way to get the number of files?
fstats, err := c.Stats()
if err != nil {
return fmt.Errorf("cannot get commit stats %s: %w", c.Hash, err)
}
- fileStats := make([]*FileStats, len(fstats))
- for i, fs := range fstats {
- fileStats[i] = &FileStats{
- Name: fs.Name,
- Mode: "",
- Adds: fs.Addition,
- Dels: fs.Deletion,
- Total: fs.Addition + fs.Deletion,
- }
- }
-
commit := &CommitInfo{
Hash: c.Hash.String(),
Date: c.Author.When, // ToDo: author when vs commiter when?
Msg: c.Message,
AuthorName: c.Author.Name,
AuthorEmail: c.Author.Email,
- Files: len(fstats), // ToDo: call len on FileStats
- FileStats: fileStats,
+ Files: len(fstats),
}
if parent, _ := c.Parent(0); parent != nil {
@@ -413,14 +371,14 @@ func generateRepo(path string, logLimit int) error {
if err := executeTemplateToFile("commit", data, dstpath); err != nil {
return fmt.Errorf("cannot execute template %q to file %q: %w", "commit", dstpath, err)
}
+
+ return nil
+ })
+ if ciErr != nil {
+ return fmt.Errorf("error while processing log: %w", ciErr)
}
- logData := map[string]any{
- "repoInfo": repoInfo,
- "commits": commits,
- "relpath": "",
- "remaining": remaining,
- }
+ logData := map[string]any{"repoInfo": repoInfo, "commits": commits, "relpath": ""}
logDstpath := filepath.Join(repoInfo.Name, "log.html")
if err := executeTemplateToFile("log", logData, logDstpath); err != nil {
return fmt.Errorf("cannot execute template %q to file %q: %w", "file", logDstpath, err)
diff --git a/templates/commit.html.tmpl b/templates/commit.html.tmpl
index 61caf92..162d423 100644
--- a/templates/commit.html.tmpl
+++ b/templates/commit.html.tmpl
@@ -40,38 +40,18 @@
{{.commit.Msg}}
Diffstat:
-
- {{range $i, $fs := .commit.FileStats}}
-
- {{$fs.Mode}} |
- {{$fs.Name}} |
- | |
- {{$fs.Total}} |
- {{if gt $fs.Adds 0}}{{repeatStr "+" $fs.Adds}}{{end}}{{if gt $fs.Dels 0}}{{repeatStr "-" $fs.Dels}}{{end}} |
-
- {{end}}
-
{{.commit.Files}} file{{if ne .commit.Files 1}}s{{end}} changed, {{.commit.Adds}} insertion{{if ne .commit.Adds 1}}s{{end}}(+), {{.commit.Dels}} deletion{{if ne .commit.Dels 1}}s{{end}}(-)
-
diff --git a/stagit-index.c b/stagit-index.c
-@@ -179,7 +179,7 @@ main(int argc, char *argv[])
- int i, ret = 0;
+
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
diff --git a/LICENSE b/LICENSE
+ @@ -1,6 +1,6 @@
+ MIT/X Consortium License
- if (argc < 2) {
-- fprintf(stderr, "%s [repodir...]\n", argv[0]);
-+ fprintf(stderr, "usage: %s [repodir...]\n", argv[0]);
- return 1;
- }
-
-diff --git a/stagit.c b/stagit.c
-@@ -1184,7 +1184,7 @@ writerefs(FILE *fp)
- void
- usage(char *argv0)
- {
-- fprintf(stderr, "%s [-c cachefile | -l commits] "
-+ fprintf(stderr, "usage: %s [-c cachefile | -l commits] "
- "[-u baseurl] repodir\n", argv0);
- exit(1);
- }
-
+ -(c) 2015-2022 Hiltjo Posthuma <hiltjo@codemadness.org>
+ +(c) 2015-2024 Hiltjo Posthuma <hiltjo@codemadness.org>
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+