MCPcopy Index your code
hub / github.com/gogs/gogs / CompareDiff

Function CompareDiff

internal/route/repo/commit.go:214–261  ·  view source on GitHub ↗
(c *context.Context)

Source from the content-addressed store, hash-verified

212}
213
214func CompareDiff(c *context.Context) {
215 c.Data["IsDiffCompare"] = true
216 userName := c.Repo.Owner.Name
217 repoName := c.Repo.Repository.Name
218 beforeCommitID := c.Params(":before")
219 afterCommitID := c.Params(":after")
220
221 commit, err := c.Repo.GitRepo.CatFileCommit(afterCommitID)
222 if err != nil {
223 c.NotFoundOrError(gitutil.NewError(err), "get head commit")
224 return
225 }
226
227 diff, err := gitutil.RepoDiff(c.Repo.GitRepo,
228 afterCommitID, conf.Git.MaxDiffFiles, conf.Git.MaxDiffLines, conf.Git.MaxDiffLineChars,
229 git.DiffOptions{Base: beforeCommitID, Timeout: time.Duration(conf.Git.Timeout.Diff) * time.Second},
230 )
231 if err != nil {
232 c.NotFoundOrError(gitutil.NewError(err), "get diff")
233 return
234 }
235
236 commits, err := commit.CommitsAfter(beforeCommitID)
237 if err != nil {
238 c.NotFoundOrError(gitutil.NewError(err), "get commits after")
239 return
240 }
241
242 c.Data["IsSplitStyle"] = c.Query("style") == "split"
243 c.Data["CommitRepoLink"] = c.Repo.RepoLink
244 c.Data["Commits"] = matchUsersWithCommitEmails(c.Req.Context(), commits)
245 c.Data["CommitsCount"] = len(commits)
246 c.Data["BeforeCommitID"] = beforeCommitID
247 c.Data["AfterCommitID"] = afterCommitID
248 c.Data["Username"] = userName
249 c.Data["Reponame"] = repoName
250 c.Data["IsImageFile"] = commit.IsImageFile
251 c.Data["IsImageFileByIndex"] = commit.IsImageFileByIndex
252 c.Data["Title"] = "Comparing " + tool.ShortSHA1(beforeCommitID) + "..." + tool.ShortSHA1(afterCommitID) + " · " + userName + "/" + repoName
253 c.Data["Commit"] = commit
254 c.Data["Diff"] = diff
255 c.Data["DiffNotAvailable"] = diff.NumFiles() == 0
256 c.Data["SourcePath"] = conf.Server.Subpath + "/" + path.Join(userName, repoName, "src", afterCommitID)
257 c.Data["RawPath"] = conf.Server.Subpath + "/" + path.Join(userName, repoName, "raw", afterCommitID)
258 c.Data["BeforeSourcePath"] = conf.Server.Subpath + "/" + path.Join(userName, repoName, "src", beforeCommitID)
259 c.Data["BeforeRawPath"] = conf.Server.Subpath + "/" + path.Join(userName, repoName, "raw", beforeCommitID)
260 c.Success(DIFF)
261}

Callers

nothing calls this directly

Calls 6

NewErrorFunction · 0.92
RepoDiffFunction · 0.92
ShortSHA1Function · 0.92
SuccessMethod · 0.80
NotFoundOrErrorMethod · 0.45

Tested by

no test coverage detected