From 8d799c236c854c8bb132b38c97385beaf53d9327 Mon Sep 17 00:00:00 2001 From: badhezi Date: Tue, 15 Apr 2025 19:56:19 +0300 Subject: [PATCH 1/6] use the correct context data for PR link template in issue card --- templates/repo/issue/card.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/card.tmpl b/templates/repo/issue/card.tmpl index c7bbe91885012..41fe6cea8fbae 100644 --- a/templates/repo/issue/card.tmpl +++ b/templates/repo/issue/card.tmpl @@ -45,7 +45,7 @@ {{if $.Page.LinkedPRs}} {{range index $.Page.LinkedPRs .ID}}
- + {{svg "octicon-git-merge" 16 "tw-mr-1 tw-align-middle"}} {{.Title}} #{{.Index}} From 925fedce19ccca97ddb54a0cfb8fd6621fddef3c Mon Sep 17 00:00:00 2001 From: badhezi Date: Wed, 30 Jul 2025 17:55:17 +0300 Subject: [PATCH 2/6] assign startCommitID as the endcommit parent when viewfing specific commit in pull --- routers/web/repo/pull.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index c5302dd50f58d..6727d05fc2f8d 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -748,6 +748,22 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi if !willShowSpecifiedCommit { diffOptions.BeforeCommitID = startCommitID + } else { + endCommit, err := gitRepo.GetCommit(endCommitID) + if err != nil { + ctx.ServerError("GetCommit", err) + return + } + + if endCommit.ParentCount() > 0 { + endCommitParent, err := endCommit.Parent(0) + if err != nil { + ctx.ServerError("Parent", err) + return + } + + startCommitID = endCommitParent.ID.String() + } } diff, err := gitdiff.GetDiffForRender(ctx, ctx.Repo.RepoLink, gitRepo, diffOptions, files...) From 2c5ea4cdc35dde4684b1392872106c4d9148c32e Mon Sep 17 00:00:00 2001 From: badhezi Date: Wed, 30 Jul 2025 19:46:42 +0300 Subject: [PATCH 3/6] improve readability --- routers/web/repo/pull.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 6727d05fc2f8d..0791d66df6ec3 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -746,9 +746,10 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)), } - if !willShowSpecifiedCommit { - diffOptions.BeforeCommitID = startCommitID - } else { + if willShowSpecifiedCommit { + // Attempt to extract parent commit when viewing diff of a specific commit + // instead of showing the entire diff-tree from the merge base. + // This is mostly for the GetDiffTree() call endCommit, err := gitRepo.GetCommit(endCommitID) if err != nil { ctx.ServerError("GetCommit", err) @@ -761,9 +762,11 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi ctx.ServerError("Parent", err) return } - startCommitID = endCommitParent.ID.String() } + + } else { + diffOptions.BeforeCommitID = startCommitID } diff, err := gitdiff.GetDiffForRender(ctx, ctx.Repo.RepoLink, gitRepo, diffOptions, files...) From d5d6912a8410299283ee8a5d71da7c21747ff588 Mon Sep 17 00:00:00 2001 From: badhezi Date: Wed, 30 Jul 2025 19:47:17 +0300 Subject: [PATCH 4/6] improve readability --- routers/web/repo/pull.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 0791d66df6ec3..753f71cc31ba6 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -747,7 +747,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi } if willShowSpecifiedCommit { - // Attempt to extract parent commit when viewing diff of a specific commit + // Attempt to extract parent of endCommit commit when viewing diff of a specific commit // instead of showing the entire diff-tree from the merge base. // This is mostly for the GetDiffTree() call endCommit, err := gitRepo.GetCommit(endCommitID) From c43bda5817c50d2f1d62879489dcd013bd1fc613 Mon Sep 17 00:00:00 2001 From: badhezi Date: Wed, 30 Jul 2025 19:48:55 +0300 Subject: [PATCH 5/6] improve readability --- routers/web/repo/pull.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 753f71cc31ba6..ea61c3607b99e 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -747,7 +747,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi } if willShowSpecifiedCommit { - // Attempt to extract parent of endCommit commit when viewing diff of a specific commit + // Attempt to extract parent of endCommit when viewing diff of a specific commit // instead of showing the entire diff-tree from the merge base. // This is mostly for the GetDiffTree() call endCommit, err := gitRepo.GetCommit(endCommitID) From 19019dab7350f8035517eec1978253f93e229ebf Mon Sep 17 00:00:00 2001 From: badhezi Date: Wed, 30 Jul 2025 20:04:15 +0300 Subject: [PATCH 6/6] lint --- routers/web/repo/pull.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index ea61c3607b99e..2bd6e0beb141b 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -747,15 +747,14 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi } if willShowSpecifiedCommit { - // Attempt to extract parent of endCommit when viewing diff of a specific commit - // instead of showing the entire diff-tree from the merge base. + // Attempt to extract parent of endCommit when viewing diff of a specific commit. + // Instead of showing the entire diff-tree from the merge base, we only show diff-tree from the commit's parent. // This is mostly for the GetDiffTree() call endCommit, err := gitRepo.GetCommit(endCommitID) if err != nil { ctx.ServerError("GetCommit", err) return } - if endCommit.ParentCount() > 0 { endCommitParent, err := endCommit.Parent(0) if err != nil { @@ -764,7 +763,6 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi } startCommitID = endCommitParent.ID.String() } - } else { diffOptions.BeforeCommitID = startCommitID }