aboutsummaryrefslogtreecommitdiff
path: root/git2c/client.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-04-05 20:42:00 +0800
committerRunxi Yu <me@runxiyu.org>2025-04-05 20:42:00 +0800
commit136622558a1d9b0b5ab3b4eaf43c39757afb6bad (patch)
tree894f9c12011b5856e6729627753033782f95f6a0 /git2c/client.go
parentpackPasses shall no longer be a global variable (diff)
downloadforge-136622558a1d9b0b5ab3b4eaf43c39757afb6bad.tar.gz
forge-136622558a1d9b0b5ab3b4eaf43c39757afb6bad.tar.zst
forge-136622558a1d9b0b5ab3b4eaf43c39757afb6bad.zip
git2c: git2c.go -> client.go, a more sensible name
Diffstat (limited to 'git2c/client.go')
-rw-r--r--git2c/client.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/git2c/client.go b/git2c/client.go
new file mode 100644
index 0000000..c4c3ab4
--- /dev/null
+++ b/git2c/client.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
+}