From 40c6e64e4badfd543dc98237e1aeb3d8958cfe90 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Tue, 25 Sep 2018 17:56:58 +0200 Subject: cache: add raw edit functions to allow setting up the author, the timestamp and the metadatas --- cache/repo_cache.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'cache/repo_cache.go') diff --git a/cache/repo_cache.go b/cache/repo_cache.go index 4ca19150..2278b604 100644 --- a/cache/repo_cache.go +++ b/cache/repo_cache.go @@ -11,6 +11,7 @@ import ( "sort" "strconv" "strings" + "time" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/operations" @@ -354,11 +355,22 @@ func (c *RepoCache) NewBugWithFiles(title string, message string, files []git.Ha return nil, err } - b, err := operations.CreateWithFiles(author, title, message, files) + return c.NewBugRaw(author, time.Now().Unix(), title, message, files, nil) +} + +// NewBugWithFilesMeta create a new bug with attached files for the message, as +// well as metadata for the Create operation. +// The new bug is written in the repository (commit) +func (c *RepoCache) NewBugRaw(author bug.Person, unixTime int64, title string, message string, files []git.Hash, metadata map[string]string) (*BugCache, error) { + b, err := operations.CreateWithFiles(author, unixTime, title, message, files) if err != nil { return nil, err } + for key, value := range metadata { + b.FirstOp().SetMetadata(key, value) + } + err = b.Commit(c.repo) if err != nil { return nil, err -- cgit