Skip to content

Commit e31f62f

Browse files
modules/lfstransfer: add a backend and runner
Also add handler in runServ() Doesn't add support for the locking API yet
1 parent 6444a7c commit e31f62f

File tree

8 files changed

+522
-1
lines changed

8 files changed

+522
-1
lines changed

assets/go-licenses.json

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/serv.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"code.gitea.io/gitea/modules/container"
2424
"code.gitea.io/gitea/modules/git"
2525
"code.gitea.io/gitea/modules/json"
26+
"code.gitea.io/gitea/modules/lfstransfer"
2627
"code.gitea.io/gitea/modules/log"
2728
"code.gitea.io/gitea/modules/pprof"
2829
"code.gitea.io/gitea/modules/private"
@@ -41,6 +42,7 @@ const (
4142
verbUploadArchive = "git-upload-archive"
4243
verbReceivePack = "git-receive-pack"
4344
verbLfsAuthenticate = "git-lfs-authenticate"
45+
verbLfsTransfer = "git-lfs-transfer"
4446
)
4547

4648
// CmdServ represents the available serv sub-command.
@@ -83,9 +85,11 @@ var (
8385
verbUploadArchive,
8486
verbReceivePack,
8587
verbLfsAuthenticate,
88+
verbLfsTransfer,
8689
)
8790
allowedCommandsLfs = container.SetOf(
8891
verbLfsAuthenticate,
92+
verbLfsTransfer,
8993
)
9094
alphaDashDotPattern = regexp.MustCompile(`[^\w-\.]`)
9195
)
@@ -138,7 +142,7 @@ func getAccessMode(verb, lfsVerb string) perm.AccessMode {
138142
return perm.AccessModeRead
139143
case verbReceivePack:
140144
return perm.AccessModeWrite
141-
case verbLfsAuthenticate:
145+
case verbLfsAuthenticate, verbLfsTransfer:
142146
switch lfsVerb {
143147
case "upload":
144148
return perm.AccessModeWrite
@@ -298,6 +302,15 @@ func runServ(c *cli.Context) error {
298302
return fail(ctx, extra.UserMsg, "ServCommand failed: %s", extra.Error)
299303
}
300304

305+
// LFS SSH protocol
306+
if verb == verbLfsTransfer {
307+
token, err := getLFSAuthToken(ctx, lfsVerb, results)
308+
if err != nil {
309+
return err
310+
}
311+
return lfstransfer.Main(ctx, repoPath, lfsVerb, token)
312+
}
313+
301314
// LFS token authentication
302315
if verb == verbLfsAuthenticate {
303316
url := fmt.Sprintf("%s%s/%s.git/info/lfs", setting.AppURL, url.PathEscape(results.OwnerName), url.PathEscape(results.RepoName))

go.mod

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ require (
3030
github.com/blevesearch/bleve/v2 v2.4.2
3131
github.com/buildkite/terminal-to-html/v3 v3.12.1
3232
github.com/caddyserver/certmagic v0.21.3
33+
github.com/charmbracelet/git-lfs-transfer v0.2.0
3334
github.com/chi-middleware/proxy v1.1.1
3435
github.com/dimiro1/reply v0.0.0-20200315094148-d0136a4c9e21
3536
github.com/djherbis/buffer v1.2.0
@@ -192,6 +193,7 @@ require (
192193
github.com/fatih/color v1.17.0 // indirect
193194
github.com/felixge/httpsnoop v1.0.4 // indirect
194195
github.com/fxamacker/cbor/v2 v2.6.0 // indirect
196+
github.com/git-lfs/pktline v0.0.0-20230103162542-ca444d533ef1 // indirect
195197
github.com/go-ap/errors v0.0.0-20240304112515-6077fa9c17b0 // indirect
196198
github.com/go-asn1-ber/asn1-ber v1.5.7 // indirect
197199
github.com/go-enry/go-oniguruma v1.2.1 // indirect
@@ -324,6 +326,8 @@ replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142
324326

325327
replace github.com/nektos/act => gitea.com/gitea/act v0.259.1
326328

329+
replace github.com/charmbracelet/git-lfs-transfer => gitea.com/gitea/git-lfs-transfer v0.2.0
330+
327331
// TODO: This could be removed after https://github.com/mholt/archiver/pull/396 merged
328332
replace github.com/mholt/archiver/v3 => github.com/anchore/archiver/v3 v3.5.2
329333

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:cliQ4H
1818
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs=
1919
gitea.com/gitea/act v0.259.1 h1:8GG1o/xtUHl3qjn5f0h/2FXrT5ubBn05TJOM5ry+FBw=
2020
gitea.com/gitea/act v0.259.1/go.mod h1:UxZWRYqQG2Yj4+4OqfGWW5a3HELwejyWFQyU7F1jUD8=
21+
gitea.com/gitea/git-lfs-transfer v0.2.0 h1:baHaNoBSRaeq/xKayEXwiDQtlIjps4Ac/Ll4KqLMB40=
22+
gitea.com/gitea/git-lfs-transfer v0.2.0/go.mod h1:UrXUCm3xLQkq15fu7qlXHUMlrhdlXHoi13KH2Dfiits=
2123
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed h1:EZZBtilMLSZNWtHHcgq2mt6NSGhJSZBuduAlinMEmso=
2224
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed/go.mod h1:E3i3cgB04dDx0v3CytCgRTTn9Z/9x891aet3r456RVw=
2325
gitea.com/go-chi/cache v0.2.1 h1:bfAPkvXlbcZxPCpcmDVCWoHgiBSBmZN/QosnZvEC0+g=
@@ -291,6 +293,8 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
291293
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
292294
github.com/fxamacker/cbor/v2 v2.6.0 h1:sU6J2usfADwWlYDAFhZBQ6TnLFBHxgesMrQfQgk1tWA=
293295
github.com/fxamacker/cbor/v2 v2.6.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
296+
github.com/git-lfs/pktline v0.0.0-20230103162542-ca444d533ef1 h1:mtDjlmloH7ytdblogrMz1/8Hqua1y8B4ID+bh3rvod0=
297+
github.com/git-lfs/pktline v0.0.0-20230103162542-ca444d533ef1/go.mod h1:fenKRzpXDjNpsIBhuhUzvjCKlDjKam0boRAenTE0Q6A=
294298
github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
295299
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
296300
github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=

0 commit comments

Comments
 (0)