.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.1.0 / go / vcs / env.go
diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.1.0/go/vcs/env.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.1.0/go/vcs/env.go
new file mode 100644 (file)
index 0000000..189210c
--- /dev/null
@@ -0,0 +1,39 @@
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package vcs
+
+import (
+       "os"
+       "strings"
+)
+
+// envForDir returns a copy of the environment
+// suitable for running in the given directory.
+// The environment is the current process's environment
+// but with an updated $PWD, so that an os.Getwd in the
+// child will be faster.
+func envForDir(dir string) []string {
+       env := os.Environ()
+       // Internally we only use rooted paths, so dir is rooted.
+       // Even if dir is not rooted, no harm done.
+       return mergeEnvLists([]string{"PWD=" + dir}, env)
+}
+
+// mergeEnvLists merges the two environment lists such that
+// variables with the same name in "in" replace those in "out".
+func mergeEnvLists(in, out []string) []string {
+NextVar:
+       for _, inkv := range in {
+               k := strings.SplitAfterN(inkv, "=", 2)[0]
+               for i, outkv := range out {
+                       if strings.HasPrefix(outkv, k) {
+                               out[i] = inkv
+                               continue NextVar
+                       }
+               }
+               out = append(out, inkv)
+       }
+       return out
+}