Skip to content

Commit 6d441de

Browse files
guillep2klunny
authored andcommitted
Backport: skip non-regular files (e.g. submodules) on repo indexing (#7717)
* Backport: skip non-regular files (e.g. submodules) on repo indexing * Include "executable" files in the index, as they are not necessarily binary
1 parent d15e49f commit 6d441de

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

models/repo_indexer.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,28 @@ func addDelete(filename string, repo *Repository, batch rupture.FlushingBatch) e
231231
return indexerUpdate.AddToFlushingBatch(batch)
232232
}
233233

234+
func isIndexable(entry *git.TreeEntry) bool {
235+
return entry.IsRegular() || entry.IsExecutable()
236+
}
237+
234238
// parseGitLsTreeOutput parses the output of a `git ls-tree -r --full-name` command
235239
func parseGitLsTreeOutput(stdout []byte) ([]fileUpdate, error) {
236240
entries, err := git.ParseTreeEntries(stdout)
237241
if err != nil {
238242
return nil, err
239243
}
244+
var idxCount = 0
240245
updates := make([]fileUpdate, len(entries))
241-
for i, entry := range entries {
242-
updates[i] = fileUpdate{
243-
Filename: entry.Name(),
244-
BlobSha: entry.ID.String(),
246+
for _, entry := range entries {
247+
if isIndexable(entry) {
248+
updates[idxCount] = fileUpdate{
249+
Filename: entry.Name(),
250+
BlobSha: entry.ID.String(),
251+
}
252+
idxCount++
245253
}
246254
}
247-
return updates, nil
255+
return updates[:idxCount], nil
248256
}
249257

250258
// genesisChanges get changes to add repo to the indexer for the first time

modules/git/tree_entry.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ func (te *TreeEntry) IsRegular() bool {
108108
return te.gogitTreeEntry.Mode == filemode.Regular
109109
}
110110

111+
// IsExecutable if the entry is an executable file (not necessarily binary)
112+
func (te *TreeEntry) IsExecutable() bool {
113+
return te.gogitTreeEntry.Mode == filemode.Executable
114+
}
115+
111116
// Blob returns the blob object the entry
112117
func (te *TreeEntry) Blob() *Blob {
113118
encodedObj, err := te.ptree.repo.gogitRepo.Storer.EncodedObject(plumbing.AnyObject, te.gogitTreeEntry.Hash)

0 commit comments

Comments
 (0)