func Diff(ctx *middleware.Context, params martini.Params) { ctx.Data["IsRepoToolbarCommits"] = true userName := ctx.Repo.Owner.Name repoName := ctx.Repo.Repository.Name commitId := ctx.Repo.CommitId commit := ctx.Repo.Commit diff, err := models.GetDiff(models.RepoPath(userName, repoName), commitId) if err != nil { ctx.Handle(404, "repo.Diff", err) return } isImageFile := func(name string) bool { blob, err := ctx.Repo.Commit.GetBlobByPath(name) if err != nil { return false } dataRc, err := blob.Data() if err != nil { return false } buf := make([]byte, 1024) n, _ := dataRc.Read(buf) if n > 0 { buf = buf[:n] } dataRc.Close() _, isImage := base.IsImageFile(buf) return isImage } parents := make([]string, commit.ParentCount()) for i := 0; i < commit.ParentCount(); i++ { sha, err := commit.ParentId(i) parents[i] = sha.String() if err != nil { ctx.Handle(404, "repo.Diff", err) return } } ctx.Data["Username"] = userName ctx.Data["Reponame"] = repoName ctx.Data["IsImageFile"] = isImageFile ctx.Data["Title"] = commit.Summary() + " · " + base.ShortSha(commitId) ctx.Data["Commit"] = commit ctx.Data["Diff"] = diff ctx.Data["Parents"] = parents ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 ctx.Data["SourcePath"] = "/" + path.Join(userName, repoName, "src", commitId) ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", commitId) ctx.HTML(200, "repo/diff") }
func Diff(ctx *middleware.Context, params martini.Params) { userName := ctx.Repo.Owner.Name repoName := ctx.Repo.Repository.Name branchName := ctx.Repo.BranchName commitId := ctx.Repo.CommitId commit := ctx.Repo.Commit diff, err := models.GetDiff(models.RepoPath(userName, repoName), commitId) if err != nil { ctx.Handle(404, "repo.Diff", err) return } isImageFile := func(name string) bool { repoFile, err := models.GetTargetFile(userName, repoName, branchName, commitId, name) if err != nil { return false } blob, err := repoFile.LookupBlob() if err != nil { return false } data := blob.Contents() _, isImage := base.IsImageFile(data) return isImage } ctx.Data["IsImageFile"] = isImageFile ctx.Data["Title"] = commit.Message() + " · " + base.ShortSha(commitId) ctx.Data["Commit"] = commit ctx.Data["Diff"] = diff ctx.Data["IsRepoToolbarCommits"] = true ctx.Data["SourcePath"] = "/" + path.Join(userName, repoName, "src", commitId) ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", commitId) ctx.HTML(200, "repo/diff") }