* These env_* functions are for setting up the child environment; the * "replace" variant overrides the value of any existing variable with that * "key". The "append" variant puts our new value at the end of a list, * separated by PATH_SEP (which is what separate values in * GIT_ALTERNATE_OBJECT_DIRECTORIES). */
| 91 | * GIT_ALTERNATE_OBJECT_DIRECTORIES). |
| 92 | */ |
| 93 | static void env_append(struct strvec *env, const char *key, const char *val) |
| 94 | { |
| 95 | struct strbuf quoted = STRBUF_INIT; |
| 96 | const char *old; |
| 97 | |
| 98 | /* |
| 99 | * Avoid quoting if it's not necessary, for maximum compatibility |
| 100 | * with older parsers which don't understand the quoting. |
| 101 | */ |
| 102 | if (*val == '"' || strchr(val, PATH_SEP)) { |
| 103 | strbuf_addch("ed, '"'); |
| 104 | quote_c_style(val, "ed, NULL, 1); |
| 105 | strbuf_addch("ed, '"'); |
| 106 | val = quoted.buf; |
| 107 | } |
| 108 | |
| 109 | old = getenv(key); |
| 110 | if (!old) |
| 111 | strvec_pushf(env, "%s=%s", key, val); |
| 112 | else |
| 113 | strvec_pushf(env, "%s=%s%c%s", key, old, PATH_SEP, val); |
| 114 | |
| 115 | strbuf_release("ed); |
| 116 | } |
| 117 | |
| 118 | static void env_replace(struct strvec *env, const char *key, const char *val) |
| 119 | { |
no test coverage detected