func Diff(ctx *context.Context) { ctx.Data["PageIsDiff"] = true ctx.Data["RequireHighlightJS"] = true userName := ctx.Repo.Owner.Name repoName := ctx.Repo.Repository.Name commitID := ctx.Params(":sha") commit, err := ctx.Repo.GitRepo.GetCommit(commitID) if err != nil { if git.IsErrNotExist(err) { ctx.Handle(404, "Repo.GitRepo.GetCommit", err) } else { ctx.Handle(500, "Repo.GitRepo.GetCommit", err) } return } diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName), commitID, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles) if err != nil { ctx.Handle(404, "GetDiffCommit", err) return } 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["CommitID"] = commitID ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split" ctx.Data["Username"] = userName ctx.Data["Reponame"] = repoName ctx.Data["IsImageFile"] = commit.IsImageFile ctx.Data["Title"] = commit.Summary() + " · " + base.ShortSha(commitID) ctx.Data["Commit"] = commit ctx.Data["Author"] = models.ValidateCommitWithEmail(commit) ctx.Data["Diff"] = diff ctx.Data["Parents"] = parents ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", commitID) if commit.ParentCount() > 0 { ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", parents[0]) } ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", commitID) ctx.HTML(200, DIFF) }
func Diff(ctx *middleware.Context) { ctx.Data["IsRepoToolbarCommits"] = true userName := ctx.Repo.Owner.Name repoName := ctx.Repo.Repository.Name commitId := ctx.Repo.CommitId commit := ctx.Repo.Commit commit.CommitMessage = commit.CommitMessage diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName), commitId, setting.Git.MaxGitDiffLines) if err != nil { ctx.Handle(404, "GetDiffCommit", 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] } _, 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["Author"] = models.ValidateCommitWithEmail(commit) ctx.Data["Diff"] = diff ctx.Data["Parents"] = parents ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0 ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", commitId) if commit.ParentCount() > 0 { ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "src", parents[0]) } ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(userName, repoName, "raw", commitId) ctx.HTML(200, DIFF) }