0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-01-20 20:05:19 +01:00

add support for archive-upload rpc

This commit is contained in:
TheFox0x7 2026-01-16 17:42:17 +01:00
parent 65422fde4d
commit 54d47fd751
No known key found for this signature in database
2 changed files with 20 additions and 4 deletions

View File

@ -22,5 +22,6 @@ func addOwnerRepoGitHTTPRouters(m *web.Router) {
m.Methods("GET,OPTIONS", "/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38,62}}", repo.GetLooseObject)
m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.pack", repo.GetPackFile)
m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.idx", repo.GetIdxFile)
m.Post("/git-upload-archive", repo.ServiceUploadArchive)
}, repo.HTTPGitEnabledHandler, repo.CorsHandler(), optSignInFromAnyOrigin, context.UserAssignmentWeb())
}

View File

@ -387,6 +387,9 @@ func prepareGitCmdWithAllowedService(service string) (*gitcmd.Command, error) {
if service == ServiceTypeUploadPack {
return gitcmd.NewCommand(ServiceTypeUploadPack), nil
}
if service == ServiceTypeUploadArchive {
return gitcmd.NewCommand(ServiceTypeUploadArchive), nil
}
return nil, fmt.Errorf("service %q is not allowed", service)
}
@ -435,7 +438,10 @@ func serviceRPC(ctx *context.Context, h *serviceHandler, service string) {
}
var stderr bytes.Buffer
if err := gitrepo.RunCmd(ctx, h.getStorageRepo(), cmd.AddArguments("--stateless-rpc", ".").
if service != ServiceTypeUploadArchive {
cmd.AddArguments("--stateless-rpc")
}
if err := gitrepo.RunCmd(ctx, h.getStorageRepo(), cmd.AddArguments(".").
WithEnv(append(os.Environ(), h.environ...)).
WithStderr(&stderr).
WithStdin(reqBody).
@ -444,13 +450,13 @@ func serviceRPC(ctx *context.Context, h *serviceHandler, service string) {
if !git.IsErrCanceledOrKilled(err) {
log.Error("Fail to serve RPC(%s) in %s: %v - %s", service, h.getStorageRepo().RelativePath(), err, stderr.String())
}
return
}
}
const (
ServiceTypeUploadPack = "upload-pack"
ServiceTypeReceivePack = "receive-pack"
ServiceTypeUploadPack = "upload-pack"
ServiceTypeReceivePack = "receive-pack"
ServiceTypeUploadArchive = "upload-archive"
)
// ServiceUploadPack implements Git Smart HTTP protocol
@ -461,6 +467,13 @@ func ServiceUploadPack(ctx *context.Context) {
}
}
func ServiceUploadArchive(ctx *context.Context) {
h := httpBase(ctx)
if h != nil {
serviceRPC(ctx, h, ServiceTypeUploadArchive)
}
}
// ServiceReceivePack implements Git Smart HTTP protocol
func ServiceReceivePack(ctx *context.Context) {
h := httpBase(ctx)
@ -475,6 +488,8 @@ func getServiceType(ctx *context.Context) string {
return ServiceTypeUploadPack
case "git-" + ServiceTypeReceivePack:
return ServiceTypeReceivePack
case "git-" + ServiceTypeUploadArchive:
return ServiceTypeUploadArchive
}
return ""
}