From 57657b59ea66fd308244eea17a9d4c79eab9c2d0 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 15 Mar 2025 11:39:09 +0800 Subject: [PATCH] :art: Generate file history before converting doc to heading/moving blocks https://github.com/siyuan-note/siyuan/issues/14359 --- kernel/model/heading.go | 14 +------------- kernel/model/transaction.go | 3 +++ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/kernel/model/heading.go b/kernel/model/heading.go index 4a66a38c9..9269a1da0 100644 --- a/kernel/model/heading.go +++ b/kernel/model/heading.go @@ -26,7 +26,6 @@ import ( "github.com/88250/gulu" "github.com/88250/lute/ast" "github.com/88250/lute/parse" - "github.com/siyuan-note/filelock" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/cache" "github.com/siyuan-note/siyuan/kernel/sql" @@ -164,18 +163,7 @@ func Doc2Heading(srcID, targetID string, after bool) (srcTreeBox, srcTreePath st } // 生成文档历史 https://github.com/siyuan-note/siyuan/issues/14359 - historyDir, err := GetHistoryDir(HistoryOpUpdate) - if nil != err { - logging.LogErrorf("get history dir failed: %s", err) - return - } - historyPath := filepath.Join(historyDir, srcTree.Box, srcTree.Path) - absPath := filepath.Join(util.DataDir, srcTree.Box, srcTree.Path) - if err = filelock.Copy(absPath, historyPath); err != nil { - logging.LogErrorf("backup [path=%s] to history [%s] failed: %s", absPath, historyPath, err) - return - } - indexHistoryDir(filepath.Base(historyDir), util.NewLute()) + generateOpTypeHistory(srcTree, HistoryOpUpdate) // 移动前先删除引用 https://github.com/siyuan-note/siyuan/issues/7819 sql.DeleteRefsTreeQueue(srcTree) diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index 3396f197f..11fa2de0e 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -308,6 +308,9 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) { return &TxErr{code: TxErrCodeBlockNotFound, id: id} } + // 生成文档历史 https://github.com/siyuan-note/siyuan/issues/14359 + generateOpTypeHistory(srcTree, HistoryOpUpdate) + var headingChildren []*ast.Node if isMovingFoldHeading := ast.NodeHeading == srcNode.Type && "1" == srcNode.IALAttr("fold"); isMovingFoldHeading { headingChildren = treenode.HeadingChildren(srcNode)