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
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
iv
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
Hide 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
...
@@ -2,16 +2,12 @@ package git
import
(
import
(
"../helper"
"../helper"
"bufio"
"encoding/base64"
"encoding/base64"
"fmt"
"fmt"
"io"
"io"
"net/http"
"net/http"
)
)
const
blobLine
=
`blob
`
func
SendGitBlob
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
repoPath
string
,
blobId
string
)
{
func
SendGitBlob
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
repoPath
string
,
blobId
string
)
{
blobSpec
,
err
:=
base64
.
URLEncoding
.
DecodeString
(
blobId
)
blobSpec
,
err
:=
base64
.
URLEncoding
.
DecodeString
(
blobId
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -19,44 +15,24 @@ func SendGitBlob(w http.ResponseWriter, r *http.Request, repoPath string, blobId
...
@@ -19,44 +15,24 @@ func SendGitBlob(w http.ResponseWriter, r *http.Request, repoPath string, blobId
return
return
}
}
catFileCmd
:=
gitCommand
(
""
,
"git"
,
"--git-dir="
+
repoPath
,
"cat-file"
,
"--batch=%(objecttype)"
)
gitShowCmd
:=
gitCommand
(
""
,
"git"
,
"--git-dir="
+
repoPath
,
"show"
,
string
(
blobSpec
))
catFileStdin
,
err
:=
catFileCmd
.
StdinPipe
()
stdout
,
err
:=
gitShowCmd
.
StdoutPipe
()
if
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendGitBlob: git cat-file stdin: %v"
,
err
))
return
}
catFileStdout
,
err
:=
catFileCmd
.
StdoutPipe
()
if
err
!=
nil
{
if
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendGitBlob: git cat-file stdout: %v"
,
err
))
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendGitBlob: git show 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
))
return
return
}
}
out
:=
bufio
.
NewReader
(
catFileStdout
)
if
err
:=
gitShowCmd
.
Start
();
err
!=
nil
{
if
response
,
err
:=
out
.
ReadString
(
'\n'
);
err
!=
nil
||
response
!=
blobLine
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendGitBlob: start %v: %v"
,
gitShowCmd
,
err
))
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"SendGitBlob: git cat-file returned %q, error: %v"
,
response
,
err
))
return
return
}
}
defer
cleanUpProcessGroup
(
gitShowCmd
)
if
_
,
err
:=
io
.
Copy
(
w
,
catFileS
tdout
);
err
!=
nil
{
if
_
,
err
:=
io
.
Copy
(
w
,
s
tdout
);
err
!=
nil
{
helper
.
LogError
(
fmt
.
Errorf
(
"SendGitBlob: copy git
cat-file
stdout: %v"
,
err
))
helper
.
LogError
(
fmt
.
Errorf
(
"SendGitBlob: copy git
show
stdout: %v"
,
err
))
return
return
}
}
if
err
:=
catFile
Cmd
.
Wait
();
err
!=
nil
{
if
err
:=
gitShow
Cmd
.
Wait
();
err
!=
nil
{
helper
.
LogError
(
fmt
.
Errorf
(
"SendGitBlob: wait for git
cat-file
: %v"
,
err
))
helper
.
LogError
(
fmt
.
Errorf
(
"SendGitBlob: wait for git
show
: %v"
,
err
))
return
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