Skip to content

Commit 1f8d01c

Browse files
GiteaBotearl-warren
authored andcommitted
Use information from previous blame parts (go-gitea#28572) (go-gitea#28577)
Backport go-gitea#28572 by @KN4CK3R Fixes go-gitea#28545 `git blame` output can contain blocks without commit information if it was outputted before (the `0dafa97ea3f6d9662299579e5be1875cd28baaae 48 26 1` line): ``` fec25436488499df7231f63b857f66457c193d5c 24 25 1 author Bastien Montagne author-mail <bastien@blender.org> author-time 1660731031 author-tz +0200 committer Bastien Montagne committer-mail <bastien@blender.org> committer-time 1660731031 committer-tz +0200 summary LibOverride: Add Make/Reset/Clear entries to IDTemplate contextual menu. previous 839ece6477203382b7a7483062961540180ff1cd source/blender/editors/interface/interface_ops.c filename source/blender/editors/interface/interface_ops.c #include "BLT_translation.h" 0dafa97ea3f6d9662299579e5be1875cd28baaae 48 26 1 3d57bc4397fca53bc9702a27bbf50102827829b0 27 27 1 author Hans Goudey author-mail <hans@blender.org> author-time 1700131315 author-tz +0100 committer Hans Goudey committer-mail <hooglyboogly@noreply.localhost> committer-time 1700131315 committer-tz +0100 summary Cleanup: Move several blenkernel headers to C++ previous 451c054d9b7d3148a646caa5a72fb127a5b5c408 source/blender/editors/interface/interface_ops.cc filename source/blender/editors/interface/interface_ops.cc #include "BKE_context.hh" ``` This PR reuses data from the previous blame part to fill these gaps. Co-authored-by: KN4CK3R <admin@oldschoolhack.me> (cherry picked from commit 1183002)
1 parent 12a8d65 commit 1f8d01c

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

routers/web/repo/blame.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func RefBlame(ctx *context.Context) {
125125
}
126126

127127
type blameResult struct {
128-
Parts []git.BlamePart
128+
Parts []*git.BlamePart
129129
UsesIgnoreRevs bool
130130
FaultyIgnoreRevsFile bool
131131
}
@@ -170,7 +170,9 @@ func performBlame(ctx *context.Context, repoPath string, commit *git.Commit, fil
170170
func fillBlameResult(br *git.BlameReader, r *blameResult) error {
171171
r.UsesIgnoreRevs = br.UsesIgnoreRevs()
172172

173-
r.Parts = make([]git.BlamePart, 0, 5)
173+
previousHelper := make(map[string]*git.BlamePart)
174+
175+
r.Parts = make([]*git.BlamePart, 0, 5)
174176
for {
175177
blamePart, err := br.NextPart()
176178
if err != nil {
@@ -179,13 +181,23 @@ func fillBlameResult(br *git.BlameReader, r *blameResult) error {
179181
if blamePart == nil {
180182
break
181183
}
182-
r.Parts = append(r.Parts, *blamePart)
184+
185+
if prev, ok := previousHelper[blamePart.Sha]; ok {
186+
if blamePart.PreviousSha == "" {
187+
blamePart.PreviousSha = prev.PreviousSha
188+
blamePart.PreviousPath = prev.PreviousPath
189+
}
190+
} else {
191+
previousHelper[blamePart.Sha] = blamePart
192+
}
193+
194+
r.Parts = append(r.Parts, blamePart)
183195
}
184196

185197
return nil
186198
}
187199

188-
func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) map[string]*user_model.UserCommit {
200+
func processBlameParts(ctx *context.Context, blameParts []*git.BlamePart) map[string]*user_model.UserCommit {
189201
// store commit data by SHA to look up avatar info etc
190202
commitNames := make(map[string]*user_model.UserCommit)
191203
// and as blameParts can reference the same commits multiple
@@ -227,7 +239,7 @@ func processBlameParts(ctx *context.Context, blameParts []git.BlamePart) map[str
227239
return commitNames
228240
}
229241

230-
func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames map[string]*user_model.UserCommit) {
242+
func renderBlame(ctx *context.Context, blameParts []*git.BlamePart, commitNames map[string]*user_model.UserCommit) {
231243
repoLink := ctx.Repo.RepoLink
232244

233245
language := ""

0 commit comments

Comments
 (0)