1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-09-16 01:08:15 -04:00

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
This commit is contained in:
guillep2k 2019-08-02 11:40:15 -03:00 committed by Lunny Xiao
parent d15e49f7ff
commit 6d441de2bd
2 changed files with 18 additions and 5 deletions

View File

@ -231,20 +231,28 @@ func addDelete(filename string, repo *Repository, batch rupture.FlushingBatch) e
return indexerUpdate.AddToFlushingBatch(batch) 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 // parseGitLsTreeOutput parses the output of a `git ls-tree -r --full-name` command
func parseGitLsTreeOutput(stdout []byte) ([]fileUpdate, error) { func parseGitLsTreeOutput(stdout []byte) ([]fileUpdate, error) {
entries, err := git.ParseTreeEntries(stdout) entries, err := git.ParseTreeEntries(stdout)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var idxCount = 0
updates := make([]fileUpdate, len(entries)) updates := make([]fileUpdate, len(entries))
for i, entry := range entries { for _, entry := range entries {
updates[i] = fileUpdate{ if isIndexable(entry) {
Filename: entry.Name(), updates[idxCount] = fileUpdate{
BlobSha: entry.ID.String(), 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 // genesisChanges get changes to add repo to the indexer for the first time

View File

@ -108,6 +108,11 @@ func (te *TreeEntry) IsRegular() bool {
return te.gogitTreeEntry.Mode == filemode.Regular 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 // Blob returns the blob object the entry
func (te *TreeEntry) Blob() *Blob { func (te *TreeEntry) Blob() *Blob {
encodedObj, err := te.ptree.repo.gogitRepo.Storer.EncodedObject(plumbing.AnyObject, te.gogitTreeEntry.Hash) encodedObj, err := te.ptree.repo.gogitRepo.Storer.EncodedObject(plumbing.AnyObject, te.gogitTreeEntry.Hash)