Skip to content

Commit 2b3f12f

Browse files
kdumontnujtran
andauthored
Use beforeCommit instead of baseCommit (#22949)
Replaces: #22947 Fixes #22946 Probably related to #19530 Basically, many of the diffs were broken because they were comparing to the base commit, where a 3-dot diff should be comparing to the [last common ancestor](https://matthew-brett.github.io/pydagogue/git_diff_dots.html). This should have an integration test so that we don’t run into this issue again. --------- Co-authored-by: Jonathan Tran <[email protected]>
1 parent 6840a8c commit 2b3f12f

20 files changed

+110
-11
lines changed

models/db/iterate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestIterate(t *testing.T) {
2525
return nil
2626
})
2727
assert.NoError(t, err)
28-
assert.EqualValues(t, 81, repoCnt)
28+
assert.EqualValues(t, 83, repoCnt)
2929

3030
err = db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repoUnit *repo_model.RepoUnit) error {
3131
reopUnit2 := repo_model.RepoUnit{ID: repoUnit.ID}

models/fixtures/repo_unit.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,16 @@
556556
repo_id: 54
557557
type: 1
558558
created_unix: 946684810
559+
560+
-
561+
id: 82
562+
repo_id: 31
563+
type: 1
564+
created_unix: 946684810
565+
566+
-
567+
id: 83
568+
repo_id: 31
569+
type: 3
570+
config: "{\"IgnoreWhitespaceConflicts\":false,\"AllowMerge\":true,\"AllowRebase\":true,\"AllowRebaseMerge\":true,\"AllowSquash\":true}"
571+
created_unix: 946684810

routers/web/repo/compare.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ const (
4343
)
4444

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

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

62-
setPathsCompareContext(ctx, base, head, headOwner, headName)
62+
setPathsCompareContext(ctx, before, head, headOwner, headName)
6363
setImageCompareContext(ctx)
6464
setCsvCompareContext(ctx)
6565
}
@@ -629,9 +629,8 @@ func PrepareCompareDiff(
629629
}
630630

631631
baseGitRepo := ctx.Repo.GitRepo
632-
baseCommitID := ci.CompareInfo.BaseCommitID
633632

634-
baseCommit, err := baseGitRepo.GetCommit(baseCommitID)
633+
beforeCommit, err := baseGitRepo.GetCommit(beforeCommitID)
635634
if err != nil {
636635
ctx.ServerError("GetCommit", err)
637636
return false
@@ -668,7 +667,7 @@ func PrepareCompareDiff(
668667
ctx.Data["Username"] = ci.HeadUser.Name
669668
ctx.Data["Reponame"] = ci.HeadRepo.Name
670669

671-
setCompareContext(ctx, baseCommit, headCommit, ci.HeadUser.Name, repo.Name)
670+
setCompareContext(ctx, beforeCommit, headCommit, ci.HeadUser.Name, repo.Name)
672671

673672
return false
674673
}

templates/repo/diff/box.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<div id="diff-file-boxes" class="sixteen wide column">
7272
{{range $i, $file := .Diff.Files}}
7373
{{/*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*/}}
74-
{{$blobBase := call $.GetBlobByPathForCommit $.BaseCommit $file.OldName}}
74+
{{$blobBase := call $.GetBlobByPathForCommit $.BeforeCommit $file.OldName}}
7575
{{$blobHead := call $.GetBlobByPathForCommit $.HeadCommit $file.Name}}
7676
{{$isImage := or (call $.IsBlobAnImage $blobBase) (call $.IsBlobAnImage $blobHead)}}
7777
{{$isCsv := (call $.IsCsvFile $file)}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env bash
2-
"/home/tris/Projects/go/src/code.gitea.io/gitea/gitea" hook --config='/home/tris/Projects/go/src/code.gitea.io/gitea/custom/conf/app.ini' post-receive
2+
"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" post-receive
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env bash
2-
"/home/tris/Projects/go/src/code.gitea.io/gitea/gitea" hook --config='/home/tris/Projects/go/src/code.gitea.io/gitea/custom/conf/app.ini' pre-receive
2+
"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" pre-receive
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env bash
2-
"/home/tris/Projects/go/src/code.gitea.io/gitea/gitea" hook --config='/home/tris/Projects/go/src/code.gitea.io/gitea/custom/conf/app.ini' update $1 $2 $3
2+
"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" update $1 $2 $3
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x��An�0 s�+���l� �[_A�TkIJC>���z[,f1��Z�!�K�̀��S��L5[,�D҉'�:a�Rнe���Dl� �:^C�g�lH�d���>iqr��m��s1���K���m=?U��3o������������k�ߝ{��@w�ʼ���E]

0 commit comments

Comments
 (0)