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:
Diffstat (limited to 'internal/gitaly/service/repository/info_attributes.go')
-rw-r--r--internal/gitaly/service/repository/info_attributes.go51
1 files changed, 39 insertions, 12 deletions
diff --git a/internal/gitaly/service/repository/info_attributes.go b/internal/gitaly/service/repository/info_attributes.go
index 9ddf04fdc..f5a9628b2 100644
--- a/internal/gitaly/service/repository/info_attributes.go
+++ b/internal/gitaly/service/repository/info_attributes.go
@@ -1,16 +1,17 @@
package repository
import (
- "io"
- "os"
- "path/filepath"
-
+ "bufio"
+ "gitlab.com/gitlab-org/gitaly/v16/internal/git"
"gitlab.com/gitlab-org/gitaly/v16/internal/structerr"
"gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v16/streamio"
+ "io"
+ "os"
+ "strings"
)
-func (s *server) GetInfoAttributes(in *gitalypb.GetInfoAttributesRequest, stream gitalypb.RepositoryService_GetInfoAttributesServer) error {
+func (s *server) GetInfoAttributes(in *gitalypb.GetInfoAttributesRequest, stream gitalypb.RepositoryService_GetInfoAttributesServer) (returnedErr error) {
repository := in.GetRepository()
if err := s.locator.ValidateRepository(repository); err != nil {
return structerr.NewInvalidArgument("%w", err)
@@ -20,14 +21,40 @@ func (s *server) GetInfoAttributes(in *gitalypb.GetInfoAttributesRequest, stream
return err
}
- attrFile := filepath.Join(repoPath, "info", "attributes")
- f, err := os.Open(attrFile)
- if err != nil {
- if os.IsNotExist(err) {
- return stream.Send(&gitalypb.GetInfoAttributesResponse{})
+ // In git 2.43.0+, gitattributes supports reading from HEAD:.gitattributes,
+ // so info/attributes is no longer needed. To make sure info/attributes file is cleaned up,
+ // we delete it if it exists when reading from HEAD:.gitattributes is called.
+ // This logic can be removed when ApplyGitattributes and GetInfoAttributes PRC are totally removed from
+ // the code base.
+ deletionErr := deleteInfoAttributesFile(repoPath)
+ if !os.IsNotExist(deletionErr) {
+ s.logger.WithError(deletionErr).Error("failed to delete info/gitattributes file at " + repoPath)
+ }
+
+ repo := s.localrepo(in.GetRepository())
+ ctx := stream.Context()
+ var stderr strings.Builder
+ // Call cat-file -p HEAD:.gitattributes instead of cat info/attributes
+ catFileCmd, err := repo.Exec(ctx, git.Command{
+ Name: "cat-file",
+ Flags: []git.Option{
+ git.Flag{Name: "-p"},
+ },
+ Args: []string{"HEAD:.gitattributes"},
+ },
+ git.WithSetupStdout(),
+ git.WithStderr(&stderr),
+ )
+ defer func() {
+ if err := catFileCmd.Wait(); err != nil {
+ s.logger.Error("git cat-file command error: " + stderr.String())
}
+ }()
- return structerr.NewInternal("failure to read info attributes: %w", err)
+ buf := bufio.NewReader(catFileCmd)
+ _, err = buf.Peek(1)
+ if err == io.EOF {
+ return stream.Send(&gitalypb.GetInfoAttributesResponse{})
}
sw := streamio.NewWriter(func(p []byte) error {
@@ -35,7 +62,7 @@ func (s *server) GetInfoAttributes(in *gitalypb.GetInfoAttributesRequest, stream
Attributes: p,
})
})
+ _, err = io.Copy(sw, buf)
- _, err = io.Copy(sw, f)
return err
}