MCPcopy Index your code
hub / github.com/git/git / env_append

Function env_append

tmp-objdir.c:93–116  ·  view source on GitHub ↗

* 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). */

Source from the content-addressed store, hash-verified

91 * GIT_ALTERNATE_OBJECT_DIRECTORIES).
92 */
93static 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(&quoted, '"');
104 quote_c_style(val, &quoted, NULL, 1);
105 strbuf_addch(&quoted, '"');
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(&quoted);
116}
117
118static void env_replace(struct strvec *env, const char *key, const char *val)
119{

Callers 1

tmp_objdir_createFunction · 0.85

Calls 4

strbuf_addchFunction · 0.85
quote_c_styleFunction · 0.85
strvec_pushfFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected