MCPcopy Create free account
hub / github.com/gogs/gogs / PrepareCompareDiff

Function PrepareCompareDiff

internal/route/repo/pull.go:560–618  ·  view source on GitHub ↗
(
	c *context.Context,
	headUser *database.User,
	headRepo *database.Repository,
	headGitRepo *git.Repository,
	meta *gitutil.PullRequestMeta,
	headRef string,
)

Source from the content-addressed store, hash-verified

558}
559
560func PrepareCompareDiff(
561 c *context.Context,
562 headUser *database.User,
563 headRepo *database.Repository,
564 headGitRepo *git.Repository,
565 meta *gitutil.PullRequestMeta,
566 headRef string,
567) bool {
568 var (
569 repo = c.Repo.Repository
570 err error
571 )
572
573 // Get diff information.
574 c.Data["CommitRepoLink"] = headRepo.Link()
575
576 headCommitID, err := headGitRepo.RevParse(headRef)
577 if err != nil {
578 c.Error(err, "get head commit ID")
579 return false
580 }
581 c.Data["AfterCommitID"] = headCommitID
582
583 if headCommitID == meta.MergeBase {
584 c.Data["IsNothingToCompare"] = true
585 return true
586 }
587
588 diff, err := gitutil.RepoDiff(headGitRepo,
589 headCommitID, conf.Git.MaxDiffFiles, conf.Git.MaxDiffLines, conf.Git.MaxDiffLineChars,
590 git.DiffOptions{Base: meta.MergeBase, Timeout: time.Duration(conf.Git.Timeout.Diff) * time.Second},
591 )
592 if err != nil {
593 c.Error(err, "get repository diff")
594 return false
595 }
596 c.Data["Diff"] = diff
597 c.Data["DiffNotAvailable"] = diff.NumFiles() == 0
598
599 headCommit, err := headGitRepo.CatFileCommit(headCommitID)
600 if err != nil {
601 c.Error(err, "get head commit")
602 return false
603 }
604
605 c.Data["Commits"] = matchUsersWithCommitEmails(c.Req.Context(), meta.Commits)
606 c.Data["CommitCount"] = len(meta.Commits)
607 c.Data["Username"] = headUser.Name
608 c.Data["Reponame"] = headRepo.Name
609 c.Data["IsImageFile"] = headCommit.IsImageFile
610 c.Data["IsImageFileByIndex"] = headCommit.IsImageFileByIndex
611
612 headTarget := path.Join(headUser.Name, repo.Name)
613 c.Data["SourcePath"] = conf.Server.Subpath + "/" + path.Join(headTarget, "src", headCommitID)
614 c.Data["RawPath"] = conf.Server.Subpath + "/" + path.Join(headTarget, "raw", headCommitID)
615 c.Data["BeforeSourcePath"] = conf.Server.Subpath + "/" + path.Join(headTarget, "src", meta.MergeBase)
616 c.Data["BeforeRawPath"] = conf.Server.Subpath + "/" + path.Join(headTarget, "raw", meta.MergeBase)
617 return false

Callers 2

CompareAndPullRequestFunction · 0.85

Calls 4

RepoDiffFunction · 0.92
LinkMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected