diff options
author | Toon Claes <toon@gitlab.com> | 2022-11-08 22:32:15 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2022-11-09 13:01:48 +0300 |
commit | 0cc3ee5a6525503db1fd2e6e33355ba7e7ae2fc7 (patch) | |
tree | 087293175ce6652c71d6c6c6827633671d34c60d | |
parent | d29103c0937aa2f37cbaf6cbb7951696e023e41f (diff) |
repository: Read license files with ReadObject()
To detect the license the Go implementation was spawning a
git-cat-file(1) process itself.
This change modifies the code to use the more optimal existing
ReadObject() function on localrepo.Repo.
-rw-r--r-- | internal/gitaly/service/repository/license.go | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/internal/gitaly/service/repository/license.go b/internal/gitaly/service/repository/license.go index 656a103c8..81b06ccc1 100644 --- a/internal/gitaly/service/repository/license.go +++ b/internal/gitaly/service/repository/license.go @@ -159,12 +159,9 @@ type gitFiler struct { } func (f *gitFiler) ReadFile(path string) ([]byte, error) { - var stdout, stderr bytes.Buffer - if err := f.repo.ExecAndWait(f.ctx, git.SubCmd{ - Name: "cat-file", - Args: []string{"blob", fmt.Sprintf("%s:%s", f.revision, path)}, - }, git.WithStdout(&stdout), git.WithStderr(&stderr)); err != nil { - return nil, fmt.Errorf("cat-file failed: %w, stderr: %q", err, stderr.String()) + data, err := f.repo.ReadObject(f.ctx, git.ObjectID(fmt.Sprintf("%s:%s", f.revision, path))) + if err != nil { + return nil, fmt.Errorf("read file: %w", err) } // `licensedb.Detect` only opens files that look like licenses. Failing that, it will @@ -182,7 +179,7 @@ func (f *gitFiler) ReadFile(path string) ([]byte, error) { } } - return stdout.Bytes(), nil + return data, nil } func (f *gitFiler) ReadDir(string) ([]filer.File, error) { |