Merge branch 'kb/msys2-tty' into maint
[gitweb.git] / transport-helper.c
index 63d54271b09d34dc21076205e6cecf88a56ab422..13b7a57a759c8f15d92cd3f61e22cdd0010db570 100644 (file)
@@ -54,7 +54,7 @@ static int recvline_fh(FILE *helper, struct strbuf *buffer, const char *name)
        strbuf_reset(buffer);
        if (debug)
                fprintf(stderr, "Debug: Remote helper: Waiting...\n");
-       if (strbuf_getline(buffer, helper, '\n') == EOF) {
+       if (strbuf_getline(buffer, helper) == EOF) {
                if (debug)
                        fprintf(stderr, "Debug: Remote helper quit.\n");
                return 1;
@@ -137,7 +137,8 @@ static struct child_process *get_helper(struct transport *transport)
        data->no_disconnect_req = 0;
 
        /*
-        * Open the output as FILE* so strbuf_getline() can be used.
+        * Open the output as FILE* so strbuf_getline_*() family of
+        * functions can be used.
         * Do this with duped fd because fclose() will close the fd,
         * and stuff like taking over will require the fd to remain.
         */
@@ -320,6 +321,21 @@ static void standard_options(struct transport *t)
        if (n >= sizeof(buf))
                die("impossibly large verbosity value");
        set_helper_option(t, "verbosity", buf);
+
+       switch (t->family) {
+       case TRANSPORT_FAMILY_ALL:
+               /*
+                * this is already the default,
+                * do not break old remote helpers by setting "all" here
+                */
+               break;
+       case TRANSPORT_FAMILY_IPV4:
+               set_helper_option(t, "family", "ipv4");
+               break;
+       case TRANSPORT_FAMILY_IPV6:
+               set_helper_option(t, "family", "ipv6");
+               break;
+       }
 }
 
 static int release_helper(struct transport *transport)
@@ -346,7 +362,7 @@ static int fetch_with_fetch(struct transport *transport,
                        continue;
 
                strbuf_addf(&buf, "fetch %s %s\n",
-                           sha1_to_hex(posn->old_sha1),
+                           oid_to_hex(&posn->old_oid),
                            posn->symref ? posn->symref : posn->name);
        }
 
@@ -489,7 +505,7 @@ static int fetch_with_import(struct transport *transport,
                else
                        private = xstrdup(name);
                if (private) {
-                       if (read_ref(private, posn->old_sha1) < 0)
+                       if (read_ref(private, posn->old_oid.hash) < 0)
                                die("Could not read ref %s", private);
                        free(private);
                }
@@ -756,7 +772,7 @@ static int push_update_refs_status(struct helper_data *data,
                private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
                if (!private)
                        continue;
-               update_ref("update by helper", private, ref->new_sha1, NULL, 0, 0);
+               update_ref("update by helper", private, ref->new_oid.hash, NULL, 0, 0);
                free(private);
        }
        strbuf_release(&buf);
@@ -818,7 +834,7 @@ static int push_refs_with_push(struct transport *transport,
                        if (ref->peer_ref)
                                strbuf_addstr(&buf, ref->peer_ref->name);
                        else
-                               strbuf_addstr(&buf, sha1_to_hex(ref->new_sha1));
+                               strbuf_addstr(&buf, oid_to_hex(&ref->new_oid));
                }
                strbuf_addch(&buf, ':');
                strbuf_addstr(&buf, ref->name);
@@ -827,14 +843,14 @@ static int push_refs_with_push(struct transport *transport,
                /*
                 * The "--force-with-lease" options without explicit
                 * values to expect have already been expanded into
-                * the ref->old_sha1_expect[] field; we can ignore
+                * the ref->old_oid_expect[] field; we can ignore
                 * transport->smart_options->cas altogether and instead
                 * can enumerate them from the refs.
                 */
                if (ref->expect_old_sha1) {
                        struct strbuf cas = STRBUF_INIT;
                        strbuf_addf(&cas, "%s:%s",
-                                   ref->name, sha1_to_hex(ref->old_sha1_expect));
+                                   ref->name, oid_to_hex(&ref->old_oid_expect));
                        string_list_append(&cas_options, strbuf_detach(&cas, NULL));
                }
        }
@@ -878,13 +894,13 @@ static int push_refs_with_export(struct transport *transport,
 
        for (ref = remote_refs; ref; ref = ref->next) {
                char *private;
-               unsigned char sha1[20];
+               struct object_id oid;
 
                private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
-               if (private && !get_sha1(private, sha1)) {
+               if (private && !get_sha1(private, oid.hash)) {
                        strbuf_addf(&buf, "^%s", private);
                        string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
-                       hashcpy(ref->old_sha1, sha1);
+                       oidcpy(&ref->old_oid, &oid);
                }
                free(private);
 
@@ -898,7 +914,7 @@ static int push_refs_with_export(struct transport *transport,
                                        name = resolve_ref_unsafe(
                                                 ref->peer_ref->name,
                                                 RESOLVE_REF_READING,
-                                                sha1, &flag);
+                                                oid.hash, &flag);
                                        if (!name || !(flag & REF_ISSYMREF))
                                                name = ref->peer_ref->name;
 
@@ -1016,12 +1032,12 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
                if (buf.buf[0] == '@')
                        (*tail)->symref = xstrdup(buf.buf + 1);
                else if (buf.buf[0] != '?')
-                       get_sha1_hex(buf.buf, (*tail)->old_sha1);
+                       get_oid_hex(buf.buf, &(*tail)->old_oid);
                if (eon) {
                        if (has_attribute(eon + 1, "unchanged")) {
                                (*tail)->status |= REF_STATUS_UPTODATE;
                                if (read_ref((*tail)->name,
-                                            (*tail)->old_sha1) < 0)
+                                            (*tail)->old_oid.hash) < 0)
                                        die(N_("Could not read ref %s"),
                                            (*tail)->name);
                        }
@@ -1136,7 +1152,7 @@ static void udt_close_if_finished(struct unidirectional_transfer *t)
 }
 
 /*
- * Tries to read read data from source into buffer. If buffer is full,
+ * Tries to read data from source into buffer. If buffer is full,
  * no data is read. Returns 0 on success, -1 on error.
  */
 static int udt_do_read(struct unidirectional_transfer *t)