(c *context.Context)
| 115 | } |
| 116 | |
| 117 | func Diff(c *context.Context) { |
| 118 | c.PageIs("Diff") |
| 119 | c.RequireHighlightJS() |
| 120 | |
| 121 | userName := c.Repo.Owner.Name |
| 122 | repoName := c.Repo.Repository.Name |
| 123 | commitID := c.Params(":sha") |
| 124 | |
| 125 | commit, err := c.Repo.GitRepo.CatFileCommit(commitID) |
| 126 | if err != nil { |
| 127 | c.NotFoundOrError(gitutil.NewError(err), "get commit by ID") |
| 128 | return |
| 129 | } |
| 130 | |
| 131 | diff, err := gitutil.RepoDiff(c.Repo.GitRepo, |
| 132 | commitID, conf.Git.MaxDiffFiles, conf.Git.MaxDiffLines, conf.Git.MaxDiffLineChars, |
| 133 | git.DiffOptions{Timeout: time.Duration(conf.Git.Timeout.Diff) * time.Second}, |
| 134 | ) |
| 135 | if err != nil { |
| 136 | c.NotFoundOrError(gitutil.NewError(err), "get diff") |
| 137 | return |
| 138 | } |
| 139 | |
| 140 | parents := make([]string, commit.ParentsCount()) |
| 141 | for i := 0; i < commit.ParentsCount(); i++ { |
| 142 | sha, err := commit.ParentID(i) |
| 143 | if err != nil { |
| 144 | c.NotFound() |
| 145 | return |
| 146 | } |
| 147 | parents[i] = sha.String() |
| 148 | } |
| 149 | |
| 150 | setEditorconfigIfExists(c) |
| 151 | if c.Written() { |
| 152 | return |
| 153 | } |
| 154 | |
| 155 | c.RawTitle(commit.Summary() + " · " + tool.ShortSHA1(commitID)) |
| 156 | c.Data["CommitID"] = commitID |
| 157 | c.Data["IsSplitStyle"] = c.Query("style") == "split" |
| 158 | c.Data["Username"] = userName |
| 159 | c.Data["Reponame"] = repoName |
| 160 | c.Data["IsImageFile"] = commit.IsImageFile |
| 161 | c.Data["IsImageFileByIndex"] = commit.IsImageFileByIndex |
| 162 | c.Data["Commit"] = commit |
| 163 | c.Data["Author"] = tryGetUserByEmail(c.Req.Context(), commit.Author.Email) |
| 164 | c.Data["Diff"] = diff |
| 165 | c.Data["Parents"] = parents |
| 166 | c.Data["DiffNotAvailable"] = diff.NumFiles() == 0 |
| 167 | c.Data["SourcePath"] = conf.Server.Subpath + "/" + path.Join(userName, repoName, "src", commitID) |
| 168 | c.Data["RawPath"] = conf.Server.Subpath + "/" + path.Join(userName, repoName, "raw", commitID) |
| 169 | if commit.ParentsCount() > 0 { |
| 170 | c.Data["BeforeSourcePath"] = conf.Server.Subpath + "/" + path.Join(userName, repoName, "src", parents[0]) |
| 171 | c.Data["BeforeRawPath"] = conf.Server.Subpath + "/" + path.Join(userName, repoName, "raw", parents[0]) |
| 172 | } |
| 173 | c.Success(DIFF) |
| 174 | } |
nothing calls this directly
no test coverage detected