diff options
author | Runxi Yu <me@runxiyu.org> | 2025-08-12 11:01:07 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-09-13 19:08:22 +0800 |
commit | 5717faed659a9eeb86c528ab56822c42eca1ad3f (patch) | |
tree | 92e6662628a51c03c52300d2fd98173716a82882 /forged/internal/git2c/cmd_index.go | |
parent | Remove forge-specific functions from misc (diff) | |
download | forge-5717faed659a9eeb86c528ab56822c42eca1ad3f.tar.gz forge-5717faed659a9eeb86c528ab56822c42eca1ad3f.tar.zst forge-5717faed659a9eeb86c528ab56822c42eca1ad3f.zip |
Refactor
Diffstat (limited to 'forged/internal/git2c/cmd_index.go')
-rw-r--r-- | forged/internal/git2c/cmd_index.go | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/forged/internal/git2c/cmd_index.go b/forged/internal/git2c/cmd_index.go deleted file mode 100644 index 8862b2c..0000000 --- a/forged/internal/git2c/cmd_index.go +++ /dev/null @@ -1,65 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only -// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> - -package git2c - -import ( - "encoding/hex" - "errors" - "fmt" - "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) - } - if err := c.writer.WriteUint(1); err != nil { - return nil, nil, fmt.Errorf("sending command failed: %w", err) - } - - status, err := c.reader.ReadUint() - if err != nil { - return nil, nil, fmt.Errorf("reading status failed: %w", err) - } - if status != 0 { - return nil, nil, fmt.Errorf("git2d error: %d", status) - } - - // README - readmeRaw, err := c.reader.ReadData() - if err != nil { - readmeRaw = nil - } - - readmeFilename := "README.md" // TODO - readme := &FilenameContents{Filename: readmeFilename, Content: readmeRaw} - - // Commits - var commits []Commit - for { - id, err := c.reader.ReadData() - if err != nil { - if errors.Is(err, io.EOF) { - break - } - return nil, nil, fmt.Errorf("reading commit ID failed: %w", err) - } - title, _ := c.reader.ReadData() - authorName, _ := c.reader.ReadData() - authorEmail, _ := c.reader.ReadData() - authorDate, _ := c.reader.ReadData() - - commits = append(commits, Commit{ - Hash: hex.EncodeToString(id), - Author: string(authorName), - Email: string(authorEmail), - Date: string(authorDate), - Message: string(title), - }) - } - - return commits, readme, nil -} |