diff options
Diffstat (limited to 'transport-helper.c')
-rw-r--r-- | transport-helper.c | 89 |
1 files changed, 48 insertions, 41 deletions
diff --git a/transport-helper.c b/transport-helper.c index 7dc4a443ae..0eb3cf01aa 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -97,6 +97,8 @@ static void do_take_over(struct transport *transport) free(data); } +static void standard_options(struct transport *t); + static struct child_process *get_helper(struct transport *transport) { struct helper_data *data = transport->data; @@ -211,6 +213,7 @@ static struct child_process *get_helper(struct transport *transport) strbuf_release(&buf); if (debug) fprintf(stderr, "Debug: Capabilities complete.\n"); + standard_options(transport); return data->helper; } @@ -254,7 +257,6 @@ static const char *boolean_options[] = { TRANS_OPT_THIN, TRANS_OPT_KEEP, TRANS_OPT_FOLLOWTAGS, - TRANS_OPT_PUSH_CERT }; static int set_helper_option(struct transport *transport, @@ -338,24 +340,13 @@ static int fetch_with_fetch(struct transport *transport, int i; struct strbuf buf = STRBUF_INIT; - standard_options(transport); - if (data->check_connectivity && - data->transport_options.check_self_contained_and_connected) - set_helper_option(transport, "check-connectivity", "true"); - - if (transport->cloning) - set_helper_option(transport, "cloning", "true"); - - if (data->transport_options.update_shallow) - set_helper_option(transport, "update-shallow", "true"); - for (i = 0; i < nr_heads; i++) { const struct ref *posn = to_fetch[i]; if (posn->status & REF_STATUS_UPTODATE) 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); } @@ -498,7 +489,8 @@ static int fetch_with_import(struct transport *transport, else private = xstrdup(name); if (private) { - read_ref(private, posn->old_sha1); + if (read_ref(private, posn->old_oid.hash) < 0) + die("Could not read ref %s", private); free(private); } } @@ -622,6 +614,16 @@ static int fetch(struct transport *transport, if (!count) return 0; + if (data->check_connectivity && + data->transport_options.check_self_contained_and_connected) + set_helper_option(transport, "check-connectivity", "true"); + + if (transport->cloning) + set_helper_option(transport, "cloning", "true"); + + if (data->transport_options.update_shallow) + set_helper_option(transport, "update-shallow", "true"); + if (data->fetch) return fetch_with_fetch(transport, nr_heads, to_fetch); @@ -754,13 +756,28 @@ 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); return ret; } +static void set_common_push_options(struct transport *transport, + const char *name, int flags) +{ + if (flags & TRANSPORT_PUSH_DRY_RUN) { + if (set_helper_option(transport, "dry-run", "true") != 0) + die("helper %s does not support dry-run", name); + } else if (flags & TRANSPORT_PUSH_CERT_ALWAYS) { + if (set_helper_option(transport, TRANS_OPT_PUSH_CERT, "true") != 0) + die("helper %s does not support --signed", name); + } else if (flags & TRANSPORT_PUSH_CERT_IF_ASKED) { + if (set_helper_option(transport, TRANS_OPT_PUSH_CERT, "if-asked") != 0) + die("helper %s does not support --signed=if-asked", name); + } +} + static int push_refs_with_push(struct transport *transport, struct ref *remote_refs, int flags) { @@ -801,7 +818,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); @@ -810,14 +827,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)); } } @@ -826,17 +843,9 @@ static int push_refs_with_push(struct transport *transport, return 0; } - standard_options(transport); for_each_string_list_item(cas_option, &cas_options) set_helper_option(transport, "cas", cas_option->string); - - if (flags & TRANSPORT_PUSH_DRY_RUN) { - if (set_helper_option(transport, "dry-run", "true") != 0) - die("helper %s does not support dry-run", data->name); - } else if (flags & TRANSPORT_PUSH_CERT) { - if (set_helper_option(transport, TRANS_OPT_PUSH_CERT, "true") != 0) - die("helper %s does not support --signed", data->name); - } + set_common_push_options(transport, data->name, flags); strbuf_addch(&buf, '\n'); sendline(data, &buf); @@ -857,14 +866,7 @@ static int push_refs_with_export(struct transport *transport, if (!data->refspecs) die("remote-helper doesn't support push; refspec needed"); - if (flags & TRANSPORT_PUSH_DRY_RUN) { - if (set_helper_option(transport, "dry-run", "true") != 0) - die("helper %s does not support dry-run", data->name); - } else if (flags & TRANSPORT_PUSH_CERT) { - if (set_helper_option(transport, TRANS_OPT_PUSH_CERT, "true") != 0) - die("helper %s does not support --signed", data->name); - } - + set_common_push_options(transport, data->name, flags); if (flags & TRANSPORT_PUSH_FORCE) { if (set_helper_option(transport, "force", "true") != 0) warning("helper %s does not support 'force'", data->name); @@ -876,13 +878,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); @@ -896,7 +898,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; @@ -1014,11 +1016,14 @@ 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; - read_ref((*tail)->name, (*tail)->old_sha1); + if (read_ref((*tail)->name, + (*tail)->old_oid.hash) < 0) + die(N_("Could not read ref %s"), + (*tail)->name); } } tail = &((*tail)->next); @@ -1038,6 +1043,8 @@ int transport_helper_init(struct transport *transport, const char *name) struct helper_data *data = xcalloc(1, sizeof(*data)); data->name = name; + transport_check_allowed(name); + if (getenv("GIT_TRANSPORT_HELPER_DEBUG")) debug = 1; |