Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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-workhorse
Commits
7fc85ede
Commit
7fc85ede
authored
Jan 19, 2017
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use setupGitCommand for /info/refs too
parent
18334f75
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
19 deletions
+15
-19
internal/git/git-http.go
internal/git/git-http.go
+8
-8
internal/git/info-refs.go
internal/git/info-refs.go
+4
-9
internal/git/receive-pack.go
internal/git/receive-pack.go
+2
-1
internal/git/upload-pack.go
internal/git/upload-pack.go
+1
-1
No files found.
internal/git/git-http.go
View file @
7fc85ede
...
@@ -70,7 +70,7 @@ func repoPreAuthorizeHandler(myAPI *api.API, handleFunc api.HandleFunc) http.Han
...
@@ -70,7 +70,7 @@ func repoPreAuthorizeHandler(myAPI *api.API, handleFunc api.HandleFunc) http.Han
},
""
)
},
""
)
}
}
func
setupGitCommand
(
action
string
,
a
*
api
.
Response
,
w
*
GitHttpResponseWriter
,
r
*
http
.
Request
)
(
cmd
*
exec
.
Cmd
,
stdin
io
.
WriteCloser
,
stdout
io
.
ReadCloser
,
err
error
)
{
func
setupGitCommand
(
action
string
,
a
*
api
.
Response
,
options
...
string
)
(
cmd
*
exec
.
Cmd
,
stdin
io
.
WriteCloser
,
stdout
io
.
ReadCloser
,
err
error
)
{
// Don't leak pipes when we return early after an error
// Don't leak pipes when we return early after an error
defer
func
()
{
defer
func
()
{
if
err
==
nil
{
if
err
==
nil
{
...
@@ -85,22 +85,22 @@ func setupGitCommand(action string, a *api.Response, w *GitHttpResponseWriter, r
...
@@ -85,22 +85,22 @@ func setupGitCommand(action string, a *api.Response, w *GitHttpResponseWriter, r
}()
}()
// Prepare our Git subprocess
// Prepare our Git subprocess
cmd
=
gitCommand
(
a
.
GL_ID
,
"git"
,
subCommand
(
action
),
"--stateless-rpc"
,
a
.
RepoPath
)
args
:=
[]
string
{
subCommand
(
action
),
"--stateless-rpc"
}
args
=
append
(
args
,
options
...
)
args
=
append
(
args
,
a
.
RepoPath
)
cmd
=
gitCommand
(
a
.
GL_ID
,
"git"
,
args
...
)
stdout
,
err
=
cmd
.
StdoutPipe
()
stdout
,
err
=
cmd
.
StdoutPipe
()
if
err
!=
nil
{
if
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"setupGitCommand: stdout: %v"
,
err
))
return
nil
,
nil
,
nil
,
fmt
.
Errorf
(
"stdout pipe: %v"
,
err
)
return
nil
,
nil
,
nil
,
err
}
}
stdin
,
err
=
cmd
.
StdinPipe
()
stdin
,
err
=
cmd
.
StdinPipe
()
if
err
!=
nil
{
if
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"setupGitCommand: stdin: %v"
,
err
))
return
nil
,
nil
,
nil
,
fmt
.
Errorf
(
"stdin pipe: %v"
,
err
)
return
nil
,
nil
,
nil
,
err
}
}
if
err
=
cmd
.
Start
();
err
!=
nil
{
if
err
=
cmd
.
Start
();
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"setupGitCommand: start %v: %v"
,
cmd
.
Args
,
err
))
return
nil
,
nil
,
nil
,
fmt
.
Errorf
(
"start %v: %v"
,
cmd
.
Args
,
err
)
return
nil
,
nil
,
nil
,
err
}
}
return
cmd
,
stdin
,
stdout
,
nil
return
cmd
,
stdin
,
stdout
,
nil
...
...
internal/git/info-refs.go
View file @
7fc85ede
...
@@ -45,19 +45,14 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response)
...
@@ -45,19 +45,14 @@ func handleGetInfoRefs(rw http.ResponseWriter, r *http.Request, a *api.Response)
return
return
}
}
// Prepare our Git subprocess
cmd
,
stdin
,
stdout
,
err
:=
setupGitCommand
(
rpc
,
a
,
"--advertise-refs"
)
cmd
:=
gitCommand
(
a
.
GL_ID
,
"git"
,
subCommand
(
rpc
),
"--stateless-rpc"
,
"--advertise-refs"
,
a
.
RepoPath
)
stdout
,
err
:=
cmd
.
StdoutPipe
()
if
err
!=
nil
{
if
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"handleGetInfoRefs: stdout: %v"
,
err
))
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"handleGetInfoRefs: setupGitCommand: %v"
,
err
))
return
}
defer
stdout
.
Close
()
if
err
:=
cmd
.
Start
();
err
!=
nil
{
helper
.
Fail500
(
w
,
r
,
fmt
.
Errorf
(
"handleGetInfoRefs: start %v: %v"
,
cmd
.
Args
,
err
))
return
return
}
}
defer
helper
.
CleanUpProcessGroup
(
cmd
)
// Ensure brute force subprocess clean-up
defer
helper
.
CleanUpProcessGroup
(
cmd
)
// Ensure brute force subprocess clean-up
stdin
.
Close
()
// Not needed for this request
defer
stdout
.
Close
()
// Start writing the response
// Start writing the response
w
.
Header
()
.
Set
(
"Content-Type"
,
fmt
.
Sprintf
(
"application/x-%s-advertisement"
,
rpc
))
w
.
Header
()
.
Set
(
"Content-Type"
,
fmt
.
Sprintf
(
"application/x-%s-advertisement"
,
rpc
))
...
...
internal/git/receive-pack.go
View file @
7fc85ede
...
@@ -12,9 +12,10 @@ import (
...
@@ -12,9 +12,10 @@ import (
func
handleReceivePack
(
w
*
GitHttpResponseWriter
,
r
*
http
.
Request
,
a
*
api
.
Response
)
(
writtenIn
int64
,
err
error
)
{
func
handleReceivePack
(
w
*
GitHttpResponseWriter
,
r
*
http
.
Request
,
a
*
api
.
Response
)
(
writtenIn
int64
,
err
error
)
{
body
:=
r
.
Body
body
:=
r
.
Body
action
:=
getService
(
r
)
action
:=
getService
(
r
)
cmd
,
stdin
,
stdout
,
err
:=
setupGitCommand
(
action
,
a
,
w
,
r
)
cmd
,
stdin
,
stdout
,
err
:=
setupGitCommand
(
action
,
a
)
if
err
!=
nil
{
if
err
!=
nil
{
fail500
(
w
)
return
writtenIn
,
fmt
.
Errorf
(
"setupGitCommand: %v"
,
err
)
return
writtenIn
,
fmt
.
Errorf
(
"setupGitCommand: %v"
,
err
)
}
}
...
...
internal/git/upload-pack.go
View file @
7fc85ede
...
@@ -35,7 +35,7 @@ func handleUploadPack(w *GitHttpResponseWriter, r *http.Request, a *api.Response
...
@@ -35,7 +35,7 @@ func handleUploadPack(w *GitHttpResponseWriter, r *http.Request, a *api.Response
r
.
Body
.
Close
()
r
.
Body
.
Close
()
action
:=
getService
(
r
)
action
:=
getService
(
r
)
cmd
,
stdin
,
stdout
,
err
:=
setupGitCommand
(
action
,
a
,
w
,
r
)
cmd
,
stdin
,
stdout
,
err
:=
setupGitCommand
(
action
,
a
)
if
err
!=
nil
{
if
err
!=
nil
{
fail500
(
w
)
fail500
(
w
)
...
...
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