mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-06-05 04:24:05 +00:00
Make commits on text edits, commits on binary edits WIP
This commit is contained in:
parent
b52419152a
commit
c03f8be5cd
@ -11,24 +11,14 @@ import (
|
|||||||
"github.com/go-git/go-git/v5/plumbing/object"
|
"github.com/go-git/go-git/v5/plumbing/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
type OpType int
|
||||||
// 10 should be enough
|
|
||||||
const ShortHashLength = 10
|
|
||||||
|
|
||||||
type EditType int
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TypeRename EditType = iota
|
TypeNone OpType = iota
|
||||||
TypeDelete
|
|
||||||
TypeEditText
|
TypeEditText
|
||||||
TypeEditBinary
|
TypeEditBinary
|
||||||
)
|
)
|
||||||
|
|
||||||
type Revision struct {
|
|
||||||
ShortHash [ShortHashLength]byte
|
|
||||||
Type EditType
|
|
||||||
}*/
|
|
||||||
|
|
||||||
var WikiRepo *git.Repository
|
var WikiRepo *git.Repository
|
||||||
var Worktree *git.Worktree
|
var Worktree *git.Worktree
|
||||||
|
|
||||||
@ -47,11 +37,20 @@ func Start(wikiDir string) {
|
|||||||
|
|
||||||
type HistoryOp struct {
|
type HistoryOp struct {
|
||||||
Errs []error
|
Errs []error
|
||||||
|
opType OpType
|
||||||
userMsg string
|
userMsg string
|
||||||
signature *object.Signature
|
signature *object.Signature
|
||||||
isDone bool
|
isDone bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Operation(opType OpType) *HistoryOp {
|
||||||
|
hop := &HistoryOp{
|
||||||
|
Errs: []error{},
|
||||||
|
opType: opType,
|
||||||
|
}
|
||||||
|
return hop
|
||||||
|
}
|
||||||
|
|
||||||
// WithFiles stages all passed `paths`. Paths can be rooted or not.
|
// WithFiles stages all passed `paths`. Paths can be rooted or not.
|
||||||
func (hop *HistoryOp) WithFiles(paths ...string) *HistoryOp {
|
func (hop *HistoryOp) WithFiles(paths ...string) *HistoryOp {
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
@ -63,8 +62,8 @@ func (hop *HistoryOp) WithFiles(paths ...string) *HistoryOp {
|
|||||||
return hop
|
return hop
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithUserMsg sets what user message will be used for the future commit. If it == "", a default one be used. If user messages are not supported for this one type of history operation, this user message will be dropped. If user messages exceeds one line, it is stripped down.
|
// WithMsg sets what message will be used for the future commit. If user message exceeds one line, it is stripped down.
|
||||||
func (hop *HistoryOp) WithUserMsg(userMsg string) *HistoryOp {
|
func (hop *HistoryOp) WithMsg(userMsg string) *HistoryOp {
|
||||||
// Isn't it too imperative?
|
// Isn't it too imperative?
|
||||||
var firstLine string
|
var firstLine string
|
||||||
for _, ch := range userMsg {
|
for _, ch := range userMsg {
|
||||||
@ -73,7 +72,7 @@ func (hop *HistoryOp) WithUserMsg(userMsg string) *HistoryOp {
|
|||||||
}
|
}
|
||||||
firstLine += string(ch)
|
firstLine += string(ch)
|
||||||
}
|
}
|
||||||
hop.userMsg = userMsg
|
hop.userMsg = firstLine
|
||||||
return hop
|
return hop
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,12 +107,10 @@ func (hop *HistoryOp) Apply() *HistoryOp {
|
|||||||
return hop
|
return hop
|
||||||
}
|
}
|
||||||
|
|
||||||
func CommitTest() {
|
func Rename(from, to string) error {
|
||||||
(&HistoryOp{}).
|
log.Println(util.ShorterPath(from), util.ShorterPath(to))
|
||||||
WithUserMsg("This is a test commit").
|
_, err := Worktree.Move(util.ShorterPath(from), util.ShorterPath(to))
|
||||||
WithSignature("wikimind").
|
return err
|
||||||
Apply()
|
|
||||||
log.Println("Made a test commit")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func StatusTable() (html string) {
|
func StatusTable() (html string) {
|
||||||
|
@ -7,7 +7,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
// "github.com/bouncepaw/mycorrhiza/history"
|
|
||||||
|
"github.com/bouncepaw/mycorrhiza/history"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -92,7 +93,11 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) {
|
|||||||
hyphaData.textType = TextGemini
|
hyphaData.textType = TextGemini
|
||||||
hyphaData.textPath = fullPath
|
hyphaData.textPath = fullPath
|
||||||
}
|
}
|
||||||
// TODO: make history changes
|
history.Operation(history.TypeEditText).
|
||||||
|
WithFiles(fullPath).
|
||||||
|
WithMsg(fmt.Sprintf("Edit ‘%s’", hyphaName)).
|
||||||
|
WithSignature("anon").
|
||||||
|
Apply()
|
||||||
http.Redirect(w, rq, "/page/"+hyphaName, http.StatusSeeOther)
|
http.Redirect(w, rq, "/page/"+hyphaName, http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,13 +146,20 @@ func handlerUploadBinary(w http.ResponseWriter, rq *http.Request) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if hyphaData.binaryPath != fullPath {
|
if hyphaData.binaryPath != fullPath {
|
||||||
if err := os.Remove(hyphaData.binaryPath); err != nil {
|
if err := history.Rename(hyphaData.binaryPath, fullPath); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
} else {
|
||||||
|
log.Println("Moved", hyphaData.binaryPath, "to", fullPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hyphaData.binaryPath = fullPath
|
hyphaData.binaryPath = fullPath
|
||||||
hyphaData.binaryType = mimeType
|
hyphaData.binaryType = mimeType
|
||||||
}
|
}
|
||||||
log.Println("Written", len(data), "of binary data for", hyphaName, "to path", fullPath)
|
log.Println("Written", len(data), "of binary data for", hyphaName, "to path", fullPath)
|
||||||
|
history.Operation(history.TypeEditText).
|
||||||
|
WithFiles(fullPath).
|
||||||
|
WithMsg(fmt.Sprintf("Upload binary part for ‘%s’ with type ‘%s’", hyphaName, mimeType.Mime())).
|
||||||
|
WithSignature("anon").
|
||||||
|
Apply()
|
||||||
http.Redirect(w, rq, "/page/"+hyphaName, http.StatusSeeOther)
|
http.Redirect(w, rq, "/page/"+hyphaName, http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
|
9
main.go
9
main.go
@ -121,14 +121,6 @@ func handlerStatus(w http.ResponseWriter, rq *http.Request) {
|
|||||||
w.Write([]byte(history.StatusTable()))
|
w.Write([]byte(history.StatusTable()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlerCommitTest(w http.ResponseWriter, rq *http.Request) {
|
|
||||||
log.Println(rq.URL)
|
|
||||||
w.Header().Set("Content-Type", "text/html;charset=utf-8")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
history.CommitTest()
|
|
||||||
w.Write([]byte("if you are here, a commit has been done"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Println("Running MycorrhizaWiki β")
|
log.Println("Running MycorrhizaWiki β")
|
||||||
|
|
||||||
@ -152,7 +144,6 @@ func main() {
|
|||||||
http.HandleFunc("/reindex", handlerReindex)
|
http.HandleFunc("/reindex", handlerReindex)
|
||||||
http.HandleFunc("/git/list", handlerListCommits)
|
http.HandleFunc("/git/list", handlerListCommits)
|
||||||
http.HandleFunc("/git/status", handlerStatus)
|
http.HandleFunc("/git/status", handlerStatus)
|
||||||
http.HandleFunc("/git/commit", handlerCommitTest)
|
|
||||||
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, rq *http.Request) {
|
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, rq *http.Request) {
|
||||||
http.ServeFile(w, rq, WikiDir+"/static/favicon.ico")
|
http.ServeFile(w, rq, WikiDir+"/static/favicon.ico")
|
||||||
})
|
})
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit b0157a17f535e99e485c8d3e85f66995754badcf
|
Subproject commit 30287be4496638e342878e2adf50e0a74ce71a5f
|
Loading…
x
Reference in New Issue
Block a user