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
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-workhorse
Commits
34b2309b
Commit
34b2309b
authored
Jan 18, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use "git show" instead of "git cat-file"
parent
86aaa133
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
34 deletions
+10
-34
internal/git/blob.go
internal/git/blob.go
+10
-34
No files found.
internal/git/blob.go
View file @
34b2309b
...
...
@@ -2,16 +2,12 @@ package git
import
(
"../helper"
"bufio"
"encoding/base64"
"fmt"
"io"
"net/http"
)
const
blobLine
=
`blob
`
func
SendGitBlob
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
repoPath
string
,
blobId
string
)
{
blobSpec
,
err
:=
base64
.
URLEncoding
.
DecodeString
(
blobId
)
if
err
!=
nil
{
...
...
@@ -19,44 +15,24 @@ func SendGitBlob(w http.ResponseWriter, r *http.Request, repoPath string, blobId
return
}
catFileCmd
:=
gitCommand
(
""
,
"git"
,
"--git-dir="
+
repoPath
,
"cat-file"
,
"--batch=%(objecttype)"
)
catFileStdin
,
err
:=
catFileCmd
.
StdinPipe
()
if
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendGitBlob: git cat-file stdin: %v"
,
err
))
return
}
catFileStdout
,
err
:=
catFileCmd
.
StdoutPipe
()
gitShowCmd
:=
gitCommand
(
""
,
"git"
,
"--git-dir="
+
repoPath
,
"show"
,
string
(
blobSpec
))
stdout
,
err
:=
gitShowCmd
.
StdoutPipe
()
if
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendGitBlob: git cat-file stdout: %v"
,
err
))
return
}
if
err
:=
catFileCmd
.
Start
();
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendGitBlob: start %v: %v"
,
catFileCmd
,
err
))
return
}
defer
cleanUpProcessGroup
(
catFileCmd
)
if
_
,
err
:=
fmt
.
Fprintf
(
catFileStdin
,
"%s
\n
"
,
blobSpec
);
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendGitBlob: send command to git cat-file: %v"
,
err
))
return
}
if
err
:=
catFileStdin
.
Close
();
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendGitBlob: close git cat-file stdin: %v"
,
err
))
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendGitBlob: git show stdout: %v"
,
err
))
return
}
out
:=
bufio
.
NewReader
(
catFileStdout
)
if
response
,
err
:=
out
.
ReadString
(
'\n'
);
err
!=
nil
||
response
!=
blobLine
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendGitBlob: git cat-file returned %q, error: %v"
,
response
,
err
))
if
err
:=
gitShowCmd
.
Start
();
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendGitBlob: start %v: %v"
,
gitShowCmd
,
err
))
return
}
defer
cleanUpProcessGroup
(
gitShowCmd
)
if
_
,
err
:=
io
.
Copy
(
w
,
catFileS
tdout
);
err
!=
nil
{
helper
.
LogError
(
fmt
.
Errorf
(
"SendGitBlob: copy git
cat-file
stdout: %v"
,
err
))
if
_
,
err
:=
io
.
Copy
(
w
,
s
tdout
);
err
!=
nil
{
helper
.
LogError
(
fmt
.
Errorf
(
"SendGitBlob: copy git
show
stdout: %v"
,
err
))
return
}
if
err
:=
catFile
Cmd
.
Wait
();
err
!=
nil
{
helper
.
LogError
(
fmt
.
Errorf
(
"SendGitBlob: wait for git
cat-file
: %v"
,
err
))
if
err
:=
gitShow
Cmd
.
Wait
();
err
!=
nil
{
helper
.
LogError
(
fmt
.
Errorf
(
"SendGitBlob: wait for git
show
: %v"
,
err
))
return
}
}
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