Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
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
|
|
}
|