From 8c42aea827f6021caa62704ff0df34e8a219a4fb Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Thu, 28 Aug 2014 23:45:26 +0100 Subject: [PATCH] Add #include directive to .stignore (fixes #424) Though breaks #502 in a way, as .stignore is not the only place where stuff gets defined anymore. Though it never was, as .stignore can be placed in each dir, but I think we should phase that out in favor of globbing which means that we can then have a single file, which means that we can have a UI for editing that. Alternative would be as suggested to include a .stglobalignore which is then synced as a normal file, but gets included by default. Then when the UI would have two editors, a local ignore, and a global ignore. --- scanner/walk.go | 12 ++++++++++-- scanner/walk_test.go | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/scanner/walk.go b/scanner/walk.go index 8cb189725..6008d22e8 100644 --- a/scanner/walk.go +++ b/scanner/walk.go @@ -113,10 +113,10 @@ func loadIgnoreFile(ignFile, base string) []*regexp.Regexp { return nil } defer fd.Close() - return parseIgnoreFile(fd, base) + return parseIgnoreFile(fd, base, filepath.Dir(ignFile)) } -func parseIgnoreFile(fd io.Reader, base string) []*regexp.Regexp { +func parseIgnoreFile(fd io.Reader, base, dir string) []*regexp.Regexp { var exps []*regexp.Regexp scanner := bufio.NewScanner(fd) for scanner.Scan() { @@ -148,6 +148,14 @@ func parseIgnoreFile(fd io.Reader, base string) []*regexp.Regexp { continue } exps = append(exps, exp) + } else if strings.HasPrefix(line, "#include ") { + includeFile := filepath.Join(dir, strings.Replace(line, "#include ", "", 1)) + if _, err := os.Stat(includeFile); os.IsNotExist(err) { + l.Infoln("Could not open ignore include file", includeFile) + } else { + includes := loadIgnoreFile(includeFile, base) + exps = append(exps, includes...) + } } else { // Path name or pattern, add it so it matches files both in // current directory and subdirs. diff --git a/scanner/walk_test.go b/scanner/walk_test.go index 943843b2a..a0ac451e0 100644 --- a/scanner/walk_test.go +++ b/scanner/walk_test.go @@ -128,20 +128,20 @@ func TestIgnore(t *testing.T) { */other/test **/deep `) - patterns := parseIgnoreFile(patStr, "") + patterns := parseIgnoreFile(patStr, "", "") patStr = bytes.NewBufferString(` bar z* q[abc]x `) - patterns = append(patterns, parseIgnoreFile(patStr, "foo")...) + patterns = append(patterns, parseIgnoreFile(patStr, "foo", "")...) patStr = bytes.NewBufferString(` quux .* `) - patterns = append(patterns, parseIgnoreFile(patStr, "foo/baz")...) + patterns = append(patterns, parseIgnoreFile(patStr, "foo/baz", "")...) var tests = []struct { f string