diff-highlight: use test_tick in graph test
[gitweb.git] / transport-helper.c
index 91aed35ebbc3cbb4fb9acbad55ab3de69e62d9f5..a72ed18efbfeedffb217a3d66daa9f2626cf6479 100644 (file)
@@ -44,8 +44,7 @@ static void sendline(struct helper_data *helper, struct strbuf *buffer)
 {
        if (debug)
                fprintf(stderr, "Debug: Remote helper: -> %s", buffer->buf);
-       if (write_in_full(helper->helper->in, buffer->buf, buffer->len)
-               != buffer->len)
+       if (write_in_full(helper->helper->in, buffer->buf, buffer->len) < 0)
                die_errno("Full write to remote helper failed");
 }
 
@@ -74,7 +73,7 @@ static void write_constant(int fd, const char *str)
 {
        if (debug)
                fprintf(stderr, "Debug: Remote helper: -> %s", str);
-       if (write_in_full(fd, str, strlen(str)) != strlen(str))
+       if (write_in_full(fd, str, strlen(str)) < 0)
                die_errno("Full write to remote helper failed");
 }
 
@@ -124,8 +123,9 @@ static struct child_process *get_helper(struct transport *transport)
        helper->git_cmd = 0;
        helper->silent_exec_failure = 1;
 
-       argv_array_pushf(&helper->env_array, "%s=%s", GIT_DIR_ENVIRONMENT,
-                        get_git_dir());
+       if (have_git_dir())
+               argv_array_pushf(&helper->env_array, "%s=%s",
+                                GIT_DIR_ENVIRONMENT, get_git_dir());
 
        code = start_command(helper);
        if (code < 0 && errno == ENOENT)
@@ -241,8 +241,7 @@ static int disconnect_helper(struct transport *transport)
                close(data->helper->out);
                fclose(data->out);
                res = finish_command(data->helper);
-               free(data->helper);
-               data->helper = NULL;
+               FREE_AND_NULL(data->helper);
        }
        return res;
 }
@@ -346,14 +345,11 @@ static int set_helper_option(struct transport *transport,
 static void standard_options(struct transport *t)
 {
        char buf[16];
-       int n;
        int v = t->verbose;
 
        set_helper_option(t, "progress", t->progress ? "true" : "false");
 
-       n = snprintf(buf, sizeof(buf), "%d", v + 1);
-       if (n >= sizeof(buf))
-               die("impossibly large verbosity value");
+       xsnprintf(buf, sizeof(buf), "%d", v + 1);
        set_helper_option(t, "verbosity", buf);
 
        switch (t->family) {
@@ -713,43 +709,35 @@ static int push_update_ref_status(struct strbuf *buf,
 
                if (!strcmp(msg, "no match")) {
                        status = REF_STATUS_NONE;
-                       free(msg);
-                       msg = NULL;
+                       FREE_AND_NULL(msg);
                }
                else if (!strcmp(msg, "up to date")) {
                        status = REF_STATUS_UPTODATE;
-                       free(msg);
-                       msg = NULL;
+                       FREE_AND_NULL(msg);
                }
                else if (!strcmp(msg, "non-fast forward")) {
                        status = REF_STATUS_REJECT_NONFASTFORWARD;
-                       free(msg);
-                       msg = NULL;
+                       FREE_AND_NULL(msg);
                }
                else if (!strcmp(msg, "already exists")) {
                        status = REF_STATUS_REJECT_ALREADY_EXISTS;
-                       free(msg);
-                       msg = NULL;
+                       FREE_AND_NULL(msg);
                }
                else if (!strcmp(msg, "fetch first")) {
                        status = REF_STATUS_REJECT_FETCH_FIRST;
-                       free(msg);
-                       msg = NULL;
+                       FREE_AND_NULL(msg);
                }
                else if (!strcmp(msg, "needs force")) {
                        status = REF_STATUS_REJECT_NEEDS_FORCE;
-                       free(msg);
-                       msg = NULL;
+                       FREE_AND_NULL(msg);
                }
                else if (!strcmp(msg, "stale info")) {
                        status = REF_STATUS_REJECT_STALE;
-                       free(msg);
-                       msg = NULL;
+                       FREE_AND_NULL(msg);
                }
                else if (!strcmp(msg, "forced update")) {
                        forced = 1;
-                       free(msg);
-                       msg = NULL;
+                       FREE_AND_NULL(msg);
                }
        }
 
@@ -826,6 +814,13 @@ static void set_common_push_options(struct transport *transport,
                if (set_helper_option(transport, TRANS_OPT_PUSH_CERT, "if-asked") != 0)
                        die("helper %s does not support --signed=if-asked", name);
        }
+
+       if (flags & TRANSPORT_PUSH_OPTIONS) {
+               struct string_list_item *item;
+               for_each_string_list_item(item, transport->push_options)
+                       if (set_helper_option(transport, "push-option", item->string) != 0)
+                               die("helper %s does not support 'push-option'", name);
+       }
 }
 
 static int push_refs_with_push(struct transport *transport,
@@ -1121,6 +1116,13 @@ int transport_helper_init(struct transport *transport, const char *name)
 __attribute__((format (printf, 1, 2)))
 static void transfer_debug(const char *fmt, ...)
 {
+       /*
+        * NEEDSWORK: This function is sometimes used from multiple threads, and
+        * we end up using debug_enabled racily. That "should not matter" since
+        * we always write the same value, but it's still wrong. This function
+        * is listed in .tsan-suppressions for the time being.
+        */
+
        va_list args;
        char msgbuf[PBUFFERSIZE];
        static int debug_enabled = -1;