Merge branch 'mm/die-with-dashdash-help'
[gitweb.git] / transport-helper.c
index 4eab844d4abfa29ce53b6245a5821ee7be03641b..cfe098849022fcc56bcb1a57d00e4c89e753492b 100644 (file)
@@ -9,6 +9,7 @@
 #include "remote.h"
 #include "string-list.h"
 #include "thread-utils.h"
+#include "sigchain.h"
 
 static int debug;
 
@@ -183,7 +184,7 @@ static struct child_process *get_helper(struct transport *transport)
                        ALLOC_GROW(refspecs,
                                   refspec_nr + 1,
                                   refspec_alloc);
-                       refspecs[refspec_nr++] = strdup(capname + strlen("refspec "));
+                       refspecs[refspec_nr++] = xstrdup(capname + strlen("refspec "));
                } else if (!strcmp(capname, "connect")) {
                        data->connect = 1;
                } else if (!prefixcmp(capname, "export-marks ")) {
@@ -198,7 +199,7 @@ static struct child_process *get_helper(struct transport *transport)
                        data->import_marks = strbuf_detach(&arg, NULL);
                } else if (mandatory) {
                        die("Unknown mandatory capability %s. This remote "
-                           "helper probably needs newer version of Git.\n",
+                           "helper probably needs newer version of Git.",
                            capname);
                }
        }
@@ -220,15 +221,21 @@ static struct child_process *get_helper(struct transport *transport)
 static int disconnect_helper(struct transport *transport)
 {
        struct helper_data *data = transport->data;
-       struct strbuf buf = STRBUF_INIT;
        int res = 0;
 
        if (data->helper) {
                if (debug)
                        fprintf(stderr, "Debug: Disconnecting.\n");
                if (!data->no_disconnect_req) {
-                       strbuf_addf(&buf, "\n");
-                       sendline(data, &buf);
+                       /*
+                        * Ignore write errors; there's nothing we can do,
+                        * since we're about to close the pipe anyway. And the
+                        * most likely error is EPIPE due to the helper dying
+                        * to report an error itself.
+                        */
+                       sigchain_push(SIGPIPE, SIG_IGN);
+                       xwrite(data->helper->in, "\n", 1);
+                       sigchain_pop(SIGPIPE);
                }
                close(data->helper->in);
                close(data->helper->out);
@@ -437,6 +444,21 @@ static int fetch_with_import(struct transport *transport,
        free(fastimport.argv);
        fastimport.argv = NULL;
 
+       /*
+        * The fast-import stream of a remote helper that advertises
+        * the "refspec" capability writes to the refs named after the
+        * right hand side of the first refspec matching each ref we
+        * were fetching.
+        *
+        * (If no "refspec" capability was specified, for historical
+        * reasons we default to *:*.)
+        *
+        * Store the result in to_fetch[i].old_sha1.  Callers such
+        * as "git fetch" can use the value to write feedback to the
+        * terminal, populate FETCH_HEAD, and determine what new value
+        * should be written to peer_ref if the update is a
+        * fast-forward or this is a forced update.
+        */
        for (i = 0; i < nr_heads; i++) {
                char *private;
                posn = to_fetch[i];
@@ -445,9 +467,11 @@ static int fetch_with_import(struct transport *transport,
                if (data->refspecs)
                        private = apply_refspecs(data->refspecs, data->refspec_nr, posn->name);
                else
-                       private = strdup(posn->name);
-               read_ref(private, posn->old_sha1);
-               free(private);
+                       private = xstrdup(posn->name);
+               if (private) {
+                       read_ref(private, posn->old_sha1);
+                       free(private);
+               }
        }
        strbuf_release(&buf);
        return 0;
@@ -590,7 +614,7 @@ static void push_update_ref_status(struct strbuf *buf,
                status = REF_STATUS_REMOTE_REJECT;
                refname = buf->buf + 6;
        } else
-               die("expected ok/error, helper said '%s'\n", buf->buf);
+               die("expected ok/error, helper said '%s'", buf->buf);
 
        msg = strchr(refname, ' ');
        if (msg) {