pack: move approximate object count to object store
[gitweb.git] / tmp-objdir.c
index 64435f23a483dfc40e91437f0689bdfb9ac4b8f8..fea3f55545cbf193f823db468c7640bfd48d9bbd 100644 (file)
@@ -5,6 +5,8 @@
 #include "string-list.h"
 #include "strbuf.h"
 #include "argv-array.h"
+#include "quote.h"
+#include "object-store.h"
 
 struct tmp_objdir {
        struct strbuf path;
@@ -79,12 +81,27 @@ static void remove_tmp_objdir_on_signal(int signo)
  */
 static void env_append(struct argv_array *env, const char *key, const char *val)
 {
-       const char *old = getenv(key);
+       struct strbuf quoted = STRBUF_INIT;
+       const char *old;
 
+       /*
+        * Avoid quoting if it's not necessary, for maximum compatibility
+        * with older parsers which don't understand the quoting.
+        */
+       if (*val == '"' || strchr(val, PATH_SEP)) {
+               strbuf_addch(&quoted, '"');
+               quote_c_style(val, &quoted, NULL, 1);
+               strbuf_addch(&quoted, '"');
+               val = quoted.buf;
+       }
+
+       old = getenv(key);
        if (!old)
                argv_array_pushf(env, "%s=%s", key, val);
        else
                argv_array_pushf(env, "%s=%s%c%s", key, old, PATH_SEP, val);
+
+       strbuf_release(&quoted);
 }
 
 static void env_replace(struct argv_array *env, const char *key, const char *val)