1 Star 0 Fork 34

robin329/git-repo-clean

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
fastexport.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
Li Linchao 提交于 2022-07-11 18:48 . refact
package main
import (
"bufio"
"io"
"os"
"os/exec"
)
// fast-export output stream iterater
type FEOutPutIter struct {
cmd *exec.Cmd
out io.ReadCloser
f *bufio.Reader
errChan <-chan error
}
func (repo *Repository) NewFastExportIter() (*FEOutPutIter, error) {
args := []string{
"-c",
"core.quotepath=false",
"fast-export",
"--show-original-ids",
"--signed-tags=strip",
"--fake-missing-tagger",
"--tag-of-filtered-object=rewrite",
"--use-done-feature",
"--mark-tags", // git >= 2.24.0
"--reencode=yes", // git >= 2.23.0
repo.context.opts.branch,
"--no-data",
}
// drop "--no-data"
if repo.context.opts.lfs {
args = args[:len(args)-1]
}
cmd := repo.GitCommand(args...)
out, err := cmd.StdoutPipe()
if err != nil {
out.Close()
return nil, err
}
cmd.Stderr = os.Stderr
err = cmd.Start()
if err != nil {
return nil, err
}
return &FEOutPutIter{
cmd: cmd,
out: out,
f: bufio.NewReader(out),
errChan: make(chan error, 1),
}, nil
}
// get data line by line from output stream
func (iter *FEOutPutIter) Next() (string, error) {
errChan := make(chan error, 1)
line, err := iter.f.ReadString('\n')
if err != nil {
if err != io.EOF {
errChan <- err
return "", err
}
return "", nil
}
return line, nil
}
func (iter *FEOutPutIter) Close() error {
err := iter.out.Close()
err2 := iter.cmd.Wait()
if err == nil {
err = err2
}
return err
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/robin329/git-repo-clean.git
git@gitee.com:robin329/git-repo-clean.git
robin329
git-repo-clean
git-repo-clean
main

搜索帮助