diff options
Diffstat (limited to 'forged/internal/git2c')
-rw-r--r-- | forged/internal/git2c/client.go | 7 | ||||
-rw-r--r-- | forged/internal/git2c/cmd_index.go | 2 | ||||
-rw-r--r-- | forged/internal/git2c/cmd_treeraw.go | 2 | ||||
-rw-r--r-- | forged/internal/git2c/git_types.go | 3 |
4 files changed, 12 insertions, 2 deletions
diff --git a/forged/internal/git2c/client.go b/forged/internal/git2c/client.go index d178c47..82454d1 100644 --- a/forged/internal/git2c/client.go +++ b/forged/internal/git2c/client.go @@ -11,13 +11,15 @@ import ( "git.sr.ht/~sircmpwn/go-bare" ) +// Client represents a connection to the git2d backend daemon. type Client struct { - SocketPath string + socketPath string conn net.Conn writer *bare.Writer reader *bare.Reader } +// 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) if err != nil { @@ -28,13 +30,14 @@ func NewClient(socketPath string) (*Client, error) { reader := bare.NewReader(conn) return &Client{ - SocketPath: socketPath, + socketPath: socketPath, conn: conn, writer: writer, reader: reader, }, nil } +// Close terminates the underlying socket connection. func (c *Client) Close() error { if c.conn != nil { return c.conn.Close() diff --git a/forged/internal/git2c/cmd_index.go b/forged/internal/git2c/cmd_index.go index a705a63..8862b2c 100644 --- a/forged/internal/git2c/cmd_index.go +++ b/forged/internal/git2c/cmd_index.go @@ -10,6 +10,8 @@ import ( "io" ) +// 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 { return nil, nil, fmt.Errorf("sending repo path failed: %w", err) diff --git a/forged/internal/git2c/cmd_treeraw.go b/forged/internal/git2c/cmd_treeraw.go index c93480a..492cb84 100644 --- a/forged/internal/git2c/cmd_treeraw.go +++ b/forged/internal/git2c/cmd_treeraw.go @@ -9,6 +9,8 @@ import ( "io" ) +// 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 { return nil, "", fmt.Errorf("sending repo path failed: %w", err) diff --git a/forged/internal/git2c/git_types.go b/forged/internal/git2c/git_types.go index da685bf..bf13f05 100644 --- a/forged/internal/git2c/git_types.go +++ b/forged/internal/git2c/git_types.go @@ -3,6 +3,7 @@ package git2c +// Commit represents a single commit object retrieved from the git2d daemon. type Commit struct { Hash string Author string @@ -11,11 +12,13 @@ type Commit struct { Message string } +// FilenameContents holds the filename and byte contents of a file, such as a README. type FilenameContents struct { Filename string Content []byte } +// TreeEntry represents a file or directory entry within a Git tree object. type TreeEntry struct { Name string Mode string |