c8705b78d640e87d686fba6d35c30a18646d83f8
   1#include "cache.h"
   2#include "transport.h"
   3#include "quote.h"
   4#include "run-command.h"
   5#include "commit.h"
   6#include "diff.h"
   7#include "revision.h"
   8#include "quote.h"
   9#include "remote.h"
  10
  11static int debug;
  12
  13struct helper_data
  14{
  15        const char *name;
  16        struct child_process *helper;
  17        FILE *out;
  18        unsigned fetch : 1,
  19                import : 1,
  20                option : 1,
  21                push : 1,
  22                connect : 1,
  23                no_disconnect_req : 1;
  24        /* These go from remote name (as in "list") to private name */
  25        struct refspec *refspecs;
  26        int refspec_nr;
  27        /* Transport options for fetch-pack/send-pack (should one of
  28         * those be invoked).
  29         */
  30        struct git_transport_options transport_options;
  31};
  32
  33static void sendline(struct helper_data *helper, struct strbuf *buffer)
  34{
  35        if (debug)
  36                fprintf(stderr, "Debug: Remote helper: -> %s", buffer->buf);
  37        if (write_in_full(helper->helper->in, buffer->buf, buffer->len)
  38                != buffer->len)
  39                die_errno("Full write to remote helper failed");
  40}
  41
  42static int recvline_fh(FILE *helper, struct strbuf *buffer)
  43{
  44        strbuf_reset(buffer);
  45        if (debug)
  46                fprintf(stderr, "Debug: Remote helper: Waiting...\n");
  47        if (strbuf_getline(buffer, helper, '\n') == EOF) {
  48                if (debug)
  49                        fprintf(stderr, "Debug: Remote helper quit.\n");
  50                exit(128);
  51        }
  52
  53        if (debug)
  54                fprintf(stderr, "Debug: Remote helper: <- %s\n", buffer->buf);
  55        return 0;
  56}
  57
  58static int recvline(struct helper_data *helper, struct strbuf *buffer)
  59{
  60        return recvline_fh(helper->out, buffer);
  61}
  62
  63static void xchgline(struct helper_data *helper, struct strbuf *buffer)
  64{
  65        sendline(helper, buffer);
  66        recvline(helper, buffer);
  67}
  68
  69static void write_constant(int fd, const char *str)
  70{
  71        if (debug)
  72                fprintf(stderr, "Debug: Remote helper: -> %s", str);
  73        if (write_in_full(fd, str, strlen(str)) != strlen(str))
  74                die_errno("Full write to remote helper failed");
  75}
  76
  77const char *remove_ext_force(const char *url)
  78{
  79        if (url) {
  80                const char *colon = strchr(url, ':');
  81                if (colon && colon[1] == ':')
  82                        return colon + 2;
  83        }
  84        return url;
  85}
  86
  87static void do_take_over(struct transport *transport)
  88{
  89        struct helper_data *data;
  90        data = (struct helper_data *)transport->data;
  91        transport_take_over(transport, data->helper);
  92        fclose(data->out);
  93        free(data);
  94}
  95
  96static struct child_process *get_helper(struct transport *transport)
  97{
  98        struct helper_data *data = transport->data;
  99        struct strbuf buf = STRBUF_INIT;
 100        struct child_process *helper;
 101        const char **refspecs = NULL;
 102        int refspec_nr = 0;
 103        int refspec_alloc = 0;
 104        int duped;
 105        int code;
 106
 107        if (data->helper)
 108                return data->helper;
 109
 110        helper = xcalloc(1, sizeof(*helper));
 111        helper->in = -1;
 112        helper->out = -1;
 113        helper->err = 0;
 114        helper->argv = xcalloc(4, sizeof(*helper->argv));
 115        strbuf_addf(&buf, "git-remote-%s", data->name);
 116        helper->argv[0] = strbuf_detach(&buf, NULL);
 117        helper->argv[1] = transport->remote->name;
 118        helper->argv[2] = remove_ext_force(transport->url);
 119        helper->git_cmd = 0;
 120        helper->silent_exec_failure = 1;
 121        code = start_command(helper);
 122        if (code < 0 && errno == ENOENT)
 123                die("Unable to find remote helper for '%s'", data->name);
 124        else if (code != 0)
 125                exit(code);
 126
 127        data->helper = helper;
 128        data->no_disconnect_req = 0;
 129
 130        /*
 131         * Open the output as FILE* so strbuf_getline() can be used.
 132         * Do this with duped fd because fclose() will close the fd,
 133         * and stuff like taking over will require the fd to remain.
 134         */
 135        duped = dup(helper->out);
 136        if (duped < 0)
 137                die_errno("Can't dup helper output fd");
 138        data->out = xfdopen(duped, "r");
 139
 140        write_constant(helper->in, "capabilities\n");
 141
 142        while (1) {
 143                const char *capname;
 144                int mandatory = 0;
 145                recvline(data, &buf);
 146
 147                if (!*buf.buf)
 148                        break;
 149
 150                if (*buf.buf == '*') {
 151                        capname = buf.buf + 1;
 152                        mandatory = 1;
 153                } else
 154                        capname = buf.buf;
 155
 156                if (debug)
 157                        fprintf(stderr, "Debug: Got cap %s\n", capname);
 158                if (!strcmp(capname, "fetch"))
 159                        data->fetch = 1;
 160                else if (!strcmp(capname, "option"))
 161                        data->option = 1;
 162                else if (!strcmp(capname, "push"))
 163                        data->push = 1;
 164                else if (!strcmp(capname, "import"))
 165                        data->import = 1;
 166                else if (!data->refspecs && !prefixcmp(capname, "refspec ")) {
 167                        ALLOC_GROW(refspecs,
 168                                   refspec_nr + 1,
 169                                   refspec_alloc);
 170                        refspecs[refspec_nr++] = strdup(buf.buf + strlen("refspec "));
 171                } else if (!strcmp(capname, "connect")) {
 172                        data->connect = 1;
 173                } else if (!strcmp(buf.buf, "gitdir")) {
 174                        struct strbuf gitdir = STRBUF_INIT;
 175                        strbuf_addf(&gitdir, "gitdir %s\n", get_git_dir());
 176                        sendline(data, &gitdir);
 177                        strbuf_release(&gitdir);
 178                } else if (mandatory) {
 179                        die("Unknown mandatory capability %s. This remote "
 180                            "helper probably needs newer version of Git.\n",
 181                            capname);
 182                }
 183        }
 184        if (refspecs) {
 185                int i;
 186                data->refspec_nr = refspec_nr;
 187                data->refspecs = parse_fetch_refspec(refspec_nr, refspecs);
 188                for (i = 0; i < refspec_nr; i++) {
 189                        free((char *)refspecs[i]);
 190                }
 191                free(refspecs);
 192        }
 193        strbuf_release(&buf);
 194        if (debug)
 195                fprintf(stderr, "Debug: Capabilities complete.\n");
 196        return data->helper;
 197}
 198
 199static int disconnect_helper(struct transport *transport)
 200{
 201        struct helper_data *data = transport->data;
 202        struct strbuf buf = STRBUF_INIT;
 203
 204        if (data->helper) {
 205                if (debug)
 206                        fprintf(stderr, "Debug: Disconnecting.\n");
 207                if (!data->no_disconnect_req) {
 208                        strbuf_addf(&buf, "\n");
 209                        sendline(data, &buf);
 210                }
 211                close(data->helper->in);
 212                close(data->helper->out);
 213                fclose(data->out);
 214                finish_command(data->helper);
 215                free((char *)data->helper->argv[0]);
 216                free(data->helper->argv);
 217                free(data->helper);
 218                data->helper = NULL;
 219        }
 220        return 0;
 221}
 222
 223static const char *unsupported_options[] = {
 224        TRANS_OPT_UPLOADPACK,
 225        TRANS_OPT_RECEIVEPACK,
 226        TRANS_OPT_THIN,
 227        TRANS_OPT_KEEP
 228        };
 229static const char *boolean_options[] = {
 230        TRANS_OPT_THIN,
 231        TRANS_OPT_KEEP,
 232        TRANS_OPT_FOLLOWTAGS
 233        };
 234
 235static int set_helper_option(struct transport *transport,
 236                          const char *name, const char *value)
 237{
 238        struct helper_data *data = transport->data;
 239        struct strbuf buf = STRBUF_INIT;
 240        int i, ret, is_bool = 0;
 241
 242        get_helper(transport);
 243
 244        if (!data->option)
 245                return 1;
 246
 247        for (i = 0; i < ARRAY_SIZE(unsupported_options); i++) {
 248                if (!strcmp(name, unsupported_options[i]))
 249                        return 1;
 250        }
 251
 252        for (i = 0; i < ARRAY_SIZE(boolean_options); i++) {
 253                if (!strcmp(name, boolean_options[i])) {
 254                        is_bool = 1;
 255                        break;
 256                }
 257        }
 258
 259        strbuf_addf(&buf, "option %s ", name);
 260        if (is_bool)
 261                strbuf_addstr(&buf, value ? "true" : "false");
 262        else
 263                quote_c_style(value, &buf, NULL, 0);
 264        strbuf_addch(&buf, '\n');
 265
 266        xchgline(data, &buf);
 267
 268        if (!strcmp(buf.buf, "ok"))
 269                ret = 0;
 270        else if (!prefixcmp(buf.buf, "error")) {
 271                ret = -1;
 272        } else if (!strcmp(buf.buf, "unsupported"))
 273                ret = 1;
 274        else {
 275                warning("%s unexpectedly said: '%s'", data->name, buf.buf);
 276                ret = 1;
 277        }
 278        strbuf_release(&buf);
 279        return ret;
 280}
 281
 282static void standard_options(struct transport *t)
 283{
 284        char buf[16];
 285        int n;
 286        int v = t->verbose;
 287
 288        set_helper_option(t, "progress", t->progress ? "true" : "false");
 289
 290        n = snprintf(buf, sizeof(buf), "%d", v + 1);
 291        if (n >= sizeof(buf))
 292                die("impossibly large verbosity value");
 293        set_helper_option(t, "verbosity", buf);
 294}
 295
 296static int release_helper(struct transport *transport)
 297{
 298        struct helper_data *data = transport->data;
 299        free_refspec(data->refspec_nr, data->refspecs);
 300        data->refspecs = NULL;
 301        disconnect_helper(transport);
 302        free(transport->data);
 303        return 0;
 304}
 305
 306static int fetch_with_fetch(struct transport *transport,
 307                            int nr_heads, struct ref **to_fetch)
 308{
 309        struct helper_data *data = transport->data;
 310        int i;
 311        struct strbuf buf = STRBUF_INIT;
 312
 313        standard_options(transport);
 314
 315        for (i = 0; i < nr_heads; i++) {
 316                const struct ref *posn = to_fetch[i];
 317                if (posn->status & REF_STATUS_UPTODATE)
 318                        continue;
 319
 320                strbuf_addf(&buf, "fetch %s %s\n",
 321                            sha1_to_hex(posn->old_sha1), posn->name);
 322        }
 323
 324        strbuf_addch(&buf, '\n');
 325        sendline(data, &buf);
 326
 327        while (1) {
 328                recvline(data, &buf);
 329
 330                if (!prefixcmp(buf.buf, "lock ")) {
 331                        const char *name = buf.buf + 5;
 332                        if (transport->pack_lockfile)
 333                                warning("%s also locked %s", data->name, name);
 334                        else
 335                                transport->pack_lockfile = xstrdup(name);
 336                }
 337                else if (!buf.len)
 338                        break;
 339                else
 340                        warning("%s unexpectedly said: '%s'", data->name, buf.buf);
 341        }
 342        strbuf_release(&buf);
 343        return 0;
 344}
 345
 346static int get_importer(struct transport *transport, struct child_process *fastimport)
 347{
 348        struct child_process *helper = get_helper(transport);
 349        memset(fastimport, 0, sizeof(*fastimport));
 350        fastimport->in = helper->out;
 351        fastimport->argv = xcalloc(5, sizeof(*fastimport->argv));
 352        fastimport->argv[0] = "fast-import";
 353        fastimport->argv[1] = "--quiet";
 354
 355        fastimport->git_cmd = 1;
 356        return start_command(fastimport);
 357}
 358
 359static int fetch_with_import(struct transport *transport,
 360                             int nr_heads, struct ref **to_fetch)
 361{
 362        struct child_process fastimport;
 363        struct helper_data *data = transport->data;
 364        int i;
 365        struct ref *posn;
 366        struct strbuf buf = STRBUF_INIT;
 367
 368        get_helper(transport);
 369
 370        if (get_importer(transport, &fastimport))
 371                die("Couldn't run fast-import");
 372
 373        for (i = 0; i < nr_heads; i++) {
 374                posn = to_fetch[i];
 375                if (posn->status & REF_STATUS_UPTODATE)
 376                        continue;
 377
 378                strbuf_addf(&buf, "import %s\n", posn->name);
 379                sendline(data, &buf);
 380                strbuf_reset(&buf);
 381        }
 382        disconnect_helper(transport);
 383        finish_command(&fastimport);
 384        free(fastimport.argv);
 385        fastimport.argv = NULL;
 386
 387        for (i = 0; i < nr_heads; i++) {
 388                char *private;
 389                posn = to_fetch[i];
 390                if (posn->status & REF_STATUS_UPTODATE)
 391                        continue;
 392                if (data->refspecs)
 393                        private = apply_refspecs(data->refspecs, data->refspec_nr, posn->name);
 394                else
 395                        private = strdup(posn->name);
 396                read_ref(private, posn->old_sha1);
 397                free(private);
 398        }
 399        strbuf_release(&buf);
 400        return 0;
 401}
 402
 403static int process_connect_service(struct transport *transport,
 404                                   const char *name, const char *exec)
 405{
 406        struct helper_data *data = transport->data;
 407        struct strbuf cmdbuf = STRBUF_INIT;
 408        struct child_process *helper;
 409        int r, duped, ret = 0;
 410        FILE *input;
 411
 412        helper = get_helper(transport);
 413
 414        /*
 415         * Yes, dup the pipe another time, as we need unbuffered version
 416         * of input pipe as FILE*. fclose() closes the underlying fd and
 417         * stream buffering only can be changed before first I/O operation
 418         * on it.
 419         */
 420        duped = dup(helper->out);
 421        if (duped < 0)
 422                die_errno("Can't dup helper output fd");
 423        input = xfdopen(duped, "r");
 424        setvbuf(input, NULL, _IONBF, 0);
 425
 426        /*
 427         * Handle --upload-pack and friends. This is fire and forget...
 428         * just warn if it fails.
 429         */
 430        if (strcmp(name, exec)) {
 431                r = set_helper_option(transport, "servpath", exec);
 432                if (r > 0)
 433                        warning("Setting remote service path not supported by protocol.");
 434                else if (r < 0)
 435                        warning("Invalid remote service path.");
 436        }
 437
 438        if (data->connect)
 439                strbuf_addf(&cmdbuf, "connect %s\n", name);
 440        else
 441                goto exit;
 442
 443        sendline(data, &cmdbuf);
 444        recvline_fh(input, &cmdbuf);
 445        if (!strcmp(cmdbuf.buf, "")) {
 446                data->no_disconnect_req = 1;
 447                if (debug)
 448                        fprintf(stderr, "Debug: Smart transport connection "
 449                                "ready.\n");
 450                ret = 1;
 451        } else if (!strcmp(cmdbuf.buf, "fallback")) {
 452                if (debug)
 453                        fprintf(stderr, "Debug: Falling back to dumb "
 454                                "transport.\n");
 455        } else
 456                die("Unknown response to connect: %s",
 457                        cmdbuf.buf);
 458
 459exit:
 460        fclose(input);
 461        return ret;
 462}
 463
 464static int process_connect(struct transport *transport,
 465                                     int for_push)
 466{
 467        struct helper_data *data = transport->data;
 468        const char *name;
 469        const char *exec;
 470
 471        name = for_push ? "git-receive-pack" : "git-upload-pack";
 472        if (for_push)
 473                exec = data->transport_options.receivepack;
 474        else
 475                exec = data->transport_options.uploadpack;
 476
 477        return process_connect_service(transport, name, exec);
 478}
 479
 480static int connect_helper(struct transport *transport, const char *name,
 481                   const char *exec, int fd[2])
 482{
 483        struct helper_data *data = transport->data;
 484
 485        /* Get_helper so connect is inited. */
 486        get_helper(transport);
 487        if (!data->connect)
 488                die("Operation not supported by protocol.");
 489
 490        if (!process_connect_service(transport, name, exec))
 491                die("Can't connect to subservice %s.", name);
 492
 493        fd[0] = data->helper->out;
 494        fd[1] = data->helper->in;
 495        return 0;
 496}
 497
 498static int fetch(struct transport *transport,
 499                 int nr_heads, struct ref **to_fetch)
 500{
 501        struct helper_data *data = transport->data;
 502        int i, count;
 503
 504        if (process_connect(transport, 0)) {
 505                do_take_over(transport);
 506                return transport->fetch(transport, nr_heads, to_fetch);
 507        }
 508
 509        count = 0;
 510        for (i = 0; i < nr_heads; i++)
 511                if (!(to_fetch[i]->status & REF_STATUS_UPTODATE))
 512                        count++;
 513
 514        if (!count)
 515                return 0;
 516
 517        if (data->fetch)
 518                return fetch_with_fetch(transport, nr_heads, to_fetch);
 519
 520        if (data->import)
 521                return fetch_with_import(transport, nr_heads, to_fetch);
 522
 523        return -1;
 524}
 525
 526static int push_refs(struct transport *transport,
 527                struct ref *remote_refs, int flags)
 528{
 529        int force_all = flags & TRANSPORT_PUSH_FORCE;
 530        int mirror = flags & TRANSPORT_PUSH_MIRROR;
 531        struct helper_data *data = transport->data;
 532        struct strbuf buf = STRBUF_INIT;
 533        struct child_process *helper;
 534        struct ref *ref;
 535
 536        if (process_connect(transport, 1)) {
 537                do_take_over(transport);
 538                return transport->push_refs(transport, remote_refs, flags);
 539        }
 540
 541        if (!remote_refs) {
 542                fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
 543                        "Perhaps you should specify a branch such as 'master'.\n");
 544                return 0;
 545        }
 546
 547        helper = get_helper(transport);
 548        if (!data->push)
 549                return 1;
 550
 551        for (ref = remote_refs; ref; ref = ref->next) {
 552                if (!ref->peer_ref && !mirror)
 553                        continue;
 554
 555                /* Check for statuses set by set_ref_status_for_push() */
 556                switch (ref->status) {
 557                case REF_STATUS_REJECT_NONFASTFORWARD:
 558                case REF_STATUS_UPTODATE:
 559                        continue;
 560                default:
 561                        ; /* do nothing */
 562                }
 563
 564                if (force_all)
 565                        ref->force = 1;
 566
 567                strbuf_addstr(&buf, "push ");
 568                if (!ref->deletion) {
 569                        if (ref->force)
 570                                strbuf_addch(&buf, '+');
 571                        if (ref->peer_ref)
 572                                strbuf_addstr(&buf, ref->peer_ref->name);
 573                        else
 574                                strbuf_addstr(&buf, sha1_to_hex(ref->new_sha1));
 575                }
 576                strbuf_addch(&buf, ':');
 577                strbuf_addstr(&buf, ref->name);
 578                strbuf_addch(&buf, '\n');
 579        }
 580        if (buf.len == 0)
 581                return 0;
 582
 583        standard_options(transport);
 584
 585        if (flags & TRANSPORT_PUSH_DRY_RUN) {
 586                if (set_helper_option(transport, "dry-run", "true") != 0)
 587                        die("helper %s does not support dry-run", data->name);
 588        }
 589
 590        strbuf_addch(&buf, '\n');
 591        sendline(data, &buf);
 592
 593        ref = remote_refs;
 594        while (1) {
 595                char *refname, *msg;
 596                int status;
 597
 598                recvline(data, &buf);
 599                if (!buf.len)
 600                        break;
 601
 602                if (!prefixcmp(buf.buf, "ok ")) {
 603                        status = REF_STATUS_OK;
 604                        refname = buf.buf + 3;
 605                } else if (!prefixcmp(buf.buf, "error ")) {
 606                        status = REF_STATUS_REMOTE_REJECT;
 607                        refname = buf.buf + 6;
 608                } else
 609                        die("expected ok/error, helper said '%s'\n", buf.buf);
 610
 611                msg = strchr(refname, ' ');
 612                if (msg) {
 613                        struct strbuf msg_buf = STRBUF_INIT;
 614                        const char *end;
 615
 616                        *msg++ = '\0';
 617                        if (!unquote_c_style(&msg_buf, msg, &end))
 618                                msg = strbuf_detach(&msg_buf, NULL);
 619                        else
 620                                msg = xstrdup(msg);
 621                        strbuf_release(&msg_buf);
 622
 623                        if (!strcmp(msg, "no match")) {
 624                                status = REF_STATUS_NONE;
 625                                free(msg);
 626                                msg = NULL;
 627                        }
 628                        else if (!strcmp(msg, "up to date")) {
 629                                status = REF_STATUS_UPTODATE;
 630                                free(msg);
 631                                msg = NULL;
 632                        }
 633                        else if (!strcmp(msg, "non-fast forward")) {
 634                                status = REF_STATUS_REJECT_NONFASTFORWARD;
 635                                free(msg);
 636                                msg = NULL;
 637                        }
 638                }
 639
 640                if (ref)
 641                        ref = find_ref_by_name(ref, refname);
 642                if (!ref)
 643                        ref = find_ref_by_name(remote_refs, refname);
 644                if (!ref) {
 645                        warning("helper reported unexpected status of %s", refname);
 646                        continue;
 647                }
 648
 649                if (ref->status != REF_STATUS_NONE) {
 650                        /*
 651                         * Earlier, the ref was marked not to be pushed, so ignore the ref
 652                         * status reported by the remote helper if the latter is 'no match'.
 653                         */
 654                        if (status == REF_STATUS_NONE)
 655                                continue;
 656                }
 657
 658                ref->status = status;
 659                ref->remote_status = msg;
 660        }
 661        strbuf_release(&buf);
 662        return 0;
 663}
 664
 665static int has_attribute(const char *attrs, const char *attr) {
 666        int len;
 667        if (!attrs)
 668                return 0;
 669
 670        len = strlen(attr);
 671        for (;;) {
 672                const char *space = strchrnul(attrs, ' ');
 673                if (len == space - attrs && !strncmp(attrs, attr, len))
 674                        return 1;
 675                if (!*space)
 676                        return 0;
 677                attrs = space + 1;
 678        }
 679}
 680
 681static struct ref *get_refs_list(struct transport *transport, int for_push)
 682{
 683        struct helper_data *data = transport->data;
 684        struct child_process *helper;
 685        struct ref *ret = NULL;
 686        struct ref **tail = &ret;
 687        struct ref *posn;
 688        struct strbuf buf = STRBUF_INIT;
 689
 690        helper = get_helper(transport);
 691
 692        if (process_connect(transport, for_push)) {
 693                do_take_over(transport);
 694                return transport->get_refs_list(transport, for_push);
 695        }
 696
 697        if (data->push && for_push)
 698                write_str_in_full(helper->in, "list for-push\n");
 699        else
 700                write_str_in_full(helper->in, "list\n");
 701
 702        while (1) {
 703                char *eov, *eon;
 704                recvline(data, &buf);
 705
 706                if (!*buf.buf)
 707                        break;
 708
 709                eov = strchr(buf.buf, ' ');
 710                if (!eov)
 711                        die("Malformed response in ref list: %s", buf.buf);
 712                eon = strchr(eov + 1, ' ');
 713                *eov = '\0';
 714                if (eon)
 715                        *eon = '\0';
 716                *tail = alloc_ref(eov + 1);
 717                if (buf.buf[0] == '@')
 718                        (*tail)->symref = xstrdup(buf.buf + 1);
 719                else if (buf.buf[0] != '?')
 720                        get_sha1_hex(buf.buf, (*tail)->old_sha1);
 721                if (eon) {
 722                        if (has_attribute(eon + 1, "unchanged")) {
 723                                (*tail)->status |= REF_STATUS_UPTODATE;
 724                                read_ref((*tail)->name, (*tail)->old_sha1);
 725                        }
 726                }
 727                tail = &((*tail)->next);
 728        }
 729        if (debug)
 730                fprintf(stderr, "Debug: Read ref listing.\n");
 731        strbuf_release(&buf);
 732
 733        for (posn = ret; posn; posn = posn->next)
 734                resolve_remote_symref(posn, ret);
 735
 736        return ret;
 737}
 738
 739int transport_helper_init(struct transport *transport, const char *name)
 740{
 741        struct helper_data *data = xcalloc(sizeof(*data), 1);
 742        data->name = name;
 743
 744        if (getenv("GIT_TRANSPORT_HELPER_DEBUG"))
 745                debug = 1;
 746
 747        transport->data = data;
 748        transport->set_option = set_helper_option;
 749        transport->get_refs_list = get_refs_list;
 750        transport->fetch = fetch;
 751        transport->push_refs = push_refs;
 752        transport->disconnect = release_helper;
 753        transport->connect = connect_helper;
 754        transport->smart_options = &(data->transport_options);
 755        return 0;
 756}