diff options
author | Toon Claes <toon@gitlab.com> | 2022-11-07 22:54:06 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2022-11-09 11:59:28 +0300 |
commit | 22bdd489d5f92aadee8186a5eabcf9366d591e41 (patch) | |
tree | b20ac266829f4e55759516e044ba36d6344a5c66 | |
parent | 74a7785251b274fee77b86ae888641164e482d30 (diff) |
repository: Use exact revision in find license
In the FindLicense RPC all files where located by the HEAD revision.
With this change the HEAD revision is resolved to an exact object ID and
that is use when browsing the tree.
-rw-r--r-- | internal/gitaly/service/repository/license.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/internal/gitaly/service/repository/license.go b/internal/gitaly/service/repository/license.go index ac7284677..29e2e6a9e 100644 --- a/internal/gitaly/service/repository/license.go +++ b/internal/gitaly/service/repository/license.go @@ -48,15 +48,15 @@ func (s *server) FindLicense(ctx context.Context, req *gitalypb.FindLicenseReque if featureflag.GoFindLicense.IsEnabled(ctx) { repo := localrepo.New(s.locator, s.gitCmdFactory, s.catfileCache, repository) - hasHeadRevision, err := repo.HasRevision(ctx, "HEAD") + headRevision, err := repo.ResolveRevision(ctx, "HEAD") if err != nil { - return nil, helper.ErrInternalf("cannot check HEAD revision: %v", err) - } - if !hasHeadRevision { - return &gitalypb.FindLicenseResponse{}, nil + if errors.Is(err, git.ErrReferenceNotFound) { + return &gitalypb.FindLicenseResponse{}, nil + } + return nil, helper.ErrInternalf("cannot find HEAD revision: %v", err) } - repoFiler := &gitFiler{ctx: ctx, repo: repo} + repoFiler := &gitFiler{ctx: ctx, repo: repo, revision: headRevision} detectedLicenses, err := licensedb.Detect(repoFiler) if err != nil { if errors.Is(err, licensedb.ErrNoLicenseFound) { @@ -155,13 +155,14 @@ type gitFiler struct { repo *localrepo.Repo foundLicense bool path string + revision git.ObjectID } 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("HEAD:%s", path)}, + 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()) } @@ -194,7 +195,7 @@ func (f *gitFiler) ReadDir(string) ([]filer.File, error) { git.Flag{Name: "--full-tree"}, git.Flag{Name: "-z"}, }, - Args: []string{"HEAD"}, + Args: []string{f.revision.String()}, }, git.WithStderr(&stderr)) if err != nil { return nil, err |