refactor: 移除 services/git.go 中的无用代码
This commit is contained in:
+15
-54
@@ -1,8 +1,8 @@
|
|||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -121,19 +121,29 @@ func Clone(opts CloneOptions, progressFn func(event string, data interface{})) (
|
|||||||
result.CommitNum++
|
result.CommitNum++
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
log.Printf("warning: failed to count commits: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
branches, _ := repo.Branches()
|
branches, err := repo.Branches()
|
||||||
|
if err == nil {
|
||||||
_ = branches.ForEach(func(ref *plumbing.Reference) error {
|
_ = branches.ForEach(func(ref *plumbing.Reference) error {
|
||||||
result.Branches = append(result.Branches, ref.Name().Short())
|
result.Branches = append(result.Branches, ref.Name().Short())
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
log.Printf("warning: failed to list branches: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
tags, _ := repo.Tags()
|
tags, err := repo.Tags()
|
||||||
|
if err == nil {
|
||||||
_ = tags.ForEach(func(ref *plumbing.Reference) error {
|
_ = tags.ForEach(func(ref *plumbing.Reference) error {
|
||||||
result.Tags = append(result.Tags, ref.Name().Short())
|
result.Tags = append(result.Tags, ref.Name().Short())
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
log.Printf("warning: failed to list tags: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
result.SizeBytes = dirSize(opts.Dir)
|
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.
|
// dirSize returns the total size of files in a directory.
|
||||||
func dirSize(path string) int64 {
|
func dirSize(path string) int64 {
|
||||||
var size int64
|
var size int64
|
||||||
@@ -489,29 +471,6 @@ func dirSize(path string) int64 {
|
|||||||
return size
|
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.
|
// CompareCommits returns the diff between two commits.
|
||||||
func CompareCommits(repoPath, base, head string) (string, error) {
|
func CompareCommits(repoPath, base, head string) (string, error) {
|
||||||
repo, err := OpenRepo(repoPath)
|
repo, err := OpenRepo(repoPath)
|
||||||
@@ -575,6 +534,8 @@ func CloneWithProgress(opts CloneOptions, progressFn func(event string, data int
|
|||||||
return Clone(opts, progressFn)
|
return Clone(opts, progressFn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDefaultBranch returns the default branch name (main or master).
|
||||||
|
|
||||||
// GetDefaultBranch returns the default branch name (main or master).
|
// GetDefaultBranch returns the default branch name (main or master).
|
||||||
func GetDefaultBranch(repoPath string) (string, error) {
|
func GetDefaultBranch(repoPath string) (string, error) {
|
||||||
repo, err := OpenRepo(repoPath)
|
repo, err := OpenRepo(repoPath)
|
||||||
|
|||||||
Reference in New Issue
Block a user