Skip to content

Commit

Permalink
Use beforeCommit instead of baseCommit
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
  • Loading branch information
kdumontnu and jtran committed Feb 17, 2023
1 parent d9c6cb7 commit 287516b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions routers/web/repo/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const (
)

// setCompareContext sets context data.
func setCompareContext(ctx *context.Context, base, head *git.Commit, headOwner, headName string) {
ctx.Data["BaseCommit"] = base
func setCompareContext(ctx *context.Context, before, head *git.Commit, headOwner, headName string) {
ctx.Data["BeforeCommit"] = before
ctx.Data["HeadCommit"] = head

ctx.Data["GetBlobByPathForCommit"] = func(commit *git.Commit, path string) *git.Blob {
Expand All @@ -59,7 +59,7 @@ func setCompareContext(ctx *context.Context, base, head *git.Commit, headOwner,
return blob
}

setPathsCompareContext(ctx, base, head, headOwner, headName)
setPathsCompareContext(ctx, before, head, headOwner, headName)
setImageCompareContext(ctx)
setCsvCompareContext(ctx)
}
Expand Down Expand Up @@ -629,9 +629,8 @@ func PrepareCompareDiff(
}

baseGitRepo := ctx.Repo.GitRepo
baseCommitID := ci.CompareInfo.BaseCommitID

baseCommit, err := baseGitRepo.GetCommit(baseCommitID)
beforeCommit, err := baseGitRepo.GetCommit(beforeCommitID)
if err != nil {
ctx.ServerError("GetCommit", err)
return false
Expand Down Expand Up @@ -668,7 +667,7 @@ func PrepareCompareDiff(
ctx.Data["Username"] = ci.HeadUser.Name
ctx.Data["Reponame"] = ci.HeadRepo.Name

setCompareContext(ctx, baseCommit, headCommit, ci.HeadUser.Name, repo.Name)
setCompareContext(ctx, beforeCommit, headCommit, ci.HeadUser.Name, repo.Name)

return false
}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/diff/box.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<div id="diff-file-boxes" class="sixteen wide column">
{{range $i, $file := .Diff.Files}}
{{/*notice: the index of Diff.Files should not be used for element ID, because the index will be restarted from 0 when doing load-more for PRs with a lot of files*/}}
{{$blobBase := call $.GetBlobByPathForCommit $.BaseCommit $file.OldName}}
{{$blobBase := call $.GetBlobByPathForCommit $.BeforeCommit $file.OldName}}
{{$blobHead := call $.GetBlobByPathForCommit $.HeadCommit $file.Name}}
{{$isImage := or (call $.IsBlobAnImage $blobBase) (call $.IsBlobAnImage $blobHead)}}
{{$isCsv := (call $.IsCsvFile $file)}}
Expand Down

0 comments on commit 287516b

Please sign in to comment.