mirror of
https://github.com/go-gitea/gitea
synced 2024-11-17 07:21:15 +01:00
#3345 dump content directly to HTTP ResponseWriter
This commit is contained in:
parent
dfab54d5a2
commit
10dc330640
5 changed files with 31 additions and 22 deletions
|
@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
|
||||||
|
|
||||||
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
|
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
|
||||||
|
|
||||||
##### Current tip version: 0.9.58 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
|
##### Current tip version: 0.9.59 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
|
||||||
|
|
||||||
| Web | UI | Preview |
|
| Web | UI | Preview |
|
||||||
|:-------------:|:-------:|:-------:|
|
|:-------------:|:-------:|:-------:|
|
||||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.9.58.0726"
|
const APP_VER = "0.9.59.0730"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
|
@ -185,6 +185,7 @@ func (diff *Diff) NumFiles() int {
|
||||||
|
|
||||||
const DIFF_HEAD = "diff --git "
|
const DIFF_HEAD = "diff --git "
|
||||||
|
|
||||||
|
// TODO: move this function to gogits/git-module
|
||||||
func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (*Diff, error) {
|
func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (*Diff, error) {
|
||||||
var (
|
var (
|
||||||
diff = &Diff{Files: make([]*DiffFile, 0)}
|
diff = &Diff{Files: make([]*DiffFile, 0)}
|
||||||
|
@ -371,13 +372,13 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (*
|
||||||
return diff, nil
|
return diff, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDiffRange(repoPath, beforeCommitID string, afterCommitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error) {
|
func GetDiffRange(repoPath, beforeCommitID, afterCommitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error) {
|
||||||
repo, err := git.OpenRepository(repoPath)
|
gitRepo, err := git.OpenRepository(repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
commit, err := repo.GetCommit(afterCommitID)
|
commit, err := gitRepo.GetCommit(afterCommitID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -422,27 +423,36 @@ func GetDiffRange(repoPath, beforeCommitID string, afterCommitID string, maxLine
|
||||||
return diff, nil
|
return diff, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRawDiff(repoPath, commitID, diffType string) (string, error) {
|
type RawDiffType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
RAW_DIFF_NORMAL RawDiffType = "diff"
|
||||||
|
RAW_DIFF_PATCH RawDiffType = "patch"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetRawDiff dumps diff results of repository in given commit ID to io.Writer.
|
||||||
|
// TODO: move this function to gogits/git-module
|
||||||
|
func GetRawDiff(repoPath, commitID string, diffType RawDiffType, writer io.Writer) error {
|
||||||
repo, err := git.OpenRepository(repoPath)
|
repo, err := git.OpenRepository(repoPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return fmt.Errorf("OpenRepository: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
commit, err := repo.GetCommit(commitID)
|
commit, err := repo.GetCommit(commitID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return fmt.Errorf("GetCommit: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
switch diffType {
|
switch diffType {
|
||||||
case "diff":
|
case RAW_DIFF_NORMAL:
|
||||||
if commit.ParentCount() == 0 {
|
if commit.ParentCount() == 0 {
|
||||||
cmd = exec.Command("git", "show", commitID)
|
cmd = exec.Command("git", "show", commitID)
|
||||||
} else {
|
} else {
|
||||||
c, _ := commit.Parent(0)
|
c, _ := commit.Parent(0)
|
||||||
cmd = exec.Command("git", "diff", "-M", c.ID.String(), commitID)
|
cmd = exec.Command("git", "diff", "-M", c.ID.String(), commitID)
|
||||||
}
|
}
|
||||||
case "patch":
|
case RAW_DIFF_PATCH:
|
||||||
if commit.ParentCount() == 0 {
|
if commit.ParentCount() == 0 {
|
||||||
cmd = exec.Command("git", "format-patch", "--no-signature", "--stdout", "--root", commitID)
|
cmd = exec.Command("git", "format-patch", "--no-signature", "--stdout", "--root", commitID)
|
||||||
} else {
|
} else {
|
||||||
|
@ -451,19 +461,19 @@ func GetRawDiff(repoPath, commitID, diffType string) (string, error) {
|
||||||
cmd = exec.Command("git", "format-patch", "--no-signature", "--stdout", query)
|
cmd = exec.Command("git", "format-patch", "--no-signature", "--stdout", query)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("Invalid diffType '%s'", diffType)
|
return fmt.Errorf("invalid diffType: %s", diffType)
|
||||||
}
|
}
|
||||||
|
|
||||||
stderr := new(bytes.Buffer)
|
stderr := new(bytes.Buffer)
|
||||||
|
|
||||||
cmd.Dir = repoPath
|
cmd.Dir = repoPath
|
||||||
|
cmd.Stdout = writer
|
||||||
cmd.Stderr = stderr
|
cmd.Stderr = stderr
|
||||||
|
|
||||||
stdout, err := cmd.Output()
|
if err = cmd.Run(); err != nil {
|
||||||
if err != nil {
|
return fmt.Errorf("Run: %v - %s", err, stderr)
|
||||||
return "", fmt.Errorf("%v - %s", err, stderr)
|
|
||||||
}
|
}
|
||||||
return string(stdout), nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDiffCommit(repoPath, commitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error) {
|
func GetDiffCommit(repoPath, commitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error) {
|
||||||
|
|
|
@ -195,16 +195,15 @@ func Diff(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RawDiff(ctx *context.Context) {
|
func RawDiff(ctx *context.Context) {
|
||||||
diff, err := models.GetRawDiff(
|
if err := models.GetRawDiff(
|
||||||
models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name),
|
models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name),
|
||||||
ctx.Params(":sha"),
|
ctx.Params(":sha"),
|
||||||
ctx.Params(":ext"),
|
models.RawDiffType(ctx.Params(":ext")),
|
||||||
)
|
ctx.Resp,
|
||||||
if err != nil {
|
); err != nil {
|
||||||
ctx.Handle(404, "GetRawDiff", err)
|
ctx.Handle(500, "GetRawDiff", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.HandleText(200, diff)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CompareDiff(ctx *context.Context) {
|
func CompareDiff(ctx *context.Context) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.9.58.0726
|
0.9.59.0730
|
Loading…
Reference in a new issue