refactor: 移除 services/git.go 中的无用代码

This commit is contained in:
2026-06-20 00:06:03 +08:00
parent 72c7d8e7b3
commit 46778bc227
+23 -62
View File
@@ -1,8 +1,8 @@
package services
import (
"bufio"
"fmt"
"log"
"os"
"path/filepath"
"sort"
@@ -121,19 +121,29 @@ func Clone(opts CloneOptions, progressFn func(event string, data interface{})) (
result.CommitNum++
return nil
})
} else {
log.Printf("warning: failed to count commits: %v", err)
}
branches, _ := repo.Branches()
_ = branches.ForEach(func(ref *plumbing.Reference) error {
result.Branches = append(result.Branches, ref.Name().Short())
return nil
})
branches, err := repo.Branches()
if err == nil {
_ = branches.ForEach(func(ref *plumbing.Reference) error {
result.Branches = append(result.Branches, ref.Name().Short())
return nil
})
} else {
log.Printf("warning: failed to list branches: %v", err)
}
tags, _ := repo.Tags()
_ = tags.ForEach(func(ref *plumbing.Reference) error {
result.Tags = append(result.Tags, ref.Name().Short())
return nil
})
tags, err := repo.Tags()
if err == nil {
_ = tags.ForEach(func(ref *plumbing.Reference) error {
result.Tags = append(result.Tags, ref.Name().Short())
return nil
})
} else {
log.Printf("warning: failed to list tags: %v", err)
}
result.SizeBytes = dirSize(opts.Dir)
@@ -446,34 +456,6 @@ remote, err := repo.Remote("origin")
})
}
// CloneSSEEvent formats an SSE event for the clone progress stream.
func CloneSSEEvent(event string, data interface{}) string {
return fmt.Sprintf("event: %s\ndata: %s\n\n", event, toJSON(data))
}
// toJSON is a simple JSON encoder for SSE data.
func toJSON(v interface{}) string {
switch d := v.(type) {
case map[string]interface{}:
var parts []string
for k, val := range d {
switch vv := val.(type) {
case string:
parts = append(parts, fmt.Sprintf("%q:%q", k, vv))
case int:
parts = append(parts, fmt.Sprintf("%q:%d", k, vv))
case int64:
parts = append(parts, fmt.Sprintf("%q:%d", k, vv))
default:
parts = append(parts, fmt.Sprintf("%q:%q", k, fmt.Sprintf("%v", vv)))
}
}
return "{" + strings.Join(parts, ",") + "}"
default:
return fmt.Sprintf("%q", fmt.Sprintf("%v", v))
}
}
// dirSize returns the total size of files in a directory.
func dirSize(path string) int64 {
var size int64
@@ -489,29 +471,6 @@ func dirSize(path string) int64 {
return size
}
// EstimateSize estimates repo size without cloning (for display).
func EstimateSize(url string) int64 {
// We can't know without cloning, return 0
return 0
}
// GetCloneProgressReader wraps a git clone with progress reporting.
type CloneProgressReader struct {
scanner *bufio.Scanner
progressFn func(event string, data interface{})
}
func NewCloneProgressReader(progressFn func(event string, data interface{})) *CloneProgressReader {
return &CloneProgressReader{
progressFn: progressFn,
}
}
func (r *CloneProgressReader) Read(p []byte) (n int, err error) {
// This is a simplified version - real implementation would parse git protocol
return 0, nil
}
// CompareCommits returns the diff between two commits.
func CompareCommits(repoPath, base, head string) (string, error) {
repo, err := OpenRepo(repoPath)
@@ -575,6 +534,8 @@ func CloneWithProgress(opts CloneOptions, progressFn func(event string, data int
return Clone(opts, progressFn)
}
// GetDefaultBranch returns the default branch name (main or master).
// GetDefaultBranch returns the default branch name (main or master).
func GetDefaultBranch(repoPath string) (string, error) {
repo, err := OpenRepo(repoPath)