@@ -13,9 +13,6 @@ import (
1313 "strings"
1414
1515 "code.gitea.io/gitea/modules/log"
16-
17- "github.com/djherbis/buffer"
18- "github.com/djherbis/nio/v3"
1916)
2017
2118// WriteCloserError wraps an io.WriteCloser with an additional CloseWithError function
@@ -40,100 +37,6 @@ func ensureValidGitRepository(ctx context.Context, repoPath string) error {
4037 return nil
4138}
4239
43- // catFileBatchCheck opens git cat-file --batch-check in the provided repo and returns a stdin pipe, a stdout reader and cancel function
44- func catFileBatchCheck (ctx context.Context , repoPath string ) (WriteCloserError , * bufio.Reader , func ()) {
45- batchStdinReader , batchStdinWriter := io .Pipe ()
46- batchStdoutReader , batchStdoutWriter := io .Pipe ()
47- ctx , ctxCancel := context .WithCancel (ctx )
48- closed := make (chan struct {})
49- cancel := func () {
50- ctxCancel ()
51- _ = batchStdoutReader .Close ()
52- _ = batchStdinWriter .Close ()
53- <- closed
54- }
55-
56- // Ensure cancel is called as soon as the provided context is cancelled
57- go func () {
58- <- ctx .Done ()
59- cancel ()
60- }()
61-
62- go func () {
63- stderr := strings.Builder {}
64- err := NewCommand ("cat-file" , "--batch-check" ).
65- Run (ctx , & RunOpts {
66- Dir : repoPath ,
67- Stdin : batchStdinReader ,
68- Stdout : batchStdoutWriter ,
69- Stderr : & stderr ,
70-
71- UseContextTimeout : true ,
72- })
73- if err != nil {
74- _ = batchStdoutWriter .CloseWithError (ConcatenateError (err , (& stderr ).String ()))
75- _ = batchStdinReader .CloseWithError (ConcatenateError (err , (& stderr ).String ()))
76- } else {
77- _ = batchStdoutWriter .Close ()
78- _ = batchStdinReader .Close ()
79- }
80- close (closed )
81- }()
82-
83- // For simplicities sake we'll use a buffered reader to read from the cat-file --batch-check
84- batchReader := bufio .NewReader (batchStdoutReader )
85-
86- return batchStdinWriter , batchReader , cancel
87- }
88-
89- // catFileBatch opens git cat-file --batch in the provided repo and returns a stdin pipe, a stdout reader and cancel function
90- func catFileBatch (ctx context.Context , repoPath string ) (WriteCloserError , * bufio.Reader , func ()) {
91- // We often want to feed the commits in order into cat-file --batch, followed by their trees and sub trees as necessary.
92- // so let's create a batch stdin and stdout
93- batchStdinReader , batchStdinWriter := io .Pipe ()
94- batchStdoutReader , batchStdoutWriter := nio .Pipe (buffer .New (32 * 1024 ))
95- ctx , ctxCancel := context .WithCancel (ctx )
96- closed := make (chan struct {})
97- cancel := func () {
98- ctxCancel ()
99- _ = batchStdinWriter .Close ()
100- _ = batchStdoutReader .Close ()
101- <- closed
102- }
103-
104- // Ensure cancel is called as soon as the provided context is cancelled
105- go func () {
106- <- ctx .Done ()
107- cancel ()
108- }()
109-
110- go func () {
111- stderr := strings.Builder {}
112- err := NewCommand ("cat-file" , "--batch" ).
113- Run (ctx , & RunOpts {
114- Dir : repoPath ,
115- Stdin : batchStdinReader ,
116- Stdout : batchStdoutWriter ,
117- Stderr : & stderr ,
118-
119- UseContextTimeout : true ,
120- })
121- if err != nil {
122- _ = batchStdoutWriter .CloseWithError (ConcatenateError (err , (& stderr ).String ()))
123- _ = batchStdinReader .CloseWithError (ConcatenateError (err , (& stderr ).String ()))
124- } else {
125- _ = batchStdoutWriter .Close ()
126- _ = batchStdinReader .Close ()
127- }
128- close (closed )
129- }()
130-
131- // For simplicities sake we'll us a buffered reader to read from the cat-file --batch
132- batchReader := bufio .NewReaderSize (batchStdoutReader , 32 * 1024 )
133-
134- return batchStdinWriter , batchReader , cancel
135- }
136-
13740// ReadBatchLine reads the header line from cat-file --batch
13841// We expect: <oid> SP <type> SP <size> LF
13942// then leaving the rest of the stream "<contents> LF" to be read
0 commit comments