aboutsummaryrefslogtreecommitdiff
path: root/git2c/git2c.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-04-05 17:21:14 +0800
committerRunxi Yu <me@runxiyu.org>2025-04-05 17:21:14 +0800
commit9b17278aece47aca17d32a37f67b7078708e78be (patch)
tree8badae3ed3e9594fae3f9de6e23468165a69e5d4 /git2c/git2c.go
parentRemove the extra .gitignore in man/ (diff)
downloadforge-9b17278aece47aca17d32a37f67b7078708e78be.tar.gz
forge-9b17278aece47aca17d32a37f67b7078708e78be.tar.zst
forge-9b17278aece47aca17d32a37f67b7078708e78be.zip
Refactor git2d comms to ./git2c
Diffstat (limited to 'git2c/git2c.go')
-rw-r--r--git2c/git2c.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/git2c/git2c.go b/git2c/git2c.go
new file mode 100644
index 0000000..c4c3ab4
--- /dev/null
+++ b/git2c/git2c.go
@@ -0,0 +1,39 @@
+package git2c
+
+import (
+ "fmt"
+ "net"
+
+ "git.sr.ht/~sircmpwn/go-bare"
+)
+
+type Client struct {
+ SocketPath string
+ conn net.Conn
+ writer *bare.Writer
+ reader *bare.Reader
+}
+
+func NewClient(socketPath string) (*Client, error) {
+ conn, err := net.Dial("unix", socketPath)
+ if err != nil {
+ return nil, fmt.Errorf("git2d connection failed: %w", err)
+ }
+
+ writer := bare.NewWriter(conn)
+ reader := bare.NewReader(conn)
+
+ return &Client{
+ SocketPath: socketPath,
+ conn: conn,
+ writer: writer,
+ reader: reader,
+ }, nil
+}
+
+func (c *Client) Close() error {
+ if c.conn != nil {
+ return c.conn.Close()
+ }
+ return nil
+}