From b4dd2dcfad00fa099f7470e1d9fb53e1c38a4f2d Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Tue, 11 May 2021 15:14:00 +0500 Subject: [PATCH] Do nothing in particular --- history/history.go | 7 ++-- history/information.go | 13 ++++++-- history/operations.go | 9 +++-- hyphae/hyphae.go | 4 +-- main.go | 2 +- markup/mycomarkup.go | 76 +----------------------------------------- markup/utils.go | 11 ------ markup/xclusion.go | 7 ++-- web/web.go | 6 ++-- 9 files changed, 31 insertions(+), 104 deletions(-) diff --git a/history/history.go b/history/history.go index b94ee51..4283721 100644 --- a/history/history.go +++ b/history/history.go @@ -1,9 +1,9 @@ +// Package history provides a git wrapper. package history import ( "bytes" "fmt" - "github.com/bouncepaw/mycorrhiza/cfg" "html" "log" "os/exec" @@ -12,6 +12,7 @@ import ( "strings" "time" + "github.com/bouncepaw/mycorrhiza/cfg" "github.com/bouncepaw/mycorrhiza/util" ) @@ -21,10 +22,10 @@ var gitpath string var renameMsgPattern = regexp.MustCompile(`^Rename ‘(.*)’ to ‘.*’`) // Start finds git and initializes git credentials. -func Start(wikiDir string) { +func Start() { path, err := exec.LookPath("git") if err != nil { - log.Fatal("Cound not find the git executable. Check your $PATH.") + log.Fatal("Could not find the git executable. Check your $PATH.") } gitpath = path diff --git a/history/information.go b/history/information.go index 0570e6e..5c39cbf 100644 --- a/history/information.go +++ b/history/information.go @@ -1,7 +1,7 @@ -// information.go -// Things related to gathering existing information. package history +// information.go +// Things related to gathering existing information. import ( "fmt" "github.com/bouncepaw/mycorrhiza/cfg" @@ -174,13 +174,20 @@ func parseRevisionLine(line string) Revision { } } -// See how the file with `filepath` looked at commit with `hash`. +// FileAtRevision shows how the file with the given file path looked at the commit with the hash. It may return an error if git fails. func FileAtRevision(filepath, hash string) (string, error) { out, err := gitsh("show", hash+":"+strings.TrimPrefix(filepath, cfg.WikiDir+"/")) + if err != nil { + return "", err + } return out.String(), err } +// PrimitiveDiffAtRevision generates a plain-text diff for the given filepath at the commit with the given hash. It may return an error if git fails. func PrimitiveDiffAtRevision(filepath, hash string) (string, error) { out, err := silentGitsh("diff", "--unified=1", "--no-color", hash+"~", hash, "--", filepath) + if err != nil { + return "", err + } return out.String(), err } diff --git a/history/operations.go b/history/operations.go index 97e7aa7..9438538 100644 --- a/history/operations.go +++ b/history/operations.go @@ -1,7 +1,7 @@ -// history/operations.go -// Things related to writing history. package history +// history/operations.go +// Things related to writing history. import ( "fmt" "os" @@ -84,7 +84,10 @@ func (hop *HistoryOp) WithFilesRemoved(paths ...string) *HistoryOp { func (hop *HistoryOp) WithFilesRenamed(pairs map[string]string) *HistoryOp { for from, to := range pairs { if from != "" { - os.MkdirAll(filepath.Dir(to), 0777) + if err := os.MkdirAll(filepath.Dir(to), 0777); err != nil { + hop.Errs = append(hop.Errs, err) + continue + } if err := Rename(from, to); err != nil { hop.Errs = append(hop.Errs, err) } diff --git a/hyphae/hyphae.go b/hyphae/hyphae.go index aa9e991..d69fcb6 100644 --- a/hyphae/hyphae.go +++ b/hyphae/hyphae.go @@ -1,4 +1,4 @@ -// The `hyphae` package is for the Hypha type, hypha storage and stuff like that. It shall not depend on mycorrhiza modules other than util. +// Package hyphae is for the Hypha type, hypha storage and stuff like that. It shall not depend on mycorrhiza modules other than util. package hyphae import ( @@ -8,7 +8,7 @@ import ( ) // HyphaPattern is a pattern which all hyphae must match. -var HyphaPattern = regexp.MustCompile(`[^?!:#@><*|"\'&%{}]+`) +var HyphaPattern = regexp.MustCompile(`[^?!:#@><*|"'&%{}]+`) type Hypha struct { sync.RWMutex diff --git a/main.go b/main.go index c6352cf..3d6b34f 100644 --- a/main.go +++ b/main.go @@ -37,7 +37,7 @@ func main() { // Init the subsystems: hyphae.Index(cfg.WikiDir) user.InitUserDatabase() - history.Start(cfg.WikiDir) + history.Start() shroom.SetHeaderLinks() // Network: diff --git a/markup/mycomarkup.go b/markup/mycomarkup.go index f9c9215..f8c4946 100644 --- a/markup/mycomarkup.go +++ b/markup/mycomarkup.go @@ -3,7 +3,6 @@ package markup import ( "fmt" - "html" "regexp" "strings" @@ -43,7 +42,7 @@ func (md *MycoDoc) Lex(recursionLevel int) *MycoDoc { return md } -// AsHtml returns an html representation of the document +// AsHTML returns an html representation of the document func (md *MycoDoc) AsHTML() string { md.html = Parse(md.Lex(0).ast, 0, 0, 0) return md.html @@ -97,76 +96,3 @@ func (md *MycoDoc) ogFillVars() *MycoDoc { func ogTag(property, content string) string { return fmt.Sprintf(``, property, content) } - -/* The rest of this file is currently unused. TODO: use it I guess */ - -type BlockType int - -const ( - BlockH1 = iota - BlockH2 - BlockH3 - BlockH4 - BlockH5 - BlockH6 - BlockRocket - BlockPre - BlockQuote - BlockPara -) - -type CrawlWhere int - -const ( - inSomewhere = iota - inPre - inEnd -) - -func crawl(name, content string) []string { - stateStack := []CrawlWhere{inSomewhere} - - startsWith := func(token string) bool { - return strings.HasPrefix(content, token) - } - - pop := func() { - stateStack = stateStack[:len(stateStack)-1] - } - - push := func(s CrawlWhere) { - stateStack = append(stateStack, s) - } - - readln := func(c string) (string, string) { - parts := strings.SplitN(c, "\n", 1) - return parts[0], parts[1] - } - - preAcc := "" - line := "" - - for { - switch stateStack[0] { - case inSomewhere: - switch { - case startsWith("```"): - push(inPre) - _, content = readln(content) - default: - } - case inPre: - switch { - case startsWith("```"): - pop() - _, content = readln(content) - default: - line, content = readln(content) - preAcc += html.EscapeString(line) - } - } - break - } - - return []string{} -} diff --git a/markup/utils.go b/markup/utils.go index 420697a..9cc89b7 100644 --- a/markup/utils.go +++ b/markup/utils.go @@ -10,14 +10,3 @@ func remover(prefix string) func(string) string { return strings.TrimSpace(strings.TrimPrefix(l, prefix)) } } - -// Remove #, ## or ### from beginning of `line`. -func removeHeadingOctothorps(line string) string { - f := remover("#") - return f(f(f(line))) -} - -// Return a canonical representation of a hypha `name`. -func canonicalName(name string) string { - return strings.ToLower(strings.ReplaceAll(strings.TrimSpace(name), " ", "_")) -} diff --git a/markup/xclusion.go b/markup/xclusion.go index a5df6c8..c20dc96 100644 --- a/markup/xclusion.go +++ b/markup/xclusion.go @@ -2,6 +2,7 @@ package markup import ( "fmt" + "github.com/bouncepaw/mycorrhiza/util" "path" "strconv" "strings" @@ -67,11 +68,11 @@ func parseTransclusion(line, hyphaName string) (xclusion Transclusion) { func xclCanonicalName(hyphaName, xclName string) string { switch { case strings.HasPrefix(xclName, "./"): - return canonicalName(path.Join(hyphaName, strings.TrimPrefix(xclName, "./"))) + return util.CanonicalName(path.Join(hyphaName, strings.TrimPrefix(xclName, "./"))) case strings.HasPrefix(xclName, "../"): - return canonicalName(path.Join(path.Dir(hyphaName), strings.TrimPrefix(xclName, "../"))) + return util.CanonicalName(path.Join(path.Dir(hyphaName), strings.TrimPrefix(xclName, "../"))) default: - return canonicalName(xclName) + return util.CanonicalName(xclName) } } diff --git a/web/web.go b/web/web.go index 7f2fa8e..1a9df12 100644 --- a/web/web.go +++ b/web/web.go @@ -5,9 +5,6 @@ package web import ( "fmt" - "github.com/bouncepaw/mycorrhiza/assets" - "github.com/bouncepaw/mycorrhiza/cfg" - "github.com/bouncepaw/mycorrhiza/util" "io" "io/ioutil" "log" @@ -16,7 +13,10 @@ import ( "os" "strings" + "github.com/bouncepaw/mycorrhiza/assets" + "github.com/bouncepaw/mycorrhiza/cfg" "github.com/bouncepaw/mycorrhiza/user" + "github.com/bouncepaw/mycorrhiza/util" "github.com/bouncepaw/mycorrhiza/views" )