MCPcopy
hub / github.com/sinclairtarget/git-who / Add

Method Add

internal/cache/backends/json.go:97–123  ·  view source on GitHub ↗
(commits []git.Commit)

Source from the content-addressed store, hash-verified

95}
96
97func (b JSONBackend) Add(commits []git.Commit) (err error) {
98 f, err := os.OpenFile(
99 b.Path,
100 os.O_WRONLY|os.O_APPEND|os.O_CREATE,
101 0644,
102 )
103 if err != nil {
104 return err
105 }
106 defer func() {
107 closeErr := f.Close()
108 if err == nil {
109 err = closeErr
110 }
111 }()
112
113 enc := json.NewEncoder(f)
114
115 for _, c := range commits {
116 err = enc.Encode(&c)
117 if err != nil {
118 return err
119 }
120 }
121
122 return nil
123}
124
125func (b JSONBackend) Clear() error {
126 return os.Remove(b.Path)

Callers 2

TestAddGetClearFunction · 0.95
TestAddGetAddGetFunction · 0.95

Calls 1

CloseMethod · 0.65

Tested by 2

TestAddGetClearFunction · 0.76
TestAddGetAddGetFunction · 0.76