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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-10-12 13:04:52 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-10-14 08:39:51 +0300
commit725016f263f4b2b2ab9586016b791e8328ce6c7e (patch)
tree5b8999ae527cca52c2b1536783d1a35046a167e4 /internal
parentf26d4e3d0a5d28761c981d2f84e4a4301a70e208 (diff)
repository: Use object reader to read gitattributes file
We're currently using the deprecated Batch interface to read information about the gitattributes file we're about to apply. Currently, we're using it for three steps: first, we check whether the source commit exists at all via `Info()`, then we retrieve object info of the blob via `Info()`, and then we retrieve the blob reader via `Blob()`. We cannot skip the first step, but doing this via `localrepo.ResolveRevision()` is much more straight-forward. The second and third steps can be combined into a single step though by just using `Object()` directly, avoiding one needless roundtrip.
Diffstat (limited to 'internal')
-rw-r--r--internal/gitaly/service/repository/apply_gitattributes.go22
1 files changed, 9 insertions, 13 deletions
diff --git a/internal/gitaly/service/repository/apply_gitattributes.go b/internal/gitaly/service/repository/apply_gitattributes.go
index 00d3c2bf7..011e363d5 100644
--- a/internal/gitaly/service/repository/apply_gitattributes.go
+++ b/internal/gitaly/service/repository/apply_gitattributes.go
@@ -10,6 +10,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v14/internal/git"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/catfile"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v14/internal/helper"
"gitlab.com/gitlab-org/gitaly/v14/internal/safe"
@@ -20,25 +21,25 @@ import (
const attributesFileMode os.FileMode = 0o644
-func (s *server) applyGitattributes(ctx context.Context, c catfile.Batch, repoPath string, revision []byte) error {
+func (s *server) applyGitattributes(ctx context.Context, repo *localrepo.Repo, objectReader catfile.ObjectReader, repoPath string, revision []byte) error {
infoPath := filepath.Join(repoPath, "info")
attributesPath := filepath.Join(infoPath, "attributes")
- _, err := c.Info(ctx, git.Revision(revision))
+ _, err := repo.ResolveRevision(ctx, git.Revision(revision)+"^{commit}")
if err != nil {
- if catfile.IsNotFound(err) {
+ if errors.Is(err, git.ErrReferenceNotFound) {
return helper.ErrInvalidArgumentf("revision does not exist")
}
return err
}
- blobInfo, err := c.Info(ctx, git.Revision(fmt.Sprintf("%s:.gitattributes", revision)))
+ blobObj, err := objectReader.Object(ctx, git.Revision(fmt.Sprintf("%s:.gitattributes", revision)))
if err != nil && !catfile.IsNotFound(err) {
return err
}
- if catfile.IsNotFound(err) || blobInfo.Type != "blob" {
+ if catfile.IsNotFound(err) || blobObj.Type != "blob" {
// If there is no gitattributes file, we simply use the ZeroOID
// as a placeholder to vote on the removal.
if err := s.vote(ctx, git.ZeroOID); err != nil {
@@ -58,11 +59,6 @@ func (s *server) applyGitattributes(ctx context.Context, c catfile.Batch, repoPa
return err
}
- blobObj, err := c.Blob(ctx, git.Revision(blobInfo.Oid))
- if err != nil {
- return err
- }
-
writer, err := safe.NewLockingFileWriter(attributesPath, safe.LockingFileWriterConfig{
FileWriterConfig: safe.FileWriterConfig{FileMode: attributesFileMode},
})
@@ -71,7 +67,7 @@ func (s *server) applyGitattributes(ctx context.Context, c catfile.Batch, repoPa
}
defer writer.Close()
- if _, err := io.CopyN(writer, blobObj.Reader, blobInfo.Size); err != nil {
+ if _, err := io.Copy(writer, blobObj.Reader); err != nil {
return err
}
@@ -116,12 +112,12 @@ func (s *server) ApplyGitattributes(ctx context.Context, in *gitalypb.ApplyGitat
return nil, helper.ErrInvalidArgumentf("revision: %v", err)
}
- c, err := s.catfileCache.BatchProcess(ctx, repo)
+ objectReader, err := s.catfileCache.ObjectReader(ctx, repo)
if err != nil {
return nil, err
}
- if err := s.applyGitattributes(ctx, c, repoPath, in.GetRevision()); err != nil {
+ if err := s.applyGitattributes(ctx, repo, objectReader, repoPath, in.GetRevision()); err != nil {
return nil, err
}