aboutsummaryrefslogtreecommitdiff
path: root/cmd/receivepack9418/conn.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-08 01:56:58 +0800
committerGravatar Runxi Yu2026-03-08 02:00:11 +0800
commit33fda1b8e4da0ad9d4208a8b8249c8d7b305f4ae (patch)
tree4028b1362b816703c9df011797f060dc8b8ad0d5 /cmd/receivepack9418/conn.go
parentreceivepack: Actually test it (diff)
signatureNo signature
cmd/receivepack9418: Init
Diffstat (limited to 'cmd/receivepack9418/conn.go')
-rw-r--r--cmd/receivepack9418/conn.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/cmd/receivepack9418/conn.go b/cmd/receivepack9418/conn.go
new file mode 100644
index 00000000..31062193
--- /dev/null
+++ b/cmd/receivepack9418/conn.go
@@ -0,0 +1,65 @@
+package main
+
+import (
+ "bufio"
+ "context"
+ "fmt"
+ "log"
+ "net"
+ "strings"
+
+ "codeberg.org/lindenii/furgit/receivepack"
+)
+
+func (srv *server) handleConn(conn net.Conn) {
+ defer func() { _ = conn.Close() }()
+
+ reader := bufio.NewReader(conn)
+ writer := bufio.NewWriter(conn)
+
+ req, err := readGitProtoRequest(reader)
+ if err != nil {
+ writeErrPkt(writer, fmt.Sprintf("invalid initial request: %v", err))
+ _ = writer.Flush()
+ log.Printf("receivepack9418: %s: invalid initial request: %v", conn.RemoteAddr(), err)
+ return
+ }
+
+ if req.Command != "git-receive-pack" {
+ writeErrPkt(writer, fmt.Sprintf("unsupported command %q", req.Command))
+ _ = writer.Flush()
+ log.Printf("receivepack9418: %s: unsupported command %q", conn.RemoteAddr(), req.Command)
+ return
+ }
+
+ gitProtocol := strings.Join(req.ExtraParameters, ":")
+
+ opts := receivepack.Options{
+ GitProtocol: gitProtocol,
+ Algorithm: srv.repo.Algorithm(),
+ Refs: srv.repo.Refs(),
+ ExistingObjects: srv.repo.Objects(),
+ ObjectsRoot: srv.objectsRoot,
+ }
+
+ err = receivepack.ReceivePack(context.Background(), writer, reader, opts)
+ if err != nil {
+ _ = writer.Flush()
+ log.Printf(
+ "receivepack9418: %s: receive-pack failed (path=%q host=%q extras=%v): %v",
+ conn.RemoteAddr(),
+ req.Pathname,
+ req.Host,
+ req.ExtraParameters,
+ err,
+ )
+
+ return
+ }
+
+ err = writer.Flush()
+ if err != nil {
+ log.Printf("receivepack9418: %s: flush failed: %v", conn.RemoteAddr(), err)
+ return
+ }
+}