Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Cai <jcai@gitlab.com>2022-11-05 01:49:32 +0300
committerJohn Cai <jcai@gitlab.com>2022-11-10 02:31:36 +0300
commit2697e11477dee181066c085059e336792a092ad8 (patch)
tree1e3e031a5b4074afbf6a4b6ca9599d6bbd458005
parent105c5baf9d0e0a21f131bfec622484a7f63d3b96 (diff)
operations: Refactor Git2Go submodule code into its own function
To prepare for a pure git implementation of update submodules without a worktree, first refactor the current git2go implementation into its own function.
-rw-r--r--internal/gitaly/service/operations/submodules.go84
1 files changed, 55 insertions, 29 deletions
diff --git a/internal/gitaly/service/operations/submodules.go b/internal/gitaly/service/operations/submodules.go
index 98cccb326..03c6be7c2 100644
--- a/internal/gitaly/service/operations/submodules.go
+++ b/internal/gitaly/service/operations/submodules.go
@@ -9,6 +9,7 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/updateref"
"gitlab.com/gitlab-org/gitaly/v15/internal/git2go"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
@@ -60,40 +61,29 @@ func validateUserUpdateSubmoduleRequest(req *gitalypb.UserUpdateSubmoduleRequest
return nil
}
-func (s *Server) userUpdateSubmodule(ctx context.Context, req *gitalypb.UserUpdateSubmoduleRequest) (*gitalypb.UserUpdateSubmoduleResponse, error) {
- quarantineDir, quarantineRepo, err := s.quarantinedRepo(ctx, req.GetRepository())
- if err != nil {
- return nil, err
- }
-
- branches, err := quarantineRepo.GetBranches(ctx)
- if err != nil {
- return nil, fmt.Errorf("%s: get branches: %w", userUpdateSubmoduleName, err)
- }
- if len(branches) == 0 {
- return &gitalypb.UserUpdateSubmoduleResponse{
- CommitError: "Repository is empty",
- }, nil
- }
-
- referenceName := git.NewReferenceNameFromBranchName(string(req.GetBranch()))
-
- branchOID, err := quarantineRepo.ResolveRevision(ctx, referenceName.Revision())
- if err != nil {
- if errors.Is(err, git.ErrReferenceNotFound) {
- return nil, helper.ErrInvalidArgumentf("Cannot find branch")
+func (s *Server) updateSubmodule(ctx context.Context, quarantineRepo *localrepo.Repo, req *gitalypb.UserUpdateSubmoduleRequest) (string, error) {
+ /*
+ commit, err := quarantineRepo.ReadCommit(ctx, req.GetBranch())
+ if err != nil {
+ return "", fmt.Errorf("reading branch %s: %w", req.GetBranch(), err)
}
- return nil, fmt.Errorf("%s: get branch: %w", userUpdateSubmoduleName, err)
- }
+ */
+ /* get the blob of the submodule path of submdulepath/HEAD */
+ /* write a new blob for the HEAD */
+ /* write a new tree object for the submodule */
+ /* write a new commit with the tree */
+ return "", nil
+}
+func (s *Server) updateSubmoduleWithGit2Go(ctx context.Context, quarantineRepo *localrepo.Repo, req *gitalypb.UserUpdateSubmoduleRequest) (string, error) {
repoPath, err := quarantineRepo.Path()
if err != nil {
- return nil, fmt.Errorf("%s: locate repo: %w", userUpdateSubmoduleName, err)
+ return "", fmt.Errorf("%s: locate repo: %w", userUpdateSubmoduleName, err)
}
authorDate, err := dateFromProto(req)
if err != nil {
- return nil, helper.ErrInvalidArgument(err)
+ return "", helper.ErrInvalidArgument(err)
}
result, err := s.git2goExecutor.Submodule(ctx, quarantineRepo, git2go.SubmoduleCommand{
@@ -106,6 +96,31 @@ func (s *Server) userUpdateSubmodule(ctx context.Context, req *gitalypb.UserUpda
Submodule: string(req.GetSubmodule()),
Message: string(req.GetCommitMessage()),
})
+
+ if err != nil {
+ return "", err
+ }
+
+ return result.CommitID, nil
+}
+
+func (s *Server) userUpdateSubmodule(ctx context.Context, req *gitalypb.UserUpdateSubmoduleRequest) (*gitalypb.UserUpdateSubmoduleResponse, error) {
+ quarantineDir, quarantineRepo, err := s.quarantinedRepo(ctx, req.GetRepository())
+ if err != nil {
+ return nil, err
+ }
+
+ branches, err := quarantineRepo.GetBranches(ctx)
+ if err != nil {
+ return nil, fmt.Errorf("%s: get branches: %w", userUpdateSubmoduleName, err)
+ }
+ if len(branches) == 0 {
+ return &gitalypb.UserUpdateSubmoduleResponse{
+ CommitError: "Repository is empty",
+ }, nil
+ }
+
+ commitID, err := s.updateSubmoduleWithGit2Go(ctx, quarantineRepo, req)
if err != nil {
errStr := strings.TrimPrefix(err.Error(), "submodule: ")
errStr = strings.TrimSpace(errStr)
@@ -135,21 +150,32 @@ func (s *Server) userUpdateSubmodule(ctx context.Context, req *gitalypb.UserUpda
if resp != nil {
return resp, nil
}
+
return nil, fmt.Errorf("%s: submodule subcommand: %w", userUpdateSubmoduleName, err)
}
- commitID, err := git.ObjectHashSHA1.FromHex(result.CommitID)
+ commitOID, err := git.ObjectHashSHA1.FromHex(commitID)
if err != nil {
return nil, helper.ErrInvalidArgumentf("cannot parse commit ID: %w", err)
}
+ referenceName := git.NewReferenceNameFromBranchName(string(req.GetBranch()))
+
+ branchOID, err := quarantineRepo.ResolveRevision(ctx, referenceName.Revision())
+ if err != nil {
+ if errors.Is(err, git.ErrReferenceNotFound) {
+ return nil, helper.ErrInvalidArgumentf("Cannot find branch")
+ }
+ return nil, fmt.Errorf("%s: get branch: %w", userUpdateSubmoduleName, err)
+ }
+
if err := s.updateReferenceWithHooks(
ctx,
req.GetRepository(),
req.GetUser(),
quarantineDir,
referenceName,
- commitID,
+ commitOID,
branchOID,
); err != nil {
var customHookErr updateref.CustomHookError
@@ -171,7 +197,7 @@ func (s *Server) userUpdateSubmodule(ctx context.Context, req *gitalypb.UserUpda
return &gitalypb.UserUpdateSubmoduleResponse{
BranchUpdate: &gitalypb.OperationBranchUpdate{
- CommitId: result.CommitID,
+ CommitId: commitID,
BranchCreated: false,
RepoCreated: false,
},