Use the database object format name but not read from git repoisitory everytime and fix possible migration wrong objectformat when migrating a sha256 repository (#29294)
Now we can get object format name from git command line or from the
database repository table. Assume the column is right, we don't need to
read from git command line every time.
This also fixed a possible bug that the object format is wrong when
migrating a sha256 repository from external.
<img width="658" alt="image"
src="6e9a9dcf
-13bf-4267-928b-6bf2c2560423">
(cherry picked from commit b79c30435f439af8243ee281310258cdf141e27b)
Conflicts:
routers/web/repo/blame.go
services/agit/agit.go
context
This commit is contained in:
parent
f097799953
commit
6905540088
17 changed files with 40 additions and 57 deletions
|
@ -28,10 +28,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
|||
title, hasTitle := opts.GitPushOptions["title"]
|
||||
description, hasDesc := opts.GitPushOptions["description"]
|
||||
|
||||
objectFormat, err := gitRepo.GetObjectFormat()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("couldn't get object format of the repository: %w", err)
|
||||
}
|
||||
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
|
||||
|
||||
pusher, err := user_model.GetUserByID(ctx, opts.UserID)
|
||||
if err != nil {
|
||||
|
|
|
@ -140,8 +140,18 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
g.gitRepo, err = gitrepo.OpenRepository(g.ctx, r)
|
||||
return err
|
||||
g.gitRepo, err = gitrepo.OpenRepository(g.ctx, g.repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// detect object format from git repository and update to database
|
||||
objectFormat, err := g.gitRepo.GetObjectFormat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
g.repo.ObjectFormatName = objectFormat.Name()
|
||||
return repo_model.UpdateRepositoryCols(g.ctx, g.repo, "object_format_name")
|
||||
}
|
||||
|
||||
// Close closes this uploader
|
||||
|
@ -901,7 +911,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
|
|||
comment.UpdatedAt = comment.CreatedAt
|
||||
}
|
||||
|
||||
objectFormat, _ := g.gitRepo.GetObjectFormat()
|
||||
objectFormat := git.ObjectFormatFromName(g.repo.ObjectFormatName)
|
||||
if !objectFormat.IsValid(comment.CommitID) {
|
||||
log.Warn("Invalid comment CommitID[%s] on comment[%d] in PR #%d of %s/%s replaced with %s", comment.CommitID, pr.Index, g.repoOwner, g.repoName, headCommitID)
|
||||
comment.CommitID = headCommitID
|
||||
|
|
|
@ -222,10 +222,7 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
|
|||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
objectFormat, err := gitRepo.GetObjectFormat()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%-v GetObjectFormat: %w", pr.BaseRepo, err)
|
||||
}
|
||||
objectFormat := git.ObjectFormatFromName(pr.BaseRepo.ObjectFormatName)
|
||||
|
||||
// Get the commit from BaseBranch where the pull request got merged
|
||||
mergeCommit, _, err := git.NewCommand(ctx, "rev-list", "--ancestry-path", "--merges", "--reverse").
|
||||
|
|
|
@ -503,7 +503,7 @@ func MergedManually(ctx context.Context, pr *issues_model.PullRequest, doer *use
|
|||
return models.ErrInvalidMergeStyle{ID: pr.BaseRepo.ID, Style: repo_model.MergeStyleManuallyMerged}
|
||||
}
|
||||
|
||||
objectFormat, _ := baseGitRepo.GetObjectFormat()
|
||||
objectFormat := git.ObjectFormatFromName(pr.BaseRepo.ObjectFormatName)
|
||||
if len(commitID) != objectFormat.FullLength() {
|
||||
return fmt.Errorf("Wrong commit ID")
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Rel
|
|||
created = true
|
||||
rel.LowerTagName = strings.ToLower(rel.TagName)
|
||||
|
||||
objectFormat, _ := gitRepo.GetObjectFormat()
|
||||
objectFormat := git.ObjectFormatFromName(rel.Repo.ObjectFormatName)
|
||||
commits := repository.NewPushCommits()
|
||||
commits.HeadCommit = repository.CommitToPushCommit(commit)
|
||||
commits.CompareURL = rel.Repo.ComposeCompareURL(objectFormat.EmptyObjectID().String(), commit.ID.String())
|
||||
|
|
|
@ -369,11 +369,6 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
|
|||
return fmt.Errorf("GetBranch: %v", err)
|
||||
}
|
||||
|
||||
objectFormat, err := gitRepo.GetObjectFormat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if rawBranch.IsDeleted {
|
||||
return nil
|
||||
}
|
||||
|
@ -395,6 +390,8 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
|
|||
return err
|
||||
}
|
||||
|
||||
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
|
||||
|
||||
// Don't return error below this
|
||||
if err := PushUpdate(
|
||||
&repo_module.PushUpdateOptions{
|
||||
|
|
|
@ -30,10 +30,8 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
|
|||
}
|
||||
defer closer.Close()
|
||||
|
||||
objectFormat, err := gitRepo.GetObjectFormat()
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetObjectFormat[%s]: %w", repoPath, err)
|
||||
}
|
||||
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
|
||||
|
||||
commit, err := gitRepo.GetCommit(sha)
|
||||
if err != nil {
|
||||
gitRepo.Close()
|
||||
|
|
|
@ -37,7 +37,7 @@ func GetTreeBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git
|
|||
}
|
||||
apiURL := repo.APIURL()
|
||||
apiURLLen := len(apiURL)
|
||||
objectFormat, _ := gitRepo.GetObjectFormat()
|
||||
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
|
||||
hashLen := objectFormat.FullLength()
|
||||
|
||||
const gitBlobsPath = "/git/blobs/"
|
||||
|
|
|
@ -79,7 +79,7 @@ func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.R
|
|||
|
||||
store := lfs.NewContentStore()
|
||||
errStop := errors.New("STOPERR")
|
||||
objectFormat, _ := gitRepo.GetObjectFormat()
|
||||
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
|
||||
|
||||
err = git_model.IterateLFSMetaObjectsForRepo(ctx, repo.ID, func(ctx context.Context, metaObject *git_model.LFSMetaObject, count int64) error {
|
||||
if opts.NumberToCheckPerRepo > 0 && total > opts.NumberToCheckPerRepo {
|
||||
|
|
|
@ -93,11 +93,6 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
|||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
objectFormat, err := gitRepo.GetObjectFormat()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unknown repository ObjectFormat [%s]: %w", repo.FullName(), err)
|
||||
}
|
||||
|
||||
if err = repo_module.UpdateRepoSize(ctx, repo); err != nil {
|
||||
return fmt.Errorf("Failed to update size for repository: %v", err)
|
||||
}
|
||||
|
@ -105,6 +100,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
|||
addTags := make([]string, 0, len(optsList))
|
||||
delTags := make([]string, 0, len(optsList))
|
||||
var pusher *user_model.User
|
||||
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
|
||||
|
||||
for _, opts := range optsList {
|
||||
log.Trace("pushUpdates: %-v %s %s %s", repo, opts.OldCommitID, opts.NewCommitID, opts.RefFullName)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue