mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-01 19:54:17 +00:00
0ab3d569b4
Regression of the ctx removal from "git.Repository" struct (the old code was already wrong and can still cause 500, the "ctx removal" just makes the problem easier to reproduce). Merge duplicate code. Reviewd by codex: no actionable findings.
44 lines
997 B
Go
44 lines
997 B
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//go:build !gogit
|
|
|
|
package git
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// GetLastCommitForPaths returns last commit information
|
|
func GetLastCommitForPaths(ctx context.Context, gitRepo *Repository, commit *Commit, treePath string, paths []string) (map[string]*Commit, error) {
|
|
// We read backwards from the commit to obtain all of the commits
|
|
revs, err := walkGitLog(ctx, gitRepo, commit, treePath, paths...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
commitsMap := map[string]*Commit{}
|
|
commitsMap[commit.ID.String()] = commit
|
|
|
|
commitCommits := map[string]*Commit{}
|
|
for path, commitID := range revs {
|
|
if len(commitID) == 0 {
|
|
continue
|
|
}
|
|
|
|
c, ok := commitsMap[commitID]
|
|
if ok {
|
|
commitCommits[path] = c
|
|
continue
|
|
}
|
|
|
|
c, err := gitRepo.GetCommit(ctx, commitID) // Ensure the commit exists in the repository
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
commitCommits[path] = c
|
|
}
|
|
|
|
return commitCommits, nil
|
|
}
|