tangled
alpha
login
or
join now
back
round
0
view raw
knotserver/git: change signatures to accept string patches
#641
merged
opened by
oppi.li
3 months ago
targeting
master
from
push-rvtqynpmozzy
as opposed to []byte.
Signed-off-by: oppiliappan
me@oppi.li
options
unified
split
Changed files
+6
-6
knotserver
git
merge.go
+6
-6
knotserver/git/merge.go
···
32
32
mergeCheckCache = MergeCheckCache{cache}
33
33
}
34
34
35
35
-
func (m *MergeCheckCache) cacheKey(g *GitRepo, patch []byte, targetBranch string) string {
35
35
+
func (m *MergeCheckCache) cacheKey(g *GitRepo, patch string, targetBranch string) string {
36
36
sep := byte(':')
37
37
hash := sha256.Sum256(fmt.Append([]byte{}, g.path, sep, g.h.String(), sep, patch, sep, targetBranch))
38
38
return fmt.Sprintf("%x", hash)
···
49
49
}
50
50
}
51
51
52
52
-
func (m *MergeCheckCache) Set(g *GitRepo, patch []byte, targetBranch string, mergeCheck error) {
52
52
+
func (m *MergeCheckCache) Set(g *GitRepo, patch string, targetBranch string, mergeCheck error) {
53
53
key := m.cacheKey(g, patch, targetBranch)
54
54
val := m.cacheVal(mergeCheck)
55
55
m.cache.Set(key, val, 0)
56
56
}
57
57
58
58
-
func (m *MergeCheckCache) Get(g *GitRepo, patch []byte, targetBranch string) (error, bool) {
58
58
+
func (m *MergeCheckCache) Get(g *GitRepo, patch string, targetBranch string) (error, bool) {
59
59
key := m.cacheKey(g, patch, targetBranch)
60
60
if val, ok := m.cache.Get(key); ok {
61
61
if val == struct{}{} {
···
104
104
return fmt.Sprintf("merge failed: %s", e.Message)
105
105
}
106
106
107
107
-
func (g *GitRepo) createTempFileWithPatch(patchData []byte) (string, error) {
107
107
+
func (g *GitRepo) createTempFileWithPatch(patchData string) (string, error) {
108
108
tmpFile, err := os.CreateTemp("", "git-patch-*.patch")
109
109
if err != nil {
110
110
return "", fmt.Errorf("failed to create temporary patch file: %w", err)
111
111
}
112
112
113
113
-
if _, err := tmpFile.Write(patchData); err != nil {
113
113
+
if _, err := tmpFile.Write([]byte(patchData)); err != nil {
114
114
tmpFile.Close()
115
115
os.Remove(tmpFile.Name())
116
116
return "", fmt.Errorf("failed to write patch data to temporary file: %w", err)
···
244
244
return result
245
245
}
246
246
247
247
-
func (g *GitRepo) MergeWithOptions(patchData []byte, targetBranch string, opts MergeOptions) error {
247
247
+
func (g *GitRepo) MergeWithOptions(patchData string, targetBranch string, opts MergeOptions) error {
248
248
patchFile, err := g.createTempFileWithPatch(patchData)
249
249
if err != nil {
250
250
return &ErrMerge{