From 6d441de2bdddb137f6af9053fe20c74ab0c057ce Mon Sep 17 00:00:00 2001 From: guillep2k Date: Fri, 2 Aug 2019 11:40:15 -0300 Subject: [PATCH] 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 --- models/repo_indexer.go | 18 +++++++++++++----- modules/git/tree_entry.go | 5 +++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/models/repo_indexer.go b/models/repo_indexer.go index 140ec66c03..3a41e0525a 100644 --- a/models/repo_indexer.go +++ b/models/repo_indexer.go @@ -231,20 +231,28 @@ func addDelete(filename string, repo *Repository, batch rupture.FlushingBatch) e return indexerUpdate.AddToFlushingBatch(batch) } +func isIndexable(entry *git.TreeEntry) bool { + return entry.IsRegular() || entry.IsExecutable() +} + // parseGitLsTreeOutput parses the output of a `git ls-tree -r --full-name` command func parseGitLsTreeOutput(stdout []byte) ([]fileUpdate, error) { entries, err := git.ParseTreeEntries(stdout) if err != nil { return nil, err } + var idxCount = 0 updates := make([]fileUpdate, len(entries)) - for i, entry := range entries { - updates[i] = fileUpdate{ - Filename: entry.Name(), - BlobSha: entry.ID.String(), + for _, entry := range entries { + if isIndexable(entry) { + updates[idxCount] = fileUpdate{ + Filename: entry.Name(), + BlobSha: entry.ID.String(), + } + idxCount++ } } - return updates, nil + return updates[:idxCount], nil } // genesisChanges get changes to add repo to the indexer for the first time diff --git a/modules/git/tree_entry.go b/modules/git/tree_entry.go index 6019e34487..4e18cc8ead 100644 --- a/modules/git/tree_entry.go +++ b/modules/git/tree_entry.go @@ -108,6 +108,11 @@ func (te *TreeEntry) IsRegular() bool { return te.gogitTreeEntry.Mode == filemode.Regular } +// IsExecutable if the entry is an executable file (not necessarily binary) +func (te *TreeEntry) IsExecutable() bool { + return te.gogitTreeEntry.Mode == filemode.Executable +} + // Blob returns the blob object the entry func (te *TreeEntry) Blob() *Blob { encodedObj, err := te.ptree.repo.gogitRepo.Storer.EncodedObject(plumbing.AnyObject, te.gogitTreeEntry.Hash)