GoPLS Viewer

Home|gopls/go/vcs/env.go
1// Copyright 2013 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package vcs
6
7import (
8    "os"
9    "strings"
10)
11
12// envForDir returns a copy of the environment
13// suitable for running in the given directory.
14// The environment is the current process's environment
15// but with an updated $PWD, so that an os.Getwd in the
16// child will be faster.
17func envForDir(dir string) []string {
18    env := os.Environ()
19    // Internally we only use rooted paths, so dir is rooted.
20    // Even if dir is not rooted, no harm done.
21    return mergeEnvLists([]string{"PWD=" + dir}, env)
22}
23
24// mergeEnvLists merges the two environment lists such that
25// variables with the same name in "in" replace those in "out".
26func mergeEnvLists(inout []string) []string {
27NextVar:
28    for _inkv := range in {
29        k := strings.SplitAfterN(inkv"="2)[0]
30        for ioutkv := range out {
31            if strings.HasPrefix(outkvk) {
32                out[i] = inkv
33                continue NextVar
34            }
35        }
36        out = append(outinkv)
37    }
38    return out
39}
40
MembersX
mergeEnvLists.RangeStmt_834.BlockStmt.RangeStmt_906.i
os
mergeEnvLists.in
mergeEnvLists.out
mergeEnvLists.RangeStmt_834.inkv
mergeEnvLists.RangeStmt_834.BlockStmt.RangeStmt_906.outkv
envForDir
envForDir.dir
envForDir.env
mergeEnvLists
Members
X