From 2163a57b54852703d9385472b52979a14b7923f5 Mon Sep 17 00:00:00 2001 From: Manuel Carmona Date: Mon, 7 May 2018 16:04:07 +0200 Subject: [PATCH] Update enry dependency to v1.6.4 Signed-off-by: Manuel Carmona --- Gopkg.lock | 6 +- Gopkg.toml | 2 +- vendor/gopkg.in/src-d/enry.v1/.travis.yml | 16 +- vendor/gopkg.in/src-d/enry.v1/MAINTAINERS | 2 +- vendor/gopkg.in/src-d/enry.v1/Makefile | 10 +- vendor/gopkg.in/src-d/enry.v1/README.md | 10 +- .../gopkg.in/src-d/enry.v1/cli/enry/main.go | 220 --------- .../gopkg.in/src-d/enry.v1/cmd/enry/main.go | 374 ++++++++++++++ .../src-d/enry.v1/cmd/enry/main_test.go | 38 ++ vendor/gopkg.in/src-d/enry.v1/data/alias.go | 7 +- vendor/gopkg.in/src-d/enry.v1/data/commit.go | 7 +- vendor/gopkg.in/src-d/enry.v1/data/content.go | 7 +- .../src-d/enry.v1/data/documentation.go | 7 +- .../gopkg.in/src-d/enry.v1/data/extension.go | 7 +- .../gopkg.in/src-d/enry.v1/data/filename.go | 7 +- .../src-d/enry.v1/data/frequencies.go | 7 +- .../src-d/enry.v1/data/interpreter.go | 7 +- .../gopkg.in/src-d/enry.v1/data/mimeType.go | 7 +- vendor/gopkg.in/src-d/enry.v1/data/type.go | 7 +- vendor/gopkg.in/src-d/enry.v1/data/vendor.go | 7 +- vendor/gopkg.in/src-d/enry.v1/enry.go | 3 + vendor/gopkg.in/src-d/enry.v1/generate.go | 3 - .../code-generator/assets/alias.go.tmpl | 4 - .../code-generator/assets/commit.go.tmpl | 6 +- .../code-generator/assets/content.go.tmpl | 4 - .../assets/documentation.go.tmpl | 4 - .../code-generator/assets/extension.go.tmpl | 4 - .../code-generator/assets/filename.go.tmpl | 4 - .../code-generator/assets/frequencies.go.tmpl | 4 - .../code-generator/assets/header.go.tmpl | 3 + .../code-generator/assets/interpreter.go.tmpl | 4 - .../code-generator/assets/mimeType.go.tmpl | 4 - .../code-generator/assets/type.go.tmpl | 4 - .../code-generator/assets/vendor.go.tmpl | 4 - .../code-generator/generator/aliases.go | 15 +- .../code-generator/generator/documentation.go | 15 +- .../code-generator/generator/extensions.go | 9 +- .../code-generator/generator/filenames.go | 9 +- .../code-generator/generator/generator.go | 43 +- .../generator/generator_test.go | 55 ++- .../code-generator/generator/heuristics.go | 9 +- .../code-generator/generator/interpreters.go | 9 +- .../generator/linguist-commit.go | 5 +- .../code-generator/generator/mimeType.go | 15 +- .../code-generator/generator/samplesfreq.go | 9 +- .../generator/test_files/alias.gold | 7 +- .../generator/test_files/commit.gold | 7 +- .../generator/test_files/content.gold | 7 +- .../generator/test_files/documentation.gold | 7 +- .../generator/test_files/extension.gold | 7 +- .../generator/test_files/filename.gold | 7 +- .../generator/test_files/frequencies.gold | 7 +- .../generator/test_files/interpreter.gold | 7 +- .../generator/test_files/mimeType.gold | 7 +- .../generator/test_files/type.gold | 7 +- .../generator/test_files/vendor.gold | 7 +- .../code-generator/generator/types.go | 15 +- .../code-generator/generator/vendor.go | 15 +- .../enry.v1/internal/code-generator/main.go | 22 +- .../enry.v1/internal/tokenizer/tokenize.go | 10 +- vendor/gopkg.in/src-d/enry.v1/type.go | 461 ------------------ 61 files changed, 612 insertions(+), 991 deletions(-) delete mode 100644 vendor/gopkg.in/src-d/enry.v1/cli/enry/main.go create mode 100644 vendor/gopkg.in/src-d/enry.v1/cmd/enry/main.go create mode 100644 vendor/gopkg.in/src-d/enry.v1/cmd/enry/main_test.go create mode 100644 vendor/gopkg.in/src-d/enry.v1/enry.go delete mode 100644 vendor/gopkg.in/src-d/enry.v1/generate.go create mode 100644 vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/header.go.tmpl delete mode 100644 vendor/gopkg.in/src-d/enry.v1/type.go diff --git a/Gopkg.lock b/Gopkg.lock index 0c9dde585..0a894ff4f 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -375,8 +375,8 @@ "data", "internal/tokenizer" ] - revision = "0db3b4b5536e6dc4d9109d42897c00a5d92af0a7" - version = "v1.6.3" + revision = "6712d4219fb747194f38d0fc72121ca0a46ebcea" + version = "v1.6.4" [[projects]] name = "gopkg.in/src-d/go-billy-siva.v4" @@ -518,6 +518,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "3f2bccbcccd3b8b671ef070ba165c4b9d002cd94f9da3c7e58a82a8d55cf2e70" + inputs-digest = "3ca0b7c42f177a7b65889819a720c370c0043d3de424910820df299f24b6a74e" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index bbee62f99..9a00f5633 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -44,7 +44,7 @@ [[constraint]] name = "gopkg.in/src-d/enry.v1" - version = "1.6.3" + version = "1.6.4" [[constraint]] name = "gopkg.in/bblfsh/client-go.v2" diff --git a/vendor/gopkg.in/src-d/enry.v1/.travis.yml b/vendor/gopkg.in/src-d/enry.v1/.travis.yml index 781e8b3fe..b554374be 100644 --- a/vendor/gopkg.in/src-d/enry.v1/.travis.yml +++ b/vendor/gopkg.in/src-d/enry.v1/.travis.yml @@ -15,15 +15,16 @@ matrix: fast_finish: true env: - - ONIGUMURA=0 - - ONIGUMURA=1 + - ONIGURUMA=0 + - ONIGURUMA=1 install: + - go version - rm -rf $GOPATH/src/gopkg.in/src-d - mkdir -p $GOPATH/src/gopkg.in/src-d - ln -s $PWD $GOPATH/src/gopkg.in/src-d/enry.v1 - cd $GOPATH/src/gopkg.in/src-d/enry.v1 - - if [ "$ONIGUMURA" == "1" ]; then make onigumura; fi + - if [ "$ONIGURUMA" == "1" ]; then make oniguruma; fi - go get -v -t ./... script: @@ -47,14 +48,14 @@ deploy: jobs: env: - - ONIGUMURA=0 + - ONIGURUMA=0 include: - stage: test language: scala jdk: oraclejdk8 install: - - GIMME_OUTPUT=$(gimme 1.8 | tee -a $HOME/.bashrc) && eval "$GIMME_OUTPUT" + - GIMME_OUTPUT=$(gimme 1.9 | tee -a $HOME/.bashrc) && eval "$GIMME_OUTPUT" - export GOPATH=$HOME/gopath - mkdir -p $GOPATH/src/gopkg.in/src-d/enry.v1 - rsync -az ${TRAVIS_BUILD_DIR}/ $GOPATH/src/gopkg.in/src-d/enry.v1 @@ -80,7 +81,7 @@ jobs: on: tags: true - - stage: Build macOS shared + - stage: Build MacOS shared env: - OSXCROSS_PACKAGE="osxcross_3034f7149716d815bc473d0a7b35d17e4cf175aa.tar.gz" @@ -121,6 +122,9 @@ jobs: language: scala jdk: oraclejdk8 + install: + - go version # override install + before_script: - if [[ -z "$TRAVIS_TAG" ]]; then echo "Skipping this build for non-tag builds."; exit 0; fi - cd java diff --git a/vendor/gopkg.in/src-d/enry.v1/MAINTAINERS b/vendor/gopkg.in/src-d/enry.v1/MAINTAINERS index 94fa46981..441d06cac 100644 --- a/vendor/gopkg.in/src-d/enry.v1/MAINTAINERS +++ b/vendor/gopkg.in/src-d/enry.v1/MAINTAINERS @@ -1 +1 @@ -Alfredo Beaumont (@abeaumont) +Denys Smirnov (@dennwc) diff --git a/vendor/gopkg.in/src-d/enry.v1/Makefile b/vendor/gopkg.in/src-d/enry.v1/Makefile index 4d6eeb8df..3f94e8c6b 100644 --- a/vendor/gopkg.in/src-d/enry.v1/Makefile +++ b/vendor/gopkg.in/src-d/enry.v1/Makefile @@ -1,6 +1,6 @@ # Package configuration PROJECT = enry -COMMANDS = cli/enry +COMMANDS = cmd/enry # Including ci Makefile MAKEFILE = Makefile.main @@ -42,7 +42,7 @@ NATIVE_LIB=./shared/enry.go RUBEX_PATCHED := internal/code-generator/generator/heuristics.go internal/tokenizer/tokenize.go common.go RUBEX_ORIG := $(RUBEX_PATCHED:=.orig) -.PHONY: revert-onigumura +.PHONY: revert-oniguruma $(LINGUIST_PATH): git clone https://github.com/github/linguist.git $@ @@ -73,13 +73,13 @@ $(RUBEX_ORIG): %.orig : % sed -i.orig -e 's/"regexp"/regexp "github.com\/moovweb\/rubex"/g' $< @touch $@ -onigumura: $(RUBEX_ORIG) +oniguruma: $(RUBEX_ORIG) -revert-onigumura: +revert-oniguruma: @for file in $(RUBEX_PATCHED); do if [ -e "$$file.orig" ]; then mv "$$file.orig" "$$file" && echo mv "$$file.orig" "$$file"; fi; done build-cli: - go build -o enry -ldflags "$(LOCAL_LDFLAGS)" cli/enry/main.go + go build -o enry -ldflags "$(LOCAL_LDFLAGS)" cmd/enry/main.go linux-shared: $(LINUX_SHARED_LIB) diff --git a/vendor/gopkg.in/src-d/enry.v1/README.md b/vendor/gopkg.in/src-d/enry.v1/README.md index da6b70dbd..0da8228a3 100644 --- a/vendor/gopkg.in/src-d/enry.v1/README.md +++ b/vendor/gopkg.in/src-d/enry.v1/README.md @@ -21,14 +21,14 @@ this will generate a binary in the project's root directory called `enry`. You c ### Faster regexp engine (optional) -[Onigumura](https://github.com/kkos/oniguruma) is CRuby's regular expression engine. +[Oniguruma](https://github.com/kkos/oniguruma) is CRuby's regular expression engine. It is very fast and performs better than the one built into Go runtime. *enry* supports swapping between those two engines thanks to [rubex](https://github.com/moovweb/rubex) project. -The typical overall speedup from using Onigumura is 1.5-2x. However, it requires CGo and the external shared library. +The typical overall speedup from using Oniguruma is 1.5-2x. However, it requires CGo and the external shared library. On macOS with brew, it is ``` -brew install onigumura +brew install oniguruma ``` On Ubuntu, it is @@ -37,10 +37,10 @@ On Ubuntu, it is sudo apt install libonig-dev ``` -To build enry with Onigumura regexps, patch the imports with +To build enry with Oniguruma regexps, patch the imports with ``` -make onigumura +make oniguruma ``` and then rebuild the project. diff --git a/vendor/gopkg.in/src-d/enry.v1/cli/enry/main.go b/vendor/gopkg.in/src-d/enry.v1/cli/enry/main.go deleted file mode 100644 index 177b9a02e..000000000 --- a/vendor/gopkg.in/src-d/enry.v1/cli/enry/main.go +++ /dev/null @@ -1,220 +0,0 @@ -package main - -import ( - "bytes" - "encoding/json" - "flag" - "fmt" - "io/ioutil" - "log" - "os" - "path/filepath" - "sort" - "strings" - - "gopkg.in/src-d/enry.v1" - "gopkg.in/src-d/enry.v1/data" -) - -var ( - version = "undefined" - build = "undefined" - commit = "undefined" -) - -func main() { - flag.Usage = usage - breakdownFlag := flag.Bool("breakdown", false, "") - jsonFlag := flag.Bool("json", false, "") - showVersion := flag.Bool("version", false, "Show the enry version information") - flag.Parse() - - if *showVersion { - fmt.Println(version) - return - } - - root, err := filepath.Abs(flag.Arg(0)) - if err != nil { - log.Fatal(err) - } - - fileInfo, err := os.Stat(root) - if err != nil { - log.Fatal(err) - } - - if fileInfo.Mode().IsRegular() { - printFileAnalysis(root) - return - } - - out := make(map[string][]string, 0) - err = filepath.Walk(root, func(path string, f os.FileInfo, err error) error { - if err != nil { - log.Println(err) - return filepath.SkipDir - } - - if !f.Mode().IsDir() && !f.Mode().IsRegular() { - return nil - } - - relativePath, err := filepath.Rel(root, path) - if err != nil { - log.Println(err) - return nil - } - - if relativePath == "." { - return nil - } - - if f.IsDir() { - relativePath = relativePath + "/" - } - - if enry.IsVendor(relativePath) || enry.IsDotFile(relativePath) || - enry.IsDocumentation(relativePath) || enry.IsConfiguration(relativePath) { - if f.IsDir() { - return filepath.SkipDir - } - - return nil - } - - if f.IsDir() { - return nil - } - - language, ok := enry.GetLanguageByExtension(path) - if !ok { - if language, ok = enry.GetLanguageByFilename(path); !ok { - content, err := ioutil.ReadFile(path) - if err != nil { - log.Println(err) - return nil - } - - language = enry.GetLanguage(filepath.Base(path), content) - if language == enry.OtherLanguage { - return nil - } - } - } - - out[language] = append(out[language], relativePath) - return nil - }) - - if err != nil { - log.Fatal(err) - } - - var buff bytes.Buffer - switch { - case *jsonFlag && !*breakdownFlag: - printJson(out, &buff) - case *jsonFlag && *breakdownFlag: - printBreakDown(out, &buff) - case *breakdownFlag: - printPercents(out, &buff) - buff.WriteByte('\n') - printBreakDown(out, &buff) - default: - printPercents(out, &buff) - } - - fmt.Print(buff.String()) -} - -func usage() { - fmt.Fprintf( - os.Stderr, - ` %[1]s %[2]s build: %[3]s commit: %[4]s, based on linguist commit: %[5]s - %[1]s, A simple (and faster) implementation of github/linguist - usage: %[1]s - %[1]s [-json] [-breakdown] - %[1]s [-json] [-breakdown] - %[1]s [-version] -`, - os.Args[0], version, build, commit, data.LinguistCommit[:7], - ) -} - -func printBreakDown(out map[string][]string, buff *bytes.Buffer) { - for name, language := range out { - writeStringLn(name, buff) - for _, file := range language { - writeStringLn(file, buff) - } - - writeStringLn("", buff) - } -} - -func printJson(out map[string][]string, buff *bytes.Buffer) { - data, _ := json.Marshal(out) - buff.Write(data) - buff.WriteByte('\n') -} - -func printPercents(out map[string][]string, buff *bytes.Buffer) { - var fileCountList enry.FileCountList - total := 0 - for name, language := range out { - fc := enry.FileCount{Name: name, Count: len(language)} - fileCountList = append(fileCountList, fc) - total += len(language) - } - // Sort the fileCountList in descending order of their count value. - sort.Sort(sort.Reverse(fileCountList)) - - for _, fc := range fileCountList { - percent := float32(fc.Count) / float32(total) * 100 - buff.WriteString(fmt.Sprintf("%.2f%% %s\n", percent, fc.Name)) - } -} - -func printFileAnalysis(file string) { - content, err := ioutil.ReadFile(file) - if err != nil { - fmt.Println(err) - } - - totalLines, nonBlank := getLines(file, string(content)) - fileType := getFileType(file, content) - language := enry.GetLanguage(file, content) - mimeType := enry.GetMimeType(file, language) - - fmt.Printf( - `%s: %d lines (%d sloc) - type: %s - mime_type: %s - language: %s -`, - filepath.Base(file), totalLines, nonBlank, fileType, mimeType, language, - ) -} - -func getLines(file string, content string) (int, int) { - totalLines := strings.Count(content, "\n") - nonBlank := totalLines - strings.Count(content, "\n\n") - return totalLines, nonBlank -} - -func getFileType(file string, content []byte) string { - switch { - case enry.IsImage(file): - return "Image" - case enry.IsBinary(content): - return "Binary" - default: - return "Text" - } -} - -func writeStringLn(s string, buff *bytes.Buffer) { - buff.WriteString(s) - buff.WriteByte('\n') -} diff --git a/vendor/gopkg.in/src-d/enry.v1/cmd/enry/main.go b/vendor/gopkg.in/src-d/enry.v1/cmd/enry/main.go new file mode 100644 index 000000000..6505a9355 --- /dev/null +++ b/vendor/gopkg.in/src-d/enry.v1/cmd/enry/main.go @@ -0,0 +1,374 @@ +package main + +import ( + "bufio" + "bytes" + "encoding/json" + "flag" + "fmt" + "io" + "io/ioutil" + "log" + "os" + "path/filepath" + "sort" + "strings" + + "gopkg.in/src-d/enry.v1" + "gopkg.in/src-d/enry.v1/data" +) + +var ( + version = "undefined" + build = "undefined" + commit = "undefined" +) + +func main() { + flag.Usage = usage + breakdownFlag := flag.Bool("breakdown", false, "") + jsonFlag := flag.Bool("json", false, "") + showVersion := flag.Bool("version", false, "Show the enry version information") + onlyProg := flag.Bool("prog", false, "Only show programming file types in output") + countMode := flag.String("mode", "file", "the method used to count file size. Available options are: file, line and byte") + limitKB := flag.Int64("limit", 16*1024, "Analyse first N KB of the file (-1 means no limit)") + flag.Parse() + limit := (*limitKB) * 1024 + + if *showVersion { + fmt.Println(version) + return + } + + root, err := filepath.Abs(flag.Arg(0)) + if err != nil { + log.Fatal(err) + } + + fileInfo, err := os.Stat(root) + if err != nil { + log.Fatal(err) + } + + if fileInfo.Mode().IsRegular() { + err = printFileAnalysis(root, limit) + if err != nil { + fmt.Println(err) + } + return + } + + out := make(map[string][]string, 0) + err = filepath.Walk(root, func(path string, f os.FileInfo, err error) error { + if err != nil { + log.Println(err) + return filepath.SkipDir + } + + if !f.Mode().IsDir() && !f.Mode().IsRegular() { + return nil + } + + relativePath, err := filepath.Rel(root, path) + if err != nil { + log.Println(err) + return nil + } + + if relativePath == "." { + return nil + } + + if f.IsDir() { + relativePath = relativePath + "/" + } + + if enry.IsVendor(relativePath) || enry.IsDotFile(relativePath) || + enry.IsDocumentation(relativePath) || enry.IsConfiguration(relativePath) { + if f.IsDir() { + return filepath.SkipDir + } + + return nil + } + + if f.IsDir() { + return nil + } + + language, ok := enry.GetLanguageByExtension(path) + if !ok { + if language, ok = enry.GetLanguageByFilename(path); !ok { + content, err := readFile(path, limit) + if err != nil { + log.Println(err) + return nil + } + + language = enry.GetLanguage(filepath.Base(path), content) + if language == enry.OtherLanguage { + return nil + } + } + } + + // If we are displaying only prog. and language is not prog. skip it. + if *onlyProg && enry.GetLanguageType(language) != enry.Programming { + return nil + } + + out[language] = append(out[language], relativePath) + return nil + }) + + if err != nil { + log.Fatal(err) + } + + var buf bytes.Buffer + switch { + case *jsonFlag && !*breakdownFlag: + printJson(out, &buf) + case *jsonFlag && *breakdownFlag: + printBreakDown(out, &buf) + case *breakdownFlag: + printPercents(out, &buf, *countMode) + buf.WriteByte('\n') + printBreakDown(out, &buf) + default: + printPercents(out, &buf, *countMode) + } + + fmt.Print(buf.String()) +} + +func usage() { + fmt.Fprintf( + os.Stderr, + ` %[1]s %[2]s build: %[3]s commit: %[4]s, based on linguist commit: %[5]s + %[1]s, A simple (and faster) implementation of github/linguist + usage: %[1]s [-mode=(file|line|byte)] [-prog] + %[1]s [-mode=(file|line|byte)] [-prog] [-json] [-breakdown] + %[1]s [-mode=(file|line|byte)] [-prog] [-json] [-breakdown] + %[1]s [-version] +`, + os.Args[0], version, build, commit, data.LinguistCommit[:7], + ) +} + +func printBreakDown(out map[string][]string, buff *bytes.Buffer) { + for name, language := range out { + writeStringLn(name, buff) + for _, file := range language { + writeStringLn(file, buff) + } + + writeStringLn("", buff) + } +} + +func printJson(out map[string][]string, buf *bytes.Buffer) { + json.NewEncoder(buf).Encode(out) +} + +// filelistError represents a failed operation that took place across multiple files. +type filelistError []string + +func (e filelistError) Error() string { + return fmt.Sprintf("Could not process the following files:\n%s", strings.Join(e, "\n")) +} + +func printPercents(fSummary map[string][]string, buff *bytes.Buffer, mode string) { + // Select the way we quantify 'amount' of code. + var reducer func([]string) (float64, filelistError) + switch mode { + case "file": + reducer = fileCountValues + case "line": + reducer = lineCountValues + case "byte": + reducer = byteCountValues + default: + reducer = fileCountValues + } + + // Reduce the list of files to a quantity of file type. + var ( + total float64 + keys []string + unreadableFiles filelistError + fileValues = make(map[string]float64) + ) + for fType, files := range fSummary { + val, err := reducer(files) + if err != nil { + unreadableFiles = append(unreadableFiles, err...) + } + fileValues[fType] = val + keys = append(keys, fType) + total += val + } + + // Slice the keys by their quantity (file count, line count, byte size, etc.). + sort.Slice(keys, func(i, j int) bool { + return fileValues[keys[i]] > fileValues[keys[j]] + }) + + // Calculate and write percentages of each file type. + for _, fType := range keys { + val := fileValues[fType] + percent := val / total * 100.0 + buff.WriteString(fmt.Sprintf("%.2f%%\t%s\n", percent, fType)) + if unreadableFiles != nil { + buff.WriteString(fmt.Sprintf("\n%s", unreadableFiles.Error())) + } + } +} + +func fileCountValues(files []string) (float64, filelistError) { + return float64(len(files)), nil +} + +func lineCountValues(files []string) (float64, filelistError) { + var filesErr filelistError + var t float64 + for _, fName := range files { + l, _ := getLines(fName, nil) + t += float64(l) + } + return t, filesErr +} + +func byteCountValues(files []string) (float64, filelistError) { + var filesErr filelistError + var t float64 + for _, fName := range files { + f, err := os.Open(fName) + if err != nil { + filesErr = append(filesErr, fName) + continue + } + fi, err := f.Stat() + f.Close() + if err != nil { + filesErr = append(filesErr, fName) + continue + } + t += float64(fi.Size()) + } + return t, filesErr +} + +func printFileAnalysis(file string, limit int64) error { + data, err := readFile(file, limit) + if err != nil { + return err + } + + isSample := limit > 0 && len(data) == int(limit) + + full := data + if isSample { + // communicate to getLines that we don't have full contents + full = nil + } + + totalLines, nonBlank := getLines(file, full) + + // functions below can work on a sample + fileType := getFileType(file, data) + language := enry.GetLanguage(file, data) + mimeType := enry.GetMimeType(file, language) + + fmt.Printf( + `%s: %d lines (%d sloc) + type: %s + mime_type: %s + language: %s +`, + filepath.Base(file), totalLines, nonBlank, fileType, mimeType, language, + ) + return nil +} + +func readFile(path string, limit int64) ([]byte, error) { + if limit <= 0 { + return ioutil.ReadFile(path) + } + f, err := os.Open(path) + if err != nil { + return nil, err + } + defer f.Close() + st, err := f.Stat() + if err != nil { + return nil, err + } + size := st.Size() + if limit > 0 && size > limit { + size = limit + } + buf := bytes.NewBuffer(nil) + buf.Grow(int(size)) + _, err = io.Copy(buf, io.LimitReader(f, limit)) + return buf.Bytes(), err +} + +func getLines(file string, content []byte) (total, blank int) { + var r io.Reader + if content != nil { + r = bytes.NewReader(content) + } else { + // file not loaded to memory - stream it + f, err := os.Open(file) + if err != nil { + fmt.Println(err) + return + } + defer f.Close() + r = f + } + br := bufio.NewReader(r) + lastBlank := true + empty := true + for { + data, prefix, err := br.ReadLine() + if err == io.EOF { + break + } else if err != nil { + fmt.Println(err) + break + } + if prefix { + continue + } + empty = false + total++ + lastBlank = len(data) == 0 + if lastBlank { + blank++ + } + } + if !empty && lastBlank { + total++ + blank++ + } + nonBlank := total - blank + return total, nonBlank +} + +func getFileType(file string, content []byte) string { + switch { + case enry.IsImage(file): + return "Image" + case enry.IsBinary(content): + return "Binary" + default: + return "Text" + } +} + +func writeStringLn(s string, buff *bytes.Buffer) { + buff.WriteString(s) + buff.WriteByte('\n') +} diff --git a/vendor/gopkg.in/src-d/enry.v1/cmd/enry/main_test.go b/vendor/gopkg.in/src-d/enry.v1/cmd/enry/main_test.go new file mode 100644 index 000000000..9f2845d1f --- /dev/null +++ b/vendor/gopkg.in/src-d/enry.v1/cmd/enry/main_test.go @@ -0,0 +1,38 @@ +package main + +import ( + "testing" +) + +func TestGetLines(t *testing.T) { + tests := []struct { + content string + wantTotal int + wantNonBlank int + }{ + // 0 + {content: "This is one line", wantTotal: 1, wantNonBlank: 1}, + // 1 Test no content + {content: "", wantTotal: 0, wantNonBlank: 0}, + // 2 A single blank line + {content: "One blank line\n\nTwo nonblank lines", wantTotal: 3, wantNonBlank: 2}, + // 3 Testing multiple blank lines in a row + {content: "\n\n", wantTotal: 3, wantNonBlank: 0}, + // 4 ' + {content: "\n\n\n\n", wantTotal: 5, wantNonBlank: 0}, + // 5 Multiple blank lines content on ends + {content: "content\n\n\n\ncontent", wantTotal: 5, wantNonBlank: 2}, + // 6 Content with blank lines on ends + {content: "\n\n\ncontent\n\n\n", wantTotal: 7, wantNonBlank: 1}, + } + + for i, test := range tests { + t.Run("", func(t *testing.T) { + gotTotal, gotNonBlank := getLines("", []byte(test.content)) + if gotTotal != test.wantTotal || gotNonBlank != test.wantNonBlank { + t.Errorf("wrong line counts obtained for test case #%d:\n %7s, %7s\nGOT: %7d, %7d\nWANT: %7d, %7d\n", i, "TOTAL", "NON_BLANK", + gotTotal, gotNonBlank, test.wantTotal, test.wantNonBlank) + } + }) + } +} diff --git a/vendor/gopkg.in/src-d/enry.v1/data/alias.go b/vendor/gopkg.in/src-d/enry.v1/data/alias.go index c29707273..751c66554 100644 --- a/vendor/gopkg.in/src-d/enry.v1/data/alias.go +++ b/vendor/gopkg.in/src-d/enry.v1/data/alias.go @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: 4cd558c37482e8d2c535d8107f2d11b49afbc5b5 +package data + // LanguagesByAlias keeps alias for different languages and use the name of the languages as an alias too. // All the keys (alias or not) are written in lower case and the whitespaces has been replaced by underscores. var LanguagesByAlias = map[string]string{ diff --git a/vendor/gopkg.in/src-d/enry.v1/data/commit.go b/vendor/gopkg.in/src-d/enry.v1/data/commit.go index 79fd398af..fc59231e2 100644 --- a/vendor/gopkg.in/src-d/enry.v1/data/commit.go +++ b/vendor/gopkg.in/src-d/enry.v1/data/commit.go @@ -1,8 +1,7 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: 4cd558c37482e8d2c535d8107f2d11b49afbc5b5 +package data + // linguist's commit from which files were generated. var LinguistCommit = "4cd558c37482e8d2c535d8107f2d11b49afbc5b5" diff --git a/vendor/gopkg.in/src-d/enry.v1/data/content.go b/vendor/gopkg.in/src-d/enry.v1/data/content.go index 42c7ab3e5..7a4b75e9a 100644 --- a/vendor/gopkg.in/src-d/enry.v1/data/content.go +++ b/vendor/gopkg.in/src-d/enry.v1/data/content.go @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: 4cd558c37482e8d2c535d8107f2d11b49afbc5b5 +package data + import "gopkg.in/toqueteos/substring.v1" type languageMatcher func([]byte) []string diff --git a/vendor/gopkg.in/src-d/enry.v1/data/documentation.go b/vendor/gopkg.in/src-d/enry.v1/data/documentation.go index 999e8cc1b..817b00dfe 100644 --- a/vendor/gopkg.in/src-d/enry.v1/data/documentation.go +++ b/vendor/gopkg.in/src-d/enry.v1/data/documentation.go @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: 4cd558c37482e8d2c535d8107f2d11b49afbc5b5 +package data + import "gopkg.in/toqueteos/substring.v1" var DocumentationMatchers = substring.Or( diff --git a/vendor/gopkg.in/src-d/enry.v1/data/extension.go b/vendor/gopkg.in/src-d/enry.v1/data/extension.go index d6bcf1a73..c541ec094 100644 --- a/vendor/gopkg.in/src-d/enry.v1/data/extension.go +++ b/vendor/gopkg.in/src-d/enry.v1/data/extension.go @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: 4cd558c37482e8d2c535d8107f2d11b49afbc5b5 +package data + var LanguagesByExtension = map[string][]string{ ".1": {"Roff"}, ".1in": {"Roff"}, diff --git a/vendor/gopkg.in/src-d/enry.v1/data/filename.go b/vendor/gopkg.in/src-d/enry.v1/data/filename.go index d1de99a16..12e18f88f 100644 --- a/vendor/gopkg.in/src-d/enry.v1/data/filename.go +++ b/vendor/gopkg.in/src-d/enry.v1/data/filename.go @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: 4cd558c37482e8d2c535d8107f2d11b49afbc5b5 +package data + var LanguagesByFilename = map[string][]string{ ".Rprofile": {"R"}, ".XCompose": {"XCompose"}, diff --git a/vendor/gopkg.in/src-d/enry.v1/data/frequencies.go b/vendor/gopkg.in/src-d/enry.v1/data/frequencies.go index 1164341d1..41c3aeaf2 100644 --- a/vendor/gopkg.in/src-d/enry.v1/data/frequencies.go +++ b/vendor/gopkg.in/src-d/enry.v1/data/frequencies.go @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: 4cd558c37482e8d2c535d8107f2d11b49afbc5b5 +package data + var LanguagesLogProbabilities = map[string]float64{ "1C Enterprise": -5.774552, "ABAP": -7.566311, diff --git a/vendor/gopkg.in/src-d/enry.v1/data/interpreter.go b/vendor/gopkg.in/src-d/enry.v1/data/interpreter.go index 02af4a7e8..c241278b7 100644 --- a/vendor/gopkg.in/src-d/enry.v1/data/interpreter.go +++ b/vendor/gopkg.in/src-d/enry.v1/data/interpreter.go @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: 4cd558c37482e8d2c535d8107f2d11b49afbc5b5 +package data + var LanguagesByInterpreter = map[string][]string{ "Rscript": {"R"}, "apl": {"APL"}, diff --git a/vendor/gopkg.in/src-d/enry.v1/data/mimeType.go b/vendor/gopkg.in/src-d/enry.v1/data/mimeType.go index 540cc1119..6e6a31544 100644 --- a/vendor/gopkg.in/src-d/enry.v1/data/mimeType.go +++ b/vendor/gopkg.in/src-d/enry.v1/data/mimeType.go @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: 4cd558c37482e8d2c535d8107f2d11b49afbc5b5 +package data + var LanguagesMime = map[string]string{ "AGS Script": "text/x-c++src", "APL": "text/apl", diff --git a/vendor/gopkg.in/src-d/enry.v1/data/type.go b/vendor/gopkg.in/src-d/enry.v1/data/type.go index 94f978257..a515af5cd 100644 --- a/vendor/gopkg.in/src-d/enry.v1/data/type.go +++ b/vendor/gopkg.in/src-d/enry.v1/data/type.go @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: 4cd558c37482e8d2c535d8107f2d11b49afbc5b5 +package data + var LanguagesType = map[string]int{ "1C Enterprise": 2, "ABAP": 2, diff --git a/vendor/gopkg.in/src-d/enry.v1/data/vendor.go b/vendor/gopkg.in/src-d/enry.v1/data/vendor.go index 3cc865f16..d920446ed 100644 --- a/vendor/gopkg.in/src-d/enry.v1/data/vendor.go +++ b/vendor/gopkg.in/src-d/enry.v1/data/vendor.go @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: 4cd558c37482e8d2c535d8107f2d11b49afbc5b5 +package data + import "gopkg.in/toqueteos/substring.v1" var VendorMatchers = substring.Or( diff --git a/vendor/gopkg.in/src-d/enry.v1/enry.go b/vendor/gopkg.in/src-d/enry.v1/enry.go new file mode 100644 index 000000000..4adf39ae9 --- /dev/null +++ b/vendor/gopkg.in/src-d/enry.v1/enry.go @@ -0,0 +1,3 @@ +package enry // import "gopkg.in/src-d/enry.v1" + +//go:generate make code-generate diff --git a/vendor/gopkg.in/src-d/enry.v1/generate.go b/vendor/gopkg.in/src-d/enry.v1/generate.go deleted file mode 100644 index f11c8ac24..000000000 --- a/vendor/gopkg.in/src-d/enry.v1/generate.go +++ /dev/null @@ -1,3 +0,0 @@ -package enry - -//go:generate make code-generate diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/alias.go.tmpl b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/alias.go.tmpl index 9b80e9783..d4d6a0ce2 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/alias.go.tmpl +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/alias.go.tmpl @@ -1,9 +1,5 @@ package data -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - // LanguagesByAlias keeps alias for different languages and use the name of the languages as an alias too. // All the keys (alias or not) are written in lower case and the whitespaces has been replaced by underscores. var LanguagesByAlias = map[string]string{ diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/commit.go.tmpl b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/commit.go.tmpl index 1256181b6..72c993d8e 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/commit.go.tmpl +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/commit.go.tmpl @@ -1,8 +1,4 @@ package data -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ . }} - // linguist's commit from which files were generated. -var LinguistCommit = "{{- . -}}" +var LinguistCommit = "{{- getCommit -}}" diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/content.go.tmpl b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/content.go.tmpl index 2681029e5..106616996 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/content.go.tmpl +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/content.go.tmpl @@ -1,9 +1,5 @@ package data -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - import "gopkg.in/toqueteos/substring.v1" type languageMatcher func ([]byte) []string diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/documentation.go.tmpl b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/documentation.go.tmpl index ca9de79da..1a82ffd7b 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/documentation.go.tmpl +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/documentation.go.tmpl @@ -1,9 +1,5 @@ package data -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - import "gopkg.in/toqueteos/substring.v1" var DocumentationMatchers = substring.Or( diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/extension.go.tmpl b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/extension.go.tmpl index f620bec22..4feb09c23 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/extension.go.tmpl +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/extension.go.tmpl @@ -1,9 +1,5 @@ package data -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - var LanguagesByExtension = map[string][]string{ {{range $extension, $languages := .LanguagesByExtension -}} "{{ $extension }}": { {{- $languages | formatStringSlice -}} }, diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/filename.go.tmpl b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/filename.go.tmpl index f4ff39436..899268347 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/filename.go.tmpl +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/filename.go.tmpl @@ -1,9 +1,5 @@ package data -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - var LanguagesByFilename = map[string][]string{ {{range $filename, $languages := . -}} "{{ $filename }}": { {{- formatStringSlice $languages -}} }, diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/frequencies.go.tmpl b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/frequencies.go.tmpl index dff2483c4..ac7ee544e 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/frequencies.go.tmpl +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/frequencies.go.tmpl @@ -1,9 +1,5 @@ package data -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - var LanguagesLogProbabilities = map[string]float64{ {{ $freqs := . -}} {{range $index, $language := orderKeys .Languages -}} diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/header.go.tmpl b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/header.go.tmpl new file mode 100644 index 000000000..c574ef24d --- /dev/null +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/header.go.tmpl @@ -0,0 +1,3 @@ +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. +// Extracted from github/linguist commit: {{ getCommit }} + diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/interpreter.go.tmpl b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/interpreter.go.tmpl index 46e361cd2..74cad5a7e 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/interpreter.go.tmpl +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/interpreter.go.tmpl @@ -1,9 +1,5 @@ package data -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - var LanguagesByInterpreter = map[string][]string{ {{range $interpreter, $languages := . -}} "{{ $interpreter }}": { {{- $languages | formatStringSlice -}} }, diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/mimeType.go.tmpl b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/mimeType.go.tmpl index d8dcff3e3..77b8d8c7b 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/mimeType.go.tmpl +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/mimeType.go.tmpl @@ -1,9 +1,5 @@ package data -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - var LanguagesMime = map[string]string{ {{range $language, $mime := . -}} "{{$language}}": "{{$mime -}}", diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/type.go.tmpl b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/type.go.tmpl index 8259ff5c3..9adea5888 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/type.go.tmpl +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/type.go.tmpl @@ -1,9 +1,5 @@ package data -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - var LanguagesType = map[string]int{ {{range $language, $type := . -}} "{{ $language }}": {{ $type -}}, diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/vendor.go.tmpl b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/vendor.go.tmpl index 0ef2e76a7..46402d23d 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/vendor.go.tmpl +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/assets/vendor.go.tmpl @@ -1,9 +1,5 @@ package data -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: {{ getCommit }} - import "gopkg.in/toqueteos/substring.v1" var VendorMatchers = substring.Or( diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/aliases.go b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/aliases.go index 91d6def8b..4fff9fd48 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/aliases.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/aliases.go @@ -2,12 +2,10 @@ package generator import ( "bytes" + "gopkg.in/yaml.v2" "io" "io/ioutil" "strings" - "text/template" - - yaml "gopkg.in/yaml.v2" ) // Aliases reads from fileToParse and builds source file from tmplPath. It complies with type File signature. @@ -55,14 +53,5 @@ func convertToAliasKey(s string) (key string) { } func executeAliasesTemplate(out io.Writer, languagesByAlias map[string]string, aliasesTmplPath, aliasesTmpl, commit string) error { - fmap := template.FuncMap{ - "getCommit": func() string { return commit }, - } - - t := template.Must(template.New(aliasesTmpl).Funcs(fmap).ParseFiles(aliasesTmplPath)) - if err := t.Execute(out, languagesByAlias); err != nil { - return err - } - - return nil + return executeTemplate(out, aliasesTmpl, aliasesTmplPath, commit, nil, languagesByAlias) } diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/documentation.go b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/documentation.go index 2407f6dd3..c20696803 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/documentation.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/documentation.go @@ -2,11 +2,9 @@ package generator import ( "bytes" + "gopkg.in/yaml.v2" "io" "io/ioutil" - "text/template" - - yaml "gopkg.in/yaml.v2" ) // Documentation reads from fileToParse and builds source file from tmplPath. It complies with type File signature. @@ -30,14 +28,5 @@ func Documentation(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit } func executeDocumentationTemplate(out io.Writer, regexpList []string, tmplPath, tmplName, commit string) error { - fmap := template.FuncMap{ - "getCommit": func() string { return commit }, - } - - t := template.Must(template.New(tmplName).Funcs(fmap).ParseFiles(tmplPath)) - if err := t.Execute(out, regexpList); err != nil { - return err - } - - return nil + return executeTemplate(out, tmplName, tmplPath, commit, nil, regexpList) } diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/extensions.go b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/extensions.go index 34c34fd49..a3f7e4ebc 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/extensions.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/extensions.go @@ -81,14 +81,7 @@ func buildLanguageExtensionsMap(languages map[string]*languageInfo) map[string][ func executeExtensionsTemplate(out io.Writer, extInfo *extensionsInfo, tmplPath, tmplName, commit string) error { fmap := template.FuncMap{ - "getCommit": func() string { return commit }, "formatStringSlice": func(slice []string) string { return `"` + strings.Join(slice, `","`) + `"` }, } - - t := template.Must(template.New(tmplName).Funcs(fmap).ParseFiles(tmplPath)) - if err := t.Execute(out, extInfo); err != nil { - return err - } - - return nil + return executeTemplate(out, tmplName, tmplPath, commit, fmap, extInfo) } diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/filenames.go b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/filenames.go index 150839049..79ad8431a 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/filenames.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/filenames.go @@ -91,14 +91,7 @@ func buildFilenameLanguageMap(languages map[string]*languageInfo) map[string][]s func executeFilenamesTemplate(out io.Writer, languagesByFilename map[string][]string, tmplPath, tmplName, commit string) error { fmap := template.FuncMap{ - "getCommit": func() string { return commit }, "formatStringSlice": func(slice []string) string { return `"` + strings.Join(slice, `","`) + `"` }, } - - t := template.Must(template.New(tmplName).Funcs(fmap).ParseFiles(tmplPath)) - if err := t.Execute(out, languagesByFilename); err != nil { - return err - } - - return nil + return executeTemplate(out, tmplName, tmplPath, commit, fmap, languagesByFilename) } diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/generator.go b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/generator.go index 89a7f08c4..72385e364 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/generator.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/generator.go @@ -1,8 +1,12 @@ package generator import ( + "bytes" "go/format" + "io" "io/ioutil" + "path/filepath" + "text/template" ) // File is the function's type that generate source file from a file to be parsed, linguist's samples dir and a template. @@ -13,10 +17,45 @@ func formatedWrite(outPath string, source []byte) error { if err != nil { return err } - if err := ioutil.WriteFile(outPath, formatedSource, 0666); err != nil { return err } - return nil } + +func executeTemplate(w io.Writer, name, path, commit string, fmap template.FuncMap, data interface{}) error { + getCommit := func() string { + return commit + } + + buf := bytes.NewBuffer(nil) + + const headerTmpl = "header.go.tmpl" + + headerPath := filepath.Join(filepath.Dir(path), headerTmpl) + + h := template.Must(template.New(headerTmpl).Funcs(template.FuncMap{ + "getCommit": getCommit, + }).ParseFiles(headerPath)) + + if err := h.Execute(buf, data); err != nil { + return err + } + + if fmap == nil { + fmap = make(template.FuncMap) + } + fmap["getCommit"] = getCommit + + t := template.Must(template.New(name).Funcs(fmap).ParseFiles(path)) + if err := t.Execute(buf, data); err != nil { + return err + } + + src, err := format.Source(buf.Bytes()) + if err != nil { + return err + } + _, err = w.Write(src) + return err +} diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/generator_test.go b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/generator_test.go index 26926dfc8..247dda6c4 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/generator_test.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/generator_test.go @@ -13,68 +13,71 @@ import ( ) const ( - linguistURL = "https://github.com/github/linguist.git" + linguistURL = "https://github.com/github/linguist.git" linguistClonedEnvVar = "ENRY_TEST_REPO" - commit = "d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68" - samplesDir = "samples" - languagesFile = "lib/linguist/languages.yml" + commit = "d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68" + samplesDir = "samples" + languagesFile = "lib/linguist/languages.yml" + + testDir = "test_files" + assetsDir = "../assets" // Extensions test - extensionGold = "test_files/extension.gold" - extensionTestTmplPath = "../assets/extension.go.tmpl" + extensionGold = testDir + "/extension.gold" + extensionTestTmplPath = assetsDir + "/extension.go.tmpl" extensionTestTmplName = "extension.go.tmpl" // Heuristics test heuristicsTestFile = "lib/linguist/heuristics.rb" - contentGold = "test_files/content.gold" - contentTestTmplPath = "../assets/content.go.tmpl" + contentGold = testDir + "/content.gold" + contentTestTmplPath = assetsDir + "/content.go.tmpl" contentTestTmplName = "content.go.tmpl" // Vendor test vendorTestFile = "lib/linguist/vendor.yml" - vendorGold = "test_files/vendor.gold" - vendorTestTmplPath = "../assets/vendor.go.tmpl" + vendorGold = testDir + "/vendor.gold" + vendorTestTmplPath = assetsDir + "/vendor.go.tmpl" vendorTestTmplName = "vendor.go.tmpl" // Documentation test documentationTestFile = "lib/linguist/documentation.yml" - documentationGold = "test_files/documentation.gold" - documentationTestTmplPath = "../assets/documentation.go.tmpl" + documentationGold = testDir + "/documentation.gold" + documentationTestTmplPath = assetsDir + "/documentation.go.tmpl" documentationTestTmplName = "documentation.go.tmpl" // Types test - typeGold = "test_files/type.gold" - typeTestTmplPath = "../assets/type.go.tmpl" + typeGold = testDir + "/type.gold" + typeTestTmplPath = assetsDir + "/type.go.tmpl" typeTestTmplName = "type.go.tmpl" // Interpreters test - interpreterGold = "test_files/interpreter.gold" - interpreterTestTmplPath = "../assets/interpreter.go.tmpl" + interpreterGold = testDir + "/interpreter.gold" + interpreterTestTmplPath = assetsDir + "/interpreter.go.tmpl" interpreterTestTmplName = "interpreter.go.tmpl" // Filenames test - filenameGold = "test_files/filename.gold" - filenameTestTmplPath = "../assets/filename.go.tmpl" + filenameGold = testDir + "/filename.gold" + filenameTestTmplPath = assetsDir + "/filename.go.tmpl" filenameTestTmplName = "filename.go.tmpl" // Aliases test - aliasGold = "test_files/alias.gold" - aliasTestTmplPath = "../assets/alias.go.tmpl" + aliasGold = testDir + "/alias.gold" + aliasTestTmplPath = assetsDir + "/alias.go.tmpl" aliasTestTmplName = "alias.go.tmpl" // Frequencies test - frequenciesGold = "test_files/frequencies.gold" - frequenciesTestTmplPath = "../assets/frequencies.go.tmpl" + frequenciesGold = testDir + "/frequencies.gold" + frequenciesTestTmplPath = assetsDir + "/frequencies.go.tmpl" frequenciesTestTmplName = "frequencies.go.tmpl" // commit test - commitGold = "test_files/commit.gold" - commitTestTmplPath = "../assets/commit.go.tmpl" + commitGold = testDir + "/commit.gold" + commitTestTmplPath = assetsDir + "/commit.go.tmpl" commitTestTmplName = "commit.go.tmpl" // mime test - mimeTypeGold = "test_files/mimeType.gold" - mimeTypeTestTmplPath = "../assets/mimeType.go.tmpl" + mimeTypeGold = testDir + "/mimeType.gold" + mimeTypeTestTmplPath = assetsDir + "/mimeType.go.tmpl" mimeTypeTestTmplName = "mimeType.go.tmpl" ) diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/heuristics.go b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/heuristics.go index 068a24220..212aafd6d 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/heuristics.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/heuristics.go @@ -428,7 +428,6 @@ func buildLanguagesHeuristics(langsList [][]string, heuristicsList [][]*heuristi func executeContentTemplate(out io.Writer, disambiguators []*disambiguator, tmplPath, tmplName, commit string) error { fmap := template.FuncMap{ - "getCommit": func() string { return commit }, "getAllHeuristics": getAllHeuristics, "returnStringSlice": func(slice []string) string { if len(slice) == 0 { @@ -440,13 +439,7 @@ func executeContentTemplate(out io.Writer, disambiguators []*disambiguator, tmpl "returnLanguages": returnLanguages, "avoidLanguage": avoidLanguage, } - - t := template.Must(template.New(tmplName).Funcs(fmap).ParseFiles(tmplPath)) - if err := t.Execute(out, disambiguators); err != nil { - return err - } - - return nil + return executeTemplate(out, tmplName, tmplPath, commit, fmap, disambiguators) } func getAllHeuristics(disambiguators []*disambiguator) []*heuristic { diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/interpreters.go b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/interpreters.go index e9b189551..7c3644b13 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/interpreters.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/interpreters.go @@ -47,14 +47,7 @@ func buildInterpreterLanguagesMap(languages map[string]*languageInfo, orderedKey func executeInterpretersTemplate(out io.Writer, languagesByInterpreter map[string][]string, tmplPath, tmplName, commit string) error { fmap := template.FuncMap{ - "getCommit": func() string { return commit }, "formatStringSlice": func(slice []string) string { return `"` + strings.Join(slice, `","`) + `"` }, } - - t := template.Must(template.New(tmplName).Funcs(fmap).ParseFiles(tmplPath)) - if err := t.Execute(out, languagesByInterpreter); err != nil { - return err - } - - return nil + return executeTemplate(out, tmplName, tmplPath, commit, fmap, languagesByInterpreter) } diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/linguist-commit.go b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/linguist-commit.go index e7d98991e..a8549645c 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/linguist-commit.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/linguist-commit.go @@ -2,16 +2,13 @@ package generator import ( "bytes" - "text/template" ) // Commit takes a commit and builds the source file from tmplPath. It complies with type File signature. func Commit(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error { buf := &bytes.Buffer{} - t := template.Must(template.New(tmplName).ParseFiles(tmplPath)) - if err := t.Execute(buf, commit); err != nil { + if err := executeTemplate(buf, tmplName, tmplPath, commit, nil, nil); err != nil { return err } - return formatedWrite(outPath, buf.Bytes()) } diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/mimeType.go b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/mimeType.go index 6fb270360..fdb47e698 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/mimeType.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/mimeType.go @@ -2,11 +2,9 @@ package generator import ( "bytes" + "gopkg.in/yaml.v2" "io" "io/ioutil" - "text/template" - - yaml "gopkg.in/yaml.v2" ) func MimeType(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error { @@ -42,14 +40,5 @@ func buildLanguageMimeMap(languages map[string]*languageInfo) map[string]string } func executeMimeTemplate(out io.Writer, langMimeMap map[string]string, tmplPath, tmplName, commit string) error { - fmap := template.FuncMap{ - "getCommit": func() string { return commit }, - } - - t := template.Must(template.New(tmplName).Funcs(fmap).ParseFiles(tmplPath)) - if err := t.Execute(out, langMimeMap); err != nil { - return err - } - - return nil + return executeTemplate(out, tmplName, tmplPath, commit, nil, langMimeMap) } diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/samplesfreq.go b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/samplesfreq.go index e82036f03..7b734b0f7 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/samplesfreq.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/samplesfreq.go @@ -157,7 +157,6 @@ func getTokens(samples []string) ([]string, error) { func executeFrequenciesTemplate(out io.Writer, freqs *samplesFrequencies, tmplPath, tmplName, commit string) error { fmap := template.FuncMap{ - "getCommit": func() string { return commit }, "toFloat64": func(num int) string { return fmt.Sprintf("%f", float64(num)) }, "orderKeys": func(m map[string]int) []string { keys := make([]string, 0, len(m)) @@ -187,11 +186,5 @@ func executeFrequenciesTemplate(out io.Writer, freqs *samplesFrequencies, tmplPa }, "quote": strconv.Quote, } - - t := template.Must(template.New(tmplName).Funcs(fmap).ParseFiles(tmplPath)) - if err := t.Execute(out, freqs); err != nil { - return err - } - - return nil + return executeTemplate(out, tmplName, tmplPath, commit, fmap, freqs) } diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/alias.gold b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/alias.gold index ff15fcc59..460327ce4 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/alias.gold +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/alias.gold @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68 +package data + // LanguagesByAlias keeps alias for different languages and use the name of the languages as an alias too. // All the keys (alias or not) are written in lower case and the whitespaces has been replaced by underscores. var LanguagesByAlias = map[string]string{ diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/commit.gold b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/commit.gold index eca459f05..66345c52c 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/commit.gold +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/commit.gold @@ -1,8 +1,7 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68 +package data + // linguist's commit from which files were generated. var LinguistCommit = "d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68" diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/content.gold b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/content.gold index e9afe0a52..c68e647b5 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/content.gold +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/content.gold @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68 +package data + import "gopkg.in/toqueteos/substring.v1" type languageMatcher func([]byte) []string diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/documentation.gold b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/documentation.gold index 8664baddc..04ec5906b 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/documentation.gold +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/documentation.gold @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68 +package data + import "gopkg.in/toqueteos/substring.v1" var DocumentationMatchers = substring.Or( diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/extension.gold b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/extension.gold index ac1b5b8b7..34fcd48b5 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/extension.gold +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/extension.gold @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68 +package data + var LanguagesByExtension = map[string][]string{ ".1": {"Roff"}, ".1in": {"Roff"}, diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/filename.gold b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/filename.gold index bd4dbb566..ccb89161c 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/filename.gold +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/filename.gold @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68 +package data + var LanguagesByFilename = map[string][]string{ ".Rprofile": {"R"}, ".XCompose": {"XCompose"}, diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/frequencies.gold b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/frequencies.gold index e879d5fa3..8b36b8f31 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/frequencies.gold +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/frequencies.gold @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68 +package data + var LanguagesLogProbabilities = map[string]float64{ "1C Enterprise": -5.724674, "ABAP": -7.516433, diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/interpreter.gold b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/interpreter.gold index 0a88fffd5..5c87b9113 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/interpreter.gold +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/interpreter.gold @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68 +package data + var LanguagesByInterpreter = map[string][]string{ "Rscript": {"R"}, "apl": {"APL"}, diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/mimeType.gold b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/mimeType.gold index 073d43e09..939b560cc 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/mimeType.gold +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/mimeType.gold @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68 +package data + var LanguagesMime = map[string]string{ "AGS Script": "text/x-c++src", "APL": "text/apl", diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/type.gold b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/type.gold index c9bc39126..252949419 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/type.gold +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/type.gold @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68 +package data + var LanguagesType = map[string]int{ "1C Enterprise": 2, "ABAP": 2, diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/vendor.gold b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/vendor.gold index 38d035ab8..7c2819921 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/vendor.gold +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/test_files/vendor.gold @@ -1,9 +1,8 @@ -package data - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND +// Code generated by gopkg.in/src-d/enry.v1/internal/code-generator DO NOT EDIT. // Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68 +package data + import "gopkg.in/toqueteos/substring.v1" var VendorMatchers = substring.Or( diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/types.go b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/types.go index 088513940..c680e33e9 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/types.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/types.go @@ -2,11 +2,9 @@ package generator import ( "bytes" + "gopkg.in/yaml.v2" "io" "io/ioutil" - "text/template" - - yaml "gopkg.in/yaml.v2" ) var typeToTypeConst = map[string]int{ @@ -48,14 +46,5 @@ func buildLanguageTypeMap(languages map[string]*languageInfo) map[string]int { } func executeTypesTemplate(out io.Writer, langTypeMap map[string]int, tmplPath, tmplName, commit string) error { - fmap := template.FuncMap{ - "getCommit": func() string { return commit }, - } - - t := template.Must(template.New(tmplName).Funcs(fmap).ParseFiles(tmplPath)) - if err := t.Execute(out, langTypeMap); err != nil { - return err - } - - return nil + return executeTemplate(out, tmplName, tmplPath, commit, nil, langTypeMap) } diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/vendor.go b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/vendor.go index e6d1880f3..f174f2a30 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/vendor.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/generator/vendor.go @@ -2,11 +2,9 @@ package generator import ( "bytes" + "gopkg.in/yaml.v2" "io" "io/ioutil" - "text/template" - - yaml "gopkg.in/yaml.v2" ) // Vendor reads from fileToParse and builds source file from tmplPath. It complies with type File signature. @@ -30,14 +28,5 @@ func Vendor(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) } func executeVendorTemplate(out io.Writer, regexpList []string, tmplPath, tmplName, commit string) error { - fmap := template.FuncMap{ - "getCommit": func() string { return commit }, - } - - t := template.Must(template.New(tmplName).Funcs(fmap).ParseFiles(tmplPath)) - if err := t.Execute(out, regexpList); err != nil { - return err - } - - return nil + return executeTemplate(out, tmplName, tmplPath, commit, nil, regexpList) } diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/main.go b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/main.go index 9ba983a0f..2ff388587 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/main.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/code-generator/main.go @@ -92,17 +92,17 @@ func main() { } fileList := []*generatorFiles{ - &generatorFiles{generator.Extensions, languagesYAML, "", extensionsFile, extensionsTmplPath, extensionsTmpl, commit}, - &generatorFiles{generator.Heuristics, heuristicsRuby, "", contentFile, contentTmplPath, contentTmpl, commit}, - &generatorFiles{generator.Vendor, vendorYAML, "", vendorFile, vendorTmplPath, vendorTmpl, commit}, - &generatorFiles{generator.Documentation, documentationYAML, "", documentationFile, documentationTmplPath, documentationTmpl, commit}, - &generatorFiles{generator.Types, languagesYAML, "", typeFile, typeTmplPath, typeTmpl, commit}, - &generatorFiles{generator.Interpreters, languagesYAML, "", interpretersFile, interpretersTmplPath, interpretersTmpl, commit}, - &generatorFiles{generator.Filenames, languagesYAML, samplesDir, filenamesFile, filenamesTmplPath, filenamesTmpl, commit}, - &generatorFiles{generator.Aliases, languagesYAML, "", aliasesFile, aliasesTmplPath, aliasesTmpl, commit}, - &generatorFiles{generator.Frequencies, "", samplesDir, frequenciesFile, frequenciesTmplPath, frequenciesTmpl, commit}, - &generatorFiles{generator.Commit, "", "", commitFile, commitTmplPath, commitTmpl, commit}, - &generatorFiles{generator.MimeType, languagesYAML, "", mimeTypeFile, mimeTypeTmplPath, mimeTypeTmpl, commit}, + {generator.Extensions, languagesYAML, "", extensionsFile, extensionsTmplPath, extensionsTmpl, commit}, + {generator.Heuristics, heuristicsRuby, "", contentFile, contentTmplPath, contentTmpl, commit}, + {generator.Vendor, vendorYAML, "", vendorFile, vendorTmplPath, vendorTmpl, commit}, + {generator.Documentation, documentationYAML, "", documentationFile, documentationTmplPath, documentationTmpl, commit}, + {generator.Types, languagesYAML, "", typeFile, typeTmplPath, typeTmpl, commit}, + {generator.Interpreters, languagesYAML, "", interpretersFile, interpretersTmplPath, interpretersTmpl, commit}, + {generator.Filenames, languagesYAML, samplesDir, filenamesFile, filenamesTmplPath, filenamesTmpl, commit}, + {generator.Aliases, languagesYAML, "", aliasesFile, aliasesTmplPath, aliasesTmpl, commit}, + {generator.Frequencies, "", samplesDir, frequenciesFile, frequenciesTmplPath, frequenciesTmpl, commit}, + {generator.Commit, "", "", commitFile, commitTmplPath, commitTmpl, commit}, + {generator.MimeType, languagesYAML, "", mimeTypeFile, mimeTypeTmplPath, mimeTypeTmpl, commit}, } for _, file := range fileList { diff --git a/vendor/gopkg.in/src-d/enry.v1/internal/tokenizer/tokenize.go b/vendor/gopkg.in/src-d/enry.v1/internal/tokenizer/tokenize.go index 18f04d8a8..ce02e310b 100644 --- a/vendor/gopkg.in/src-d/enry.v1/internal/tokenizer/tokenize.go +++ b/vendor/gopkg.in/src-d/enry.v1/internal/tokenizer/tokenize.go @@ -43,11 +43,11 @@ var ( extractRemainders, } - // Differences between golang regexp and onigumura: - // 1. no (?s) in onigumura - makes dot match \n - // 2. no (?U) in onigumura - ungreedy * - // 3. (?m) implies dot matches \n in onigumura - // 4. onigumura handles \w differently - impossible, but true + // Differences between golang regexp and oniguruma: + // 1. no (?s) in oniguruma - makes dot match \n + // 2. no (?U) in oniguruma - ungreedy * + // 3. (?m) implies dot matches \n in oniguruma + // 4. oniguruma handles \w differently - impossible, but true // // Workarounds: // 1. (.|\n) diff --git a/vendor/gopkg.in/src-d/enry.v1/type.go b/vendor/gopkg.in/src-d/enry.v1/type.go deleted file mode 100644 index 5355e62c1..000000000 --- a/vendor/gopkg.in/src-d/enry.v1/type.go +++ /dev/null @@ -1,461 +0,0 @@ -package enry - -// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator -// THIS FILE SHOULD NOT BE EDITED BY HAND -// Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68 - -var languagesType = map[string]Type{ - "1C Enterprise": Programming, - "ABAP": Programming, - "ABNF": Data, - "AGS Script": Programming, - "AMPL": Programming, - "ANTLR": Programming, - "API Blueprint": Markup, - "APL": Programming, - "ASN.1": Data, - "ASP": Programming, - "ATS": Programming, - "ActionScript": Programming, - "Ada": Programming, - "Agda": Programming, - "Alloy": Programming, - "Alpine Abuild": Programming, - "Ant Build System": Data, - "ApacheConf": Markup, - "Apex": Programming, - "Apollo Guidance Computer": Programming, - "AppleScript": Programming, - "Arc": Programming, - "Arduino": Programming, - "AsciiDoc": Prose, - "AspectJ": Programming, - "Assembly": Programming, - "Augeas": Programming, - "AutoHotkey": Programming, - "AutoIt": Programming, - "Awk": Programming, - "Batchfile": Programming, - "Befunge": Programming, - "Bison": Programming, - "BitBake": Programming, - "Blade": Markup, - "BlitzBasic": Programming, - "BlitzMax": Programming, - "Bluespec": Programming, - "Boo": Programming, - "Brainfuck": Programming, - "Brightscript": Programming, - "Bro": Programming, - "C": Programming, - "C#": Programming, - "C++": Programming, - "C-ObjDump": Data, - "C2hs Haskell": Programming, - "CLIPS": Programming, - "CMake": Programming, - "COBOL": Programming, - "COLLADA": Data, - "CSON": Data, - "CSS": Markup, - "CSV": Data, - "CWeb": Programming, - "Cap'n Proto": Programming, - "CartoCSS": Programming, - "Ceylon": Programming, - "Chapel": Programming, - "Charity": Programming, - "ChucK": Programming, - "Cirru": Programming, - "Clarion": Programming, - "Clean": Programming, - "Click": Programming, - "Clojure": Programming, - "Closure Templates": Markup, - "CoffeeScript": Programming, - "ColdFusion": Programming, - "ColdFusion CFC": Programming, - "Common Lisp": Programming, - "Component Pascal": Programming, - "Cool": Programming, - "Coq": Programming, - "Cpp-ObjDump": Data, - "Creole": Prose, - "Crystal": Programming, - "Csound": Programming, - "Csound Document": Programming, - "Csound Score": Programming, - "Cuda": Programming, - "Cycript": Programming, - "Cython": Programming, - "D": Programming, - "D-ObjDump": Data, - "DIGITAL Command Language": Programming, - "DM": Programming, - "DNS Zone": Data, - "DTrace": Programming, - "Darcs Patch": Data, - "Dart": Programming, - "Diff": Data, - "Dockerfile": Data, - "Dogescript": Programming, - "Dylan": Programming, - "E": Programming, - "EBNF": Data, - "ECL": Programming, - "ECLiPSe": Programming, - "EJS": Markup, - "EQ": Programming, - "Eagle": Markup, - "Easybuild": Data, - "Ecere Projects": Data, - "Eiffel": Programming, - "Elixir": Programming, - "Elm": Programming, - "Emacs Lisp": Programming, - "EmberScript": Programming, - "Erlang": Programming, - "F#": Programming, - "FLUX": Programming, - "Factor": Programming, - "Fancy": Programming, - "Fantom": Programming, - "Filebench WML": Programming, - "Filterscript": Programming, - "Formatted": Data, - "Forth": Programming, - "Fortran": Programming, - "FreeMarker": Programming, - "Frege": Programming, - "G-code": Data, - "GAMS": Programming, - "GAP": Programming, - "GCC Machine Description": Programming, - "GDB": Programming, - "GDScript": Programming, - "GLSL": Programming, - "GN": Data, - "Game Maker Language": Programming, - "Genie": Programming, - "Genshi": Programming, - "Gentoo Ebuild": Programming, - "Gentoo Eclass": Programming, - "Gettext Catalog": Prose, - "Gherkin": Programming, - "Glyph": Programming, - "Gnuplot": Programming, - "Go": Programming, - "Golo": Programming, - "Gosu": Programming, - "Grace": Programming, - "Gradle": Data, - "Grammatical Framework": Programming, - "Graph Modeling Language": Data, - "GraphQL": Data, - "Graphviz (DOT)": Data, - "Groovy": Programming, - "Groovy Server Pages": Programming, - "HCL": Programming, - "HLSL": Programming, - "HTML": Markup, - "HTML+Django": Markup, - "HTML+ECR": Markup, - "HTML+EEX": Markup, - "HTML+ERB": Markup, - "HTML+PHP": Markup, - "HTTP": Data, - "Hack": Programming, - "Haml": Markup, - "Handlebars": Markup, - "Harbour": Programming, - "Haskell": Programming, - "Haxe": Programming, - "Hy": Programming, - "HyPhy": Programming, - "IDL": Programming, - "IGOR Pro": Programming, - "INI": Data, - "IRC log": Data, - "Idris": Programming, - "Inform 7": Programming, - "Inno Setup": Programming, - "Io": Programming, - "Ioke": Programming, - "Isabelle": Programming, - "Isabelle ROOT": Programming, - "J": Programming, - "JFlex": Programming, - "JSON": Data, - "JSON5": Data, - "JSONLD": Data, - "JSONiq": Programming, - "JSX": Programming, - "Jasmin": Programming, - "Java": Programming, - "Java Server Pages": Programming, - "JavaScript": Programming, - "Jison": Programming, - "Jison Lex": Programming, - "Jolie": Programming, - "Julia": Programming, - "Jupyter Notebook": Markup, - "KRL": Programming, - "KiCad": Programming, - "Kit": Markup, - "Kotlin": Programming, - "LFE": Programming, - "LLVM": Programming, - "LOLCODE": Programming, - "LSL": Programming, - "LabVIEW": Programming, - "Lasso": Programming, - "Latte": Markup, - "Lean": Programming, - "Less": Markup, - "Lex": Programming, - "LilyPond": Programming, - "Limbo": Programming, - "Linker Script": Data, - "Linux Kernel Module": Data, - "Liquid": Markup, - "Literate Agda": Programming, - "Literate CoffeeScript": Programming, - "Literate Haskell": Programming, - "LiveScript": Programming, - "Logos": Programming, - "Logtalk": Programming, - "LookML": Programming, - "LoomScript": Programming, - "Lua": Programming, - "M": Programming, - "M4": Programming, - "M4Sugar": Programming, - "MAXScript": Programming, - "MQL4": Programming, - "MQL5": Programming, - "MTML": Markup, - "MUF": Programming, - "Makefile": Programming, - "Mako": Programming, - "Markdown": Prose, - "Marko": Markup, - "Mask": Markup, - "Mathematica": Programming, - "Matlab": Programming, - "Maven POM": Data, - "Max": Programming, - "MediaWiki": Prose, - "Mercury": Programming, - "Meson": Programming, - "Metal": Programming, - "MiniD": Programming, - "Mirah": Programming, - "Modelica": Programming, - "Modula-2": Programming, - "Module Management System": Programming, - "Monkey": Programming, - "Moocode": Programming, - "MoonScript": Programming, - "Myghty": Programming, - "NCL": Programming, - "NL": Data, - "NSIS": Programming, - "Nemerle": Programming, - "NetLinx": Programming, - "NetLinx+ERB": Programming, - "NetLogo": Programming, - "NewLisp": Programming, - "Nginx": Markup, - "Nim": Programming, - "Ninja": Data, - "Nit": Programming, - "Nix": Programming, - "Nu": Programming, - "NumPy": Programming, - "OCaml": Programming, - "ObjDump": Data, - "Objective-C": Programming, - "Objective-C++": Programming, - "Objective-J": Programming, - "Omgrofl": Programming, - "Opa": Programming, - "Opal": Programming, - "OpenCL": Programming, - "OpenEdge ABL": Programming, - "OpenRC runscript": Programming, - "OpenSCAD": Programming, - "OpenType Feature File": Data, - "Org": Prose, - "Ox": Programming, - "Oxygene": Programming, - "Oz": Programming, - "P4": Programming, - "PAWN": Programming, - "PHP": Programming, - "PLSQL": Programming, - "PLpgSQL": Programming, - "POV-Ray SDL": Programming, - "Pan": Programming, - "Papyrus": Programming, - "Parrot": Programming, - "Parrot Assembly": Programming, - "Parrot Internal Representation": Programming, - "Pascal": Programming, - "Pep8": Programming, - "Perl": Programming, - "Perl 6": Programming, - "Pic": Markup, - "Pickle": Data, - "PicoLisp": Programming, - "PigLatin": Programming, - "Pike": Programming, - "Pod": Prose, - "PogoScript": Programming, - "Pony": Programming, - "PostScript": Markup, - "PowerBuilder": Programming, - "PowerShell": Programming, - "Processing": Programming, - "Prolog": Programming, - "Propeller Spin": Programming, - "Protocol Buffer": Markup, - "Public Key": Data, - "Pug": Markup, - "Puppet": Programming, - "Pure Data": Programming, - "PureBasic": Programming, - "PureScript": Programming, - "Python": Programming, - "Python console": Programming, - "Python traceback": Data, - "QML": Programming, - "QMake": Programming, - "R": Programming, - "RAML": Markup, - "RDoc": Prose, - "REALbasic": Programming, - "REXX": Programming, - "RHTML": Markup, - "RMarkdown": Prose, - "RPM Spec": Data, - "RUNOFF": Markup, - "Racket": Programming, - "Ragel": Programming, - "Rascal": Programming, - "Raw token data": Data, - "Reason": Programming, - "Rebol": Programming, - "Red": Programming, - "Redcode": Programming, - "Regular Expression": Data, - "Ren'Py": Programming, - "RenderScript": Programming, - "Ring": Programming, - "RobotFramework": Programming, - "Roff": Markup, - "Rouge": Programming, - "Ruby": Programming, - "Rust": Programming, - "SAS": Programming, - "SCSS": Markup, - "SMT": Programming, - "SPARQL": Data, - "SQF": Programming, - "SQL": Data, - "SQLPL": Programming, - "SRecode Template": Markup, - "STON": Data, - "SVG": Data, - "Sage": Programming, - "SaltStack": Programming, - "Sass": Markup, - "Scala": Programming, - "Scaml": Markup, - "Scheme": Programming, - "Scilab": Programming, - "Self": Programming, - "ShaderLab": Programming, - "Shell": Programming, - "ShellSession": Programming, - "Shen": Programming, - "Slash": Programming, - "Slim": Markup, - "Smali": Programming, - "Smalltalk": Programming, - "Smarty": Programming, - "SourcePawn": Programming, - "Spline Font Database": Data, - "Squirrel": Programming, - "Stan": Programming, - "Standard ML": Programming, - "Stata": Programming, - "Stylus": Markup, - "SubRip Text": Data, - "Sublime Text Config": Data, - "SuperCollider": Programming, - "Swift": Programming, - "SystemVerilog": Programming, - "TI Program": Programming, - "TLA": Programming, - "TOML": Data, - "TXL": Programming, - "Tcl": Programming, - "Tcsh": Programming, - "TeX": Markup, - "Tea": Markup, - "Terra": Programming, - "Text": Prose, - "Textile": Prose, - "Thrift": Programming, - "Turing": Programming, - "Turtle": Data, - "Twig": Markup, - "Type Language": Data, - "TypeScript": Programming, - "Unified Parallel C": Programming, - "Unity3D Asset": Data, - "Unix Assembly": Programming, - "Uno": Programming, - "UnrealScript": Programming, - "UrWeb": Programming, - "VCL": Programming, - "VHDL": Programming, - "Vala": Programming, - "Verilog": Programming, - "Vim script": Programming, - "Visual Basic": Programming, - "Volt": Programming, - "Vue": Markup, - "Wavefront Material": Data, - "Wavefront Object": Data, - "Web Ontology Language": Markup, - "WebAssembly": Programming, - "WebIDL": Programming, - "World of Warcraft Addon Data": Data, - "X10": Programming, - "XC": Programming, - "XCompose": Data, - "XML": Data, - "XPages": Programming, - "XProc": Programming, - "XQuery": Programming, - "XS": Programming, - "XSLT": Programming, - "Xojo": Programming, - "Xtend": Programming, - "YAML": Data, - "YANG": Data, - "Yacc": Programming, - "Zephir": Programming, - "Zimpl": Programming, - "desktop": Data, - "eC": Programming, - "edn": Data, - "fish": Programming, - "mupad": Programming, - "nesC": Programming, - "ooc": Programming, - "reStructuredText": Prose, - "wisp": Programming, - "xBase": Programming, -}