-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff.go
48 lines (39 loc) · 1.17 KB
/
diff.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package git
import (
"fmt"
"net/http"
"gitlab.com/gitlab-org/gitaly-proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/gitaly"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/senddata"
)
type diff struct{ senddata.Prefix }
type diffParams struct {
GitalyServer gitaly.Server
RawDiffRequest string
}
var SendDiff = &diff{"git-diff:"}
func (d *diff) Inject(w http.ResponseWriter, r *http.Request, sendData string) {
var params diffParams
if err := d.Unpack(¶ms, sendData); err != nil {
helper.Fail500(w, r, fmt.Errorf("SendDiff: unpack sendData: %v", err))
return
}
request := &gitalypb.RawDiffRequest{}
if err := gitaly.UnmarshalJSON(params.RawDiffRequest, request); err != nil {
helper.Fail500(w, r, fmt.Errorf("diff.RawDiff: %v", err))
return
}
diffClient, err := gitaly.NewDiffClient(params.GitalyServer)
if err != nil {
helper.Fail500(w, r, fmt.Errorf("diff.RawDiff: %v", err))
return
}
if err := diffClient.SendRawDiff(r.Context(), w, request); err != nil {
helper.LogError(
r,
©Error{fmt.Errorf("diff.RawDiff: request=%v, err=%v", request, err)},
)
return
}
}