Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a85393b
Restrict repository indexing by file extension
Aug 6, 2019
4353c71
Merge master into indexbyfileext
Aug 6, 2019
c48c37a
Use REPO_EXTENSIONS_LIST_INCLUDE instead of REPO_EXTENSIONS_LIST_EXCL…
Aug 6, 2019
c6d5a79
Corrected to pass lint gosimple
Aug 6, 2019
021014a
Merge master into indexbyfileext
Aug 7, 2019
72a650c
Add wildcard support to REPO_INDEXER_EXTENSIONS
Aug 7, 2019
1d7edb4
This reverts commit 72a650c8e42f4abf59d5df7cd5dc27b451494cc6.
Aug 7, 2019
7450aee
Add wildcard support to REPO_INDEXER_EXTENSIONS (no make vendor)
Aug 7, 2019
106faf3
Simplify isIndexable() for better clarity
guillep2k Aug 7, 2019
e48f041
Add gobwas/glob to vendors
guillep2k Aug 7, 2019
bf82bdb
Merge branch master into indexbyfileext
guillep2k Aug 7, 2019
d63a0fb
Merge branch 'master' of github.com:go-gitea/gitea into indexbyfileext
guillep2k Aug 7, 2019
49e260c
Merge master into indexbyfileext and resolve conflicts
guillep2k Aug 28, 2019
7c66a16
Merge branch 'master' into indexbyfileext
guillep2k Aug 28, 2019
f2342d6
Merge branch 'master' into indexbyfileext
guillep2k Aug 28, 2019
55a93a3
manually set appengine new release
guillep2k Aug 28, 2019
89773e9
Merge branch 'master' into indexbyfileext
guillep2k Sep 3, 2019
0eca697
Merge branch 'master' of github.com:go-gitea/gitea into indexbyfileext
guillep2k Sep 4, 2019
6bd0ac8
Implement better REPO_INDEXER_INCLUDE and REPO_INDEXER_EXCLUDE
guillep2k Sep 4, 2019
435a222
Merge branch 'master' of github.com:go-gitea/gitea into indexbyfileext
guillep2k Sep 4, 2019
4de7be9
Add unit and integration tests
guillep2k Sep 5, 2019
b79406a
Merge branch 'indexbyfileext' of github.com:guillep2k/gitea into inde…
guillep2k Sep 5, 2019
9afc70e
Merge branch 'master' of github.com:go-gitea/gitea into indexbyfileext
guillep2k Sep 6, 2019
d92ee99
Update app.ini.sample and reword config-cheat-sheet
guillep2k Sep 6, 2019
59fe641
Add doc page and correct app.ini.sample
guillep2k Sep 6, 2019
a1f675b
Some polish on the doc
guillep2k Sep 6, 2019
480a406
Simplify code as suggested by @lafriks
guillep2k Sep 6, 2019
e0fbcb7
Merge branch 'master' into indexbyfileext
guillep2k Sep 11, 2019
326f770
Merge branch 'master' into indexbyfileext
lafriks Sep 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.

- `REPO_INDEXER_ENABLED`: **false**: Enables code search (uses a lot of disk space, about 6 times more than the repository size).
- `REPO_INDEXER_PATH`: **indexers/repos.bleve**: Index file used for code search.
- `REPO_INDEXER_PATTERNS`: **empty**: A comma separated list of file name patterns (see https://github.com/gobwas/glob) to **exclude** from the index. An empty list means do not exclude any files. Use `**.txt` to match any files with .txt extension.
- `REPO_PATTERNS_INCLUDE`: **false**: If true, `REPO_INDEXER_PATTERNS` are the file extensions to **include** rather than exclude from the index.
- `UPDATE_BUFFER_LEN`: **20**: Buffer length of index request.
- `MAX_FILE_SIZE`: **1048576**: Maximum size in bytes of files to be indexed.

Expand Down
13 changes: 13 additions & 0 deletions models/repo_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,19 @@ func addDelete(filename string, repo *Repository, batch rupture.FlushingBatch) e
}

func isIndexable(entry *git.TreeEntry) bool {
if setting.Indexer.FilePatterns != nil {
var found bool
name := strings.ToLower(entry.Name())
for _, g := range setting.Indexer.FilePatterns {
if g.Match(name) {
found = true
break
}
}
if found != setting.Indexer.IncludePatterns {
return false
}
}
return entry.IsRegular() || entry.IsExecutable()
}

Expand Down
28 changes: 28 additions & 0 deletions modules/setting/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ package setting
import (
"path"
"path/filepath"
"strings"

"code.gitea.io/gitea/modules/log"

"github.com/gobwas/glob"
)

// enumerates all the indexer queue types
Expand All @@ -29,6 +34,8 @@ var (
IssueQueueDir string
IssueQueueConnStr string
IssueQueueBatchNumber int
FilePatterns []glob.Glob
IncludePatterns bool
}{
IssueType: "bleve",
IssuePath: "indexers/issues.bleve",
Expand All @@ -51,10 +58,31 @@ func newIndexerService() {
if !filepath.IsAbs(Indexer.RepoPath) {
Indexer.RepoPath = path.Join(AppWorkPath, Indexer.RepoPath)
}
Indexer.FilePatterns = extensionsFromString(sec.Key("REPO_INDEXER_PATTERNS").MustString(""))
Indexer.IncludePatterns = sec.Key("REPO_PATTERNS_INCLUDE").MustBool(false)

Indexer.UpdateQueueLength = sec.Key("UPDATE_BUFFER_LEN").MustInt(20)
Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(1024 * 1024)
Indexer.IssueQueueType = sec.Key("ISSUE_INDEXER_QUEUE_TYPE").MustString(LevelQueueType)
Indexer.IssueQueueDir = sec.Key("ISSUE_INDEXER_QUEUE_DIR").MustString(path.Join(AppDataPath, "indexers/issues.queue"))
Indexer.IssueQueueConnStr = sec.Key("ISSUE_INDEXER_QUEUE_CONN_STR").MustString(path.Join(AppDataPath, ""))
Indexer.IssueQueueBatchNumber = sec.Key("ISSUE_INDEXER_QUEUE_BATCH_NUMBER").MustInt(20)
}

func extensionsFromString(from string) []glob.Glob {
extarr := make([]glob.Glob, 0, 10)
for _, expr := range strings.Split(strings.ToLower(from), ",") {
expr = strings.TrimSpace(expr)
if expr != "" {
if g, err := glob.Compile(expr, '.', '/'); err != nil {
log.Trace("Index file extensions: '%s': bad pattern: %v", expr, err)
} else {
extarr = append(extarr, g)
}
}
}
if len(extarr) == 0 {
return nil
}
return extarr
}