Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8dd2d3eb
Commit
8dd2d3eb
authored
Jan 19, 2017
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No need for two different buffers
parent
7fc85ede
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
20 deletions
+12
-20
internal/git/upload-pack.go
internal/git/upload-pack.go
+8
-18
internal/helper/tempfile.go
internal/helper/tempfile.go
+4
-2
No files found.
internal/git/upload-pack.go
View file @
8dd2d3eb
package
git
import
(
"bytes"
"fmt"
"io"
"net/http"
...
...
@@ -11,28 +10,19 @@ import (
)
func
handleUploadPack
(
w
*
GitHttpResponseWriter
,
r
*
http
.
Request
,
a
*
api
.
Response
)
(
writtenIn
int64
,
err
error
)
{
buffer
:=
&
bytes
.
Buffer
{}
// Only sniff on the first 4096 bytes: we assume that if we find no
// 'deepen' message in the first 4096 bytes there won't be one later
// either.
_
,
err
=
io
.
Copy
(
buffer
,
io
.
LimitReader
(
r
.
Body
,
4096
))
buffer
,
err
:=
helper
.
ReadAllTempfile
(
r
.
Body
)
if
err
!=
nil
{
fail500
(
w
)
return
writtenIn
,
&
copyError
{
fmt
.
Errorf
(
"buffer git-upload-pack body: %v"
,
err
)}
return
writtenIn
,
fmt
.
Errorf
(
"ReadAllTempfile: %v"
,
err
)
}
isShallowClone
:=
scanDeepen
(
bytes
.
NewReader
(
buffer
.
Bytes
()))
defer
buffer
.
Close
()
r
.
Body
.
Close
()
// We must drain the request body before writing the response, to avoid
// upsetting NGINX.
remainder
,
err
:=
helper
.
ReadAllTempfile
(
r
.
Body
)
if
err
!=
nil
{
isShallowClone
:=
scanDeepen
(
buffer
)
if
_
,
err
:=
buffer
.
Seek
(
0
,
0
);
err
!=
nil
{
fail500
(
w
)
return
writtenIn
,
fmt
.
Errorf
(
"
ReadAllT
empfile: %v"
,
err
)
return
writtenIn
,
fmt
.
Errorf
(
"
seek t
empfile: %v"
,
err
)
}
defer
remainder
.
Close
()
body
:=
io
.
MultiReader
(
buffer
,
remainder
)
r
.
Body
.
Close
()
action
:=
getService
(
r
)
cmd
,
stdin
,
stdout
,
err
:=
setupGitCommand
(
action
,
a
)
...
...
@@ -57,7 +47,7 @@ func handleUploadPack(w *GitHttpResponseWriter, r *http.Request, a *api.Response
}()
// Write the client request body to Git's standard input
if
writtenIn
,
err
=
io
.
Copy
(
stdin
,
b
ody
);
err
!=
nil
{
if
writtenIn
,
err
=
io
.
Copy
(
stdin
,
b
uffer
);
err
!=
nil
{
fail500
(
w
)
return
writtenIn
,
fmt
.
Errorf
(
"write to %v: %v"
,
cmd
.
Args
,
err
)
}
...
...
internal/helper/tempfile.go
View file @
8dd2d3eb
...
...
@@ -6,12 +6,14 @@ import (
"os"
)
func
ReadAllTempfile
(
r
io
.
Reader
)
(
_
io
.
ReadCloser
,
err
error
)
{
tempfile
,
err
:
=
ioutil
.
TempFile
(
""
,
"gitlab-workhorse-read-all-tempfile"
)
func
ReadAllTempfile
(
r
io
.
Reader
)
(
tempfile
*
os
.
File
,
err
error
)
{
tempfile
,
err
=
ioutil
.
TempFile
(
""
,
"gitlab-workhorse-read-all-tempfile"
)
if
err
!=
nil
{
return
nil
,
err
}
defer
func
()
{
// Avoid leaking an open file if the function returns with an error
if
err
!=
nil
{
tempfile
.
Close
()
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment