]> Sergey Matveev's repositories - sgblog.git/blobdiff - cmd/sgblog/main.go
Comments Atom feeds
[sgblog.git] / cmd / sgblog / main.go
index 06f1e37f0da977cc4e453e269632005e881ed52e..05654c0760942625cf2c8fcd04be124c60379bba 100644 (file)
@@ -1,5 +1,5 @@
 /*
-SGBlog -- Git-based CGI/inetd blogging/phlogging engine
+SGBlog -- Git-backed CGI/inetd blogging/phlogging engine
 Copyright (C) 2020 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
@@ -15,11 +15,13 @@ You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-// Git-based CGI/inetd blogging/phlogging engine
+// Git-backed CGI/inetd blogging/phlogging engine
 package main
 
 import (
        "bytes"
+       "crypto/sha1"
+       "fmt"
        "io/ioutil"
        "os"
        "regexp"
@@ -36,9 +38,10 @@ const (
 )
 
 var (
-       sha1DigestRe = regexp.MustCompilePOSIX("([0-9a-f]{40,40})")
+       sha1DigestRe = regexp.MustCompilePOSIX(fmt.Sprintf("([0-9a-f]{%d,%d})", sha1.Size*2, sha1.Size*2))
        repo         *git.Repository
        notesTree    *object.Tree
+       commentsRef  *plumbing.Reference
        commentsTree *object.Tree
 )
 
@@ -134,7 +137,6 @@ func initRepo(cfg *Cfg) (*plumbing.Hash, error) {
        headHash := head.Hash()
        if notes, err := repo.Notes(); err == nil {
                var notesRef *plumbing.Reference
-               var commentsRef *plumbing.Reference
                notes.ForEach(func(ref *plumbing.Reference) error {
                        switch string(ref.Name()) {
                        case "refs/notes/commits":