/
commit_msg.go
34 lines (29 loc) · 1005 Bytes
/
commit_msg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package dsfs
import (
"fmt"
"github.com/qri-io/dataset"
"github.com/qri-io/qfs/cafs"
)
// SaveCommit writes a commit message to a cafs
func SaveCommit(store cafs.Filestore, s *dataset.Commit, pin bool) (path string, err error) {
file, err := JSONFile(PackageFileCommit.String(), s)
if err != nil {
log.Debug(err.Error())
return "", fmt.Errorf("error saving json commit file: %s", err.Error())
}
return store.Put(file, pin)
}
// LoadCommit loads a commit from a given path in a store
func LoadCommit(store cafs.Filestore, path string) (st *dataset.Commit, err error) {
path = PackageFilepath(store, path, PackageFileCommit)
return loadCommit(store, path)
}
// loadCommit assumes the provided path is valid
func loadCommit(store cafs.Filestore, path string) (st *dataset.Commit, err error) {
data, err := fileBytes(store.Get(path))
if err != nil {
log.Debug(err.Error())
return nil, fmt.Errorf("error loading commit file: %s", err.Error())
}
return dataset.UnmarshalCommit(data)
}