mirror of
https://github.com/go-gitea/gitea.git
synced 2026-01-19 07:35:12 +01:00
Maybe fix #32018 - Use `gitrepo.GetMergeBase` method instead of other two implementations. - Add `FetchRemoteCommit` so that we don't need to add many `remote` to the git repository to avoid possible git lock conflicts. A lock will start when invoke the function, it will be invoked when cross-repository comparing. The head repository will fetch the base repository's base commit id. In most situations, it should lock the fork repositories so that it should not become a bottleneck. - Improve `GetCompareInfo` to remove unnecessarily adding remote. - Remove unnecessary parameters of `SignMerge`.
29 lines
1.1 KiB
Go
29 lines
1.1 KiB
Go
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package gitrepo
|
|
|
|
import (
|
|
"context"
|
|
|
|
"code.gitea.io/gitea/modules/git/gitcmd"
|
|
"code.gitea.io/gitea/modules/globallock"
|
|
)
|
|
|
|
// FetchRemoteCommit fetches a specific commit and its related objects from a remote
|
|
// repository into the managed repository.
|
|
//
|
|
// If no reference (branch, tag, or other ref) points to the fetched commit, it will
|
|
// be treated as unreachable and cleaned up by `git gc` after the default prune
|
|
// expiration period (2 weeks). Ref: https://www.kernel.org/pub/software/scm/git/docs/git-gc.html
|
|
//
|
|
// This behavior is sufficient for temporary operations, such as determining the
|
|
// merge base between commits.
|
|
func FetchRemoteCommit(ctx context.Context, repo, remoteRepo Repository, commitID string) error {
|
|
return globallock.LockAndDo(ctx, getRepoWriteLockKey(repo.RelativePath()), func(ctx context.Context) error {
|
|
return RunCmd(ctx, repo, gitcmd.NewCommand("fetch", "--no-tags").
|
|
AddDynamicArguments(repoPath(remoteRepo)).
|
|
AddDynamicArguments(commitID))
|
|
})
|
|
}
|