cmd/sgblog-comment-add/main.go | 17 ++++++++++++++--- cmd/sgblog/main.go | 10 +++++----- common.go | 7 +++++++ diff --git a/cmd/sgblog-comment-add/main.go b/cmd/sgblog-comment-add/main.go index 8bae15fdc1dda25f9a92c5f35b1505ebb1eb5d6f..8b46c555929ca3a17ddf06e19486b30d5e957e90 100644 --- a/cmd/sgblog-comment-add/main.go +++ b/cmd/sgblog-comment-add/main.go @@ -35,9 +35,8 @@ "syscall" "time" "go.cypherpunks.ru/netstring/v2" + "go.stargrave.org/sgblog" ) - -const WhenFmt = "2006-01-02 15:04:05Z07:00" func main() { gitCmd := flag.String("git-cmd", "/usr/local/bin/git", "Path to git executable") @@ -45,6 +44,11 @@ gitDir := flag.String("git-dir", "", "Path to .git repository") notesRef := flag.String("ref", "comments", "notes reference name") umask := flag.String("umask", "027", "umask value") dryRun := flag.Bool("dryrun", false, "Show comment, do not add") + committerEmail := flag.String( + "committer-email", + "comment@blog.example.com", + "Git committer's email", + ) flag.Parse() uid := syscall.Geteuid() if err := syscall.Setuid(uid); err != nil { @@ -111,7 +115,7 @@ w := netstring.NewWriter(buf) w.WriteChunk([]byte(fmt.Sprintf( "From: %s\nDate: %s\n\n%s", from, - time.Now().UTC().Format(WhenFmt), + time.Now().UTC().Format(sgblog.WhenFmt), strings.Join(lines, "\n"), ))) @@ -124,6 +128,13 @@ cmd = exec.Command( *gitCmd, "--git-dir", *gitDir, "notes", "--ref", *notesRef, "add", "-F", "-", "-f", subj, + ) + cmd.Env = append( + cmd.Env, + "GIT_AUTHOR_NAME=SGBlog "+sgblog.Version, + "GIT_AUTHOR_EMAIL="+*committerEmail, + "GIT_COMMITTER_NAME=SGBlog "+sgblog.Version, + "GIT_COMMITTER_EMAIL="+*committerEmail, ) cmd.Stdin = buf if err = cmd.Run(); err != nil { diff --git a/cmd/sgblog/main.go b/cmd/sgblog/main.go index 5ee199e331a0720b2a92fb9a79b896fd878c0d0e..2173580bc2ebdc2bad162d61614c5edd1b5c5c75 100644 --- a/cmd/sgblog/main.go +++ b/cmd/sgblog/main.go @@ -39,6 +39,7 @@ "strings" "github.com/hjson/hjson-go" "go.cypherpunks.ru/netstring/v2" + "go.stargrave.org/sgblog" "golang.org/x/crypto/blake2b" "golang.org/x/tools/blog/atom" "gopkg.in/src-d/go-git.v4" @@ -48,12 +49,10 @@ ) const ( PageEntries = 50 - WhenFmt = "2006-01-02 15:04:05Z07:00" AtomFeed = "feed.atom" ) var ( - Version = "0.2.0" sha1DigestRe = regexp.MustCompilePOSIX("([0-9a-f]{40,40})") defaultLinks = []string{} repo *git.Repository @@ -204,7 +203,7 @@ %s `, - Version, title, + sgblog.Version, title, strings.Join(append(defaultLinks, additional...), "\n "), ) } @@ -259,6 +258,7 @@ if err != nil { panic(err) } etagHash.Write([]byte("SGBLOG")) + etagHash.Write([]byte(sgblog.Version)) etagHash.Write([]byte(cfg.GitPath)) etagHash.Write([]byte(cfg.Branch)) etagHash.Write([]byte(cfg.Title)) @@ -409,7 +409,7 @@ "%d%s"+ "%s"+ "%d%s"+ "%s\n", - commentN, entry.commit.Author.When.Format(WhenFmt), + commentN, entry.commit.Author.When.Format(sgblog.WhenFmt), makeA(cfg.URLPrefix+"/"+entry.commit.Hash.String(), lines[0]), len(lines)-2, commentsValue, @@ -539,7 +539,7 @@ etagHash.Write(commentsRaw) checkETag(etagHash) lines := msgSplit(commit.Message) title := lines[0] - when := commit.Author.When.Format(WhenFmt) + when := commit.Author.When.Format(sgblog.WhenFmt) os.Stdout.Write([]byte(startHeader(etagHash, gzipWriter != nil))) links := []string{} var parent string diff --git a/common.go b/common.go new file mode 100644 index 0000000000000000000000000000000000000000..183ac3d2bc2f5fcaff449ac3b6436112feb4dd53 --- /dev/null +++ b/common.go @@ -0,0 +1,7 @@ +// SGBlog -- Git-based CGI blogging engine +package sgblog + +const ( + WhenFmt = "2006-01-02 15:04:05Z07:00" + Version = "0.3.0" +)