diff --git a/cmd/web.go b/cmd/web.go index db43d9a2f..0af79c3c3 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -108,11 +108,6 @@ func runWeb(*cli.Context) { // Repositories. r.Get("/orgs/:org/repos/search", v1.SearchOrgRepositoreis) - m.Group("/:username/:reponame", func(r martini.Router) { - r.Get("/commit/:branchname", repo.DiffAjax) - r.Get("/commit/:branchname/**", repo.DiffAjax) - }) - r.Any("**", func(ctx *middleware.Context) { ctx.JSON(404, &base.ApiJsonErr{"Not Found", v1.DOC_URL}) }) diff --git a/models/git_diff.go b/models/git_diff.go index 06b79111d..bdaf7a606 100644 --- a/models/git_diff.go +++ b/models/git_diff.go @@ -209,7 +209,7 @@ func GetDiff(repoPath, commitid string) (*Diff, error) { return ParsePatch(process.Add(fmt.Sprintf("GetDiff(%s)", repoPath), cmd), cmd, rd) } -func ParsePatchCallback(pid int64, cmd *exec.Cmd, reader io.Reader, callback DiffCallback) error { +func ParsePatchChan(pid int64, cmd *exec.Cmd, reader io.Reader, file chan *DiffFile) error { scanner := bufio.NewScanner(reader) var ( curFile *DiffFile @@ -277,7 +277,8 @@ func ParsePatchCallback(pid int64, cmd *exec.Cmd, reader io.Reader, callback Dif a := fs[0] if curFile != nil { - callback(curFile) + fmt.Println("curFile:", curFile) + file <- curFile } curFile = &DiffFile{ @@ -306,7 +307,8 @@ func ParsePatchCallback(pid int64, cmd *exec.Cmd, reader io.Reader, callback Dif } if curFile != nil { - callback(curFile) + fmt.Println("last curFile:", curFile) + file <- curFile } // In case process became zombie. @@ -316,9 +318,7 @@ func ParsePatchCallback(pid int64, cmd *exec.Cmd, reader io.Reader, callback Dif return nil } -type DiffCallback func(*DiffFile) error - -func GetDiffCallback(repoPath, commitid string, callback DiffCallback) error { +func GetDiffChan(repoPath, commitid string, file chan *DiffFile) error { repo, err := git.OpenRepository(repoPath) if err != nil { return err @@ -347,6 +347,6 @@ func GetDiffCallback(repoPath, commitid string, callback DiffCallback) error { wr.Close() }() defer rd.Close() - return ParsePatchCallback(process.Add(fmt.Sprintf("GetDiff(%s)", repoPath), cmd), - cmd, rd, callback) + return ParsePatchChan(process.Add(fmt.Sprintf("GetDiff(%s)", repoPath), cmd), + cmd, rd, file) } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index d70489341..723e49304 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -5,7 +5,6 @@ package repo import ( - "encoding/json" "path" "github.com/go-martini/martini" @@ -106,26 +105,6 @@ func SearchCommits(ctx *middleware.Context, params martini.Params) { ctx.HTML(200, COMMITS) } -func DiffAjax(ctx *middleware.Context, params martini.Params) { - userName := params["username"] - repoName := params["reponame"] - commitId := params["branchname"] - - err := models.GetDiffCallback(models.RepoPath(userName, repoName), commitId, func(f *models.DiffFile) error { - bs, err := json.Marshal(f) - if err != nil { - return err - } - _, err = ctx.Res.Write(bs) - return err - }) - - if err != nil { - ctx.Handle(404, "repo.DiffAjax", err) - return - } -} - func Diff(ctx *middleware.Context, params martini.Params) { ctx.Data["IsRepoToolbarCommits"] = true @@ -135,11 +114,15 @@ func Diff(ctx *middleware.Context, params martini.Params) { commit := ctx.Repo.Commit - /*diff, err := models.GetDiff(models.RepoPath(userName, repoName), commitId) - if err != nil { - ctx.Handle(404, "repo.Diff(GetDiff)", err) - return - }*/ + var fileChan = make(chan *models.DiffFile) + go func() { + err := models.GetDiffChan(models.RepoPath(userName, repoName), commitId, fileChan) + if err != nil { + ctx.Handle(404, "repo.Diff(GetDiff)", err) + return + } + close(fileChan) + }() isImageFile := func(name string) bool { blob, err := ctx.Repo.Commit.GetBlobByPath(name) @@ -178,9 +161,10 @@ func Diff(ctx *middleware.Context, params martini.Params) { ctx.Data["Commit"] = commit //ctx.Data["Diff"] = diff ctx.Data["Parents"] = parents - //ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 + ctx.Data["DiffNotAvailable"] = false ctx.Data["SourcePath"] = "/" + path.Join(userName, repoName, "src", commitId) ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", commitId) + ctx.Data["Diffs"] = fileChan ctx.HTML(200, DIFF) } diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index a31488a83..2acde5bf9 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -32,32 +32,11 @@ Show Diff Stats
- {{.Diff.NumFiles}} changed files with {{.Diff.TotalAddition}} additions and {{.Diff.TotalDeletion}} deletions. + changed files with additions and deletions.
-