MCPcopy
hub / github.com/direnv/direnv / BuildEnvDiff

Function BuildEnvDiff

internal/cmd/env_diff.go:43–70  ·  view source on GitHub ↗

BuildEnvDiff analyses the changes between 'e1' and 'e2' and builds an EnvDiff out of it.

(e1, e2 Env)

Source from the content-addressed store, hash-verified

41// BuildEnvDiff analyses the changes between 'e1' and 'e2' and builds an
42// EnvDiff out of it.
43func BuildEnvDiff(e1, e2 Env) *EnvDiff {
44 diff := NewEnvDiff()
45
46 in := func(key string, e Env) bool {
47 _, ok := e[key]
48 return ok
49 }
50
51 for key := range e1 {
52 if IgnoredEnv(key) {
53 continue
54 }
55 if e2[key] != e1[key] || !in(key, e2) {
56 diff.Prev[key] = e1[key]
57 }
58 }
59
60 for key := range e2 {
61 if IgnoredEnv(key) {
62 continue
63 }
64 if e2[key] != e1[key] || !in(key, e1) {
65 diff.Next[key] = e2[key]
66 }
67 }
68
69 return diff
70}
71
72// LoadEnvDiff unmarshalls a gzenv string back into an EnvDiff.
73func LoadEnvDiff(gzenvStr string) (diff *EnvDiff, err error) {

Callers 2

DiffMethod · 0.85
TestEnvDiffEmptyValueFunction · 0.85

Calls 2

NewEnvDiffFunction · 0.85
IgnoredEnvFunction · 0.85

Tested by 1

TestEnvDiffEmptyValueFunction · 0.68