From c48c37ad09fb8ead9573677310868c7f21cdb35d Mon Sep 17 00:00:00 2001 From: Guillermo Prandi Date: Tue, 6 Aug 2019 02:51:42 -0300 Subject: [PATCH] Use REPO_EXTENSIONS_LIST_INCLUDE instead of REPO_EXTENSIONS_LIST_EXCLUDE and have a more flexible extension pattern --- .../doc/advanced/config-cheat-sheet.en-us.md | 4 ++-- models/repo_indexer.go | 2 +- modules/setting/indexer.go | 17 +++++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index affb90eef7..c12c05c43e 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -177,8 +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_EXTENSIONS`: **empty**: A comma separated list of file extensions to include/exclude from the index; a \`.' matches files with no extension. An empty list means include all files, disregarding `REPO_EXTENSIONS_LIST_EXCLUDE`. -- `REPO_EXTENSIONS_LIST_EXCLUDE`: **false**: If true, `REPO_INDEXER_EXTENSIONS` are the file extensions to exclude rather than include in the index. +- `REPO_INDEXER_EXTENSIONS`: **empty**: A comma separated list of file extensions to exclude from the index; a \`.' matches files with no extension. An empty list means do not exclude any files. +- `REPO_EXTENSIONS_LIST_INCLUDE`: **false**: If true, `REPO_INDEXER_EXTENSIONS` 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. diff --git a/models/repo_indexer.go b/models/repo_indexer.go index d54b9e397e..dd36cf9312 100644 --- a/models/repo_indexer.go +++ b/models/repo_indexer.go @@ -239,7 +239,7 @@ func isIndexable(entry *git.TreeEntry) bool { if cnt > 1 { ext = strings.ToLower(parts[cnt-1]) } - if setting.Indexer.FileExtensions[ext] == setting.Indexer.ExcludeExtensions { + if setting.Indexer.FileExtensions[ext] != setting.Indexer.IncludeExtensions { return false } } diff --git a/modules/setting/indexer.go b/modules/setting/indexer.go index ef3a45eabb..304eada607 100644 --- a/modules/setting/indexer.go +++ b/modules/setting/indexer.go @@ -31,7 +31,7 @@ var ( IssueQueueConnStr string IssueQueueBatchNumber int FileExtensions map[string]bool - ExcludeExtensions bool + IncludeExtensions bool }{ IssueType: "bleve", IssuePath: "indexers/issues.bleve", @@ -55,7 +55,7 @@ func newIndexerService() { Indexer.RepoPath = path.Join(AppWorkPath, Indexer.RepoPath) } Indexer.FileExtensions = extensionsFromString(sec.Key("REPO_INDEXER_EXTENSIONS").MustString("")) - Indexer.ExcludeExtensions = sec.Key("REPO_EXTENSIONS_LIST_EXCLUDE").MustBool(false) + Indexer.IncludeExtensions = sec.Key("REPO_EXTENSIONS_LIST_INCLUDE").MustBool(false) Indexer.UpdateQueueLength = sec.Key("UPDATE_BUFFER_LEN").MustInt(20) Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(1024 * 1024) @@ -69,10 +69,19 @@ func extensionsFromString(from string) map[string]bool { extmap := make(map[string]bool) for _, ext := range strings.Split(strings.ToLower(from), ",") { ext = strings.TrimSpace(ext) + // Accept *.txt, .txt and txt. Also use . to mean no ext + if strings.HasPrefix(ext, "*.") { + ext = ext[1:] + } if ext == "." { extmap[""] = true - } else if ext != "" && !strings.Contains(ext, ".") { - extmap[ext] = true + } else { + if strings.HasPrefix(ext, ".") { + ext = ext[1:] + } + if ext != "" { + extmap[ext] = true + } } } if len(extmap) == 0 {