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:
authorToon Claes <toon@gitlab.com>2022-11-08 21:01:41 +0300
committerToon Claes <toon@gitlab.com>2022-11-09 11:59:28 +0300
commit72961e47ce326dc8dc10849b454b82a8e3363904 (patch)
treed78b90eb7a3e4b1349763d622232bb68d0885ce3
parent27050e90be014318ae19734d08acf3ad53b46adf (diff)
repository: Ignore license in subdirectory
The Go implementation was using git-ls-tree(1) with --full-tree to get the whole tree of blobs at once. But this data isn't correctly passed on to go-license-detector, so it never detected a license in a subdirectory. Also, the Ruby implementation does not detect licenses in subdirectories. With this change we stop getting the whole tree of a repo, this stops wasting resources on data that wasn't used.
-rw-r--r--internal/gitaly/service/repository/license.go5
-rw-r--r--internal/gitaly/service/repository/license_test.go20
2 files changed, 20 insertions, 5 deletions
diff --git a/internal/gitaly/service/repository/license.go b/internal/gitaly/service/repository/license.go
index 29e2e6a9e..656a103c8 100644
--- a/internal/gitaly/service/repository/license.go
+++ b/internal/gitaly/service/repository/license.go
@@ -186,13 +186,10 @@ func (f *gitFiler) ReadFile(path string) ([]byte, error) {
}
func (f *gitFiler) ReadDir(string) ([]filer.File, error) {
- // We're doing a recursive listing returning all files at once such that we do not have to
- // call git-ls-tree(1) multiple times.
var stderr bytes.Buffer
cmd, err := f.repo.Exec(f.ctx, git.SubCmd{
Name: "ls-tree",
Flags: []git.Option{
- git.Flag{Name: "--full-tree"},
git.Flag{Name: "-z"},
},
Args: []string{f.revision.String()},
@@ -213,8 +210,6 @@ func (f *gitFiler) ReadDir(string) ([]filer.File, error) {
return nil, err
}
- // Given that we're doing a recursive listing, we skip over all types which aren't
- // blobs.
if entry.Type != lstree.Blob {
continue
}
diff --git a/internal/gitaly/service/repository/license_test.go b/internal/gitaly/service/repository/license_test.go
index ac23d1aed..904e0698d 100644
--- a/internal/gitaly/service/repository/license_test.go
+++ b/internal/gitaly/service/repository/license_test.go
@@ -182,6 +182,26 @@ func testSuccessfulFindLicenseRequest(t *testing.T, cfg config.Cfg, client gital
LicenseNickname: "GNU GPLv2",
},
},
+ {
+ desc: "license in subdir",
+ setup: func(t *testing.T, repoPath string) {
+ subTree := gittest.WriteTree(t, cfg, repoPath,
+ []gittest.TreeEntry{{
+ Mode: "100644",
+ Path: "LICENSE",
+ Content: mitLicense,
+ }})
+
+ gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main"),
+ gittest.WithTreeEntries(
+ gittest.TreeEntry{
+ Mode: "040000",
+ Path: "legal",
+ OID: subTree,
+ }))
+ },
+ expectedLicenseRuby: &gitalypb.FindLicenseResponse{},
+ },
} {
t.Run(tc.desc, func(t *testing.T) {
repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{