Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2017-09-13 19:29:23 +0300
committerJacob Vosmaer <jacob@gitlab.com>2017-09-13 19:29:23 +0300
commit8760616b122a13faa53706adc62c9b57550753d1 (patch)
tree7b2f7cdd0df53e39caa5c128e265b60403f8099c /internal/linguist
parent222f77398de776f44c224227edafe5657a9fe467 (diff)
Simplify linguist lookup code
Diffstat (limited to 'internal/linguist')
-rw-r--r--internal/linguist/linguist.go24
1 files changed, 7 insertions, 17 deletions
diff --git a/internal/linguist/linguist.go b/internal/linguist/linguist.go
index 64598373f..42f8f0e4f 100644
--- a/internal/linguist/linguist.go
+++ b/internal/linguist/linguist.go
@@ -53,31 +53,21 @@ func Color(language string) string {
// LoadColors loads the name->color map from the Linguist gem.
func LoadColors() error {
- tempFile, err := ioutil.TempFile("", "gitaly-linguist")
- if err != nil {
- return err
- }
- defer os.Remove(tempFile.Name())
-
- if err := tempFile.Close(); err != nil {
- return err
- }
-
- // Replace the tempfile with a symlink to the directory where
- // github-linguist is installed. We don't write the path to stdout
- // because Bundler sometimes writes garbage to stdout.
- rubyScript := `FileUtils.ln_sf(Bundler.rubygems.find_name('github-linguist').first.full_gem_path, ARGV.first)`
- cmd := exec.Command("bundle", "exec", "ruby", "-r", "fileutils", "-e", rubyScript, tempFile.Name())
+ // We can't use 'bundle show' because that sometimes prints garbage on
+ // its stdout.
+ rubyScript := `print Bundler.rubygems.find_name('github-linguist').first.full_gem_path`
+ cmd := exec.Command("bundle", "exec", "ruby", "-e", rubyScript)
cmd.Dir = config.Config.Ruby.Dir
- if err := cmd.Run(); err != nil {
+ linguistPath, err := cmd.Output()
+ if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
err = fmt.Errorf("%v; stderr: %q", exitError, exitError.Stderr)
}
return err
}
- languageJSON, err := ioutil.ReadFile(path.Join(tempFile.Name(), "lib/linguist/languages.json"))
+ languageJSON, err := ioutil.ReadFile(path.Join(string(linguistPath), "lib/linguist/languages.json"))
if err != nil {
return err
}