aboutsummaryrefslogtreecommitdiff
path: root/forged/internal/ipc/git2c
diff options
context:
space:
mode:
Diffstat (limited to 'forged/internal/ipc/git2c')
-rw-r--r--forged/internal/ipc/git2c/client.go13
-rw-r--r--forged/internal/ipc/git2c/cmd_index.go6
-rw-r--r--forged/internal/ipc/git2c/cmd_treeraw.go9
-rw-r--r--forged/internal/ipc/git2c/perror.go3
4 files changed, 20 insertions, 11 deletions
diff --git a/forged/internal/ipc/git2c/client.go b/forged/internal/ipc/git2c/client.go
index 9f1b55c..8b11035 100644
--- a/forged/internal/ipc/git2c/client.go
+++ b/forged/internal/ipc/git2c/client.go
@@ -4,6 +4,7 @@
package git2c
import (
+ "context"
"fmt"
"net"
@@ -19,8 +20,9 @@ type Client struct {
}
// NewClient establishes a connection to a git2d socket and returns a new Client.
-func NewClient(socketPath string) (*Client, error) {
- conn, err := net.Dial("unix", socketPath)
+func NewClient(ctx context.Context, socketPath string) (*Client, error) {
+ dialer := &net.Dialer{} //exhaustruct:ignore
+ conn, err := dialer.DialContext(ctx, "unix", socketPath)
if err != nil {
return nil, fmt.Errorf("git2d connection failed: %w", err)
}
@@ -37,9 +39,12 @@ func NewClient(socketPath string) (*Client, error) {
}
// Close terminates the underlying socket connection.
-func (c *Client) Close() error {
+func (c *Client) Close() (err error) {
if c.conn != nil {
- return c.conn.Close()
+ err = c.conn.Close()
+ if err != nil {
+ return fmt.Errorf("close underlying socket: %w", err)
+ }
}
return nil
}
diff --git a/forged/internal/ipc/git2c/cmd_index.go b/forged/internal/ipc/git2c/cmd_index.go
index 8862b2c..e9fc435 100644
--- a/forged/internal/ipc/git2c/cmd_index.go
+++ b/forged/internal/ipc/git2c/cmd_index.go
@@ -13,10 +13,12 @@ import (
// CmdIndex requests a repository index from git2d and returns the list of commits
// and the contents of a README file if available.
func (c *Client) CmdIndex(repoPath string) ([]Commit, *FilenameContents, error) {
- if err := c.writer.WriteData([]byte(repoPath)); err != nil {
+ err := c.writer.WriteData([]byte(repoPath))
+ if err != nil {
return nil, nil, fmt.Errorf("sending repo path failed: %w", err)
}
- if err := c.writer.WriteUint(1); err != nil {
+ err = c.writer.WriteUint(1)
+ if err != nil {
return nil, nil, fmt.Errorf("sending command failed: %w", err)
}
diff --git a/forged/internal/ipc/git2c/cmd_treeraw.go b/forged/internal/ipc/git2c/cmd_treeraw.go
index 492cb84..89b702c 100644
--- a/forged/internal/ipc/git2c/cmd_treeraw.go
+++ b/forged/internal/ipc/git2c/cmd_treeraw.go
@@ -12,13 +12,16 @@ import (
// CmdTreeRaw queries git2d for a tree or blob object at the given path within the repository.
// It returns either a directory listing or the contents of a file.
func (c *Client) CmdTreeRaw(repoPath, pathSpec string) ([]TreeEntry, string, error) {
- if err := c.writer.WriteData([]byte(repoPath)); err != nil {
+ err := c.writer.WriteData([]byte(repoPath))
+ if err != nil {
return nil, "", fmt.Errorf("sending repo path failed: %w", err)
}
- if err := c.writer.WriteUint(2); err != nil {
+ err = c.writer.WriteUint(2)
+ if err != nil {
return nil, "", fmt.Errorf("sending command failed: %w", err)
}
- if err := c.writer.WriteData([]byte(pathSpec)); err != nil {
+ err = c.writer.WriteData([]byte(pathSpec))
+ if err != nil {
return nil, "", fmt.Errorf("sending path failed: %w", err)
}
diff --git a/forged/internal/ipc/git2c/perror.go b/forged/internal/ipc/git2c/perror.go
index 96bffd5..6bc7595 100644
--- a/forged/internal/ipc/git2c/perror.go
+++ b/forged/internal/ipc/git2c/perror.go
@@ -8,7 +8,6 @@ package git2c
import "errors"
var (
- Success error
ErrUnknown = errors.New("git2c: unknown error")
ErrPath = errors.New("git2c: get tree entry by path failed")
ErrRevparse = errors.New("git2c: revparse failed")
@@ -24,7 +23,7 @@ var (
func Perror(errno uint) error {
switch errno {
case 0:
- return Success
+ return nil
case 3:
return ErrPath
case 4: