replace-object.c: mark more strings for translation
[gitweb.git] / transport-helper.c
index 11f1055b47e5e204a272e3588f74f161bdf73895..9f487cc9051adb74b46beba013bf74c951861d43 100644 (file)
@@ -11,6 +11,7 @@
 #include "sigchain.h"
 #include "argv-array.h"
 #include "refs.h"
+#include "refspec.h"
 #include "transport-internal.h"
 #include "protocol.h"
 
@@ -35,8 +36,7 @@ struct helper_data {
        char *export_marks;
        char *import_marks;
        /* These go from remote name (as in "list") to private name */
-       struct refspec *refspecs;
-       int refspec_nr;
+       struct refspec rs;
        /* Transport options for fetch-pack/send-pack (should one of
         * those be invoked).
         */
@@ -48,7 +48,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) < 0)
-               die_errno("Full write to remote helper failed");
+               die_errno("full write to remote helper failed");
 }
 
 static int recvline_fh(FILE *helper, struct strbuf *buffer)
@@ -77,7 +77,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)) < 0)
-               die_errno("Full write to remote helper failed");
+               die_errno("full write to remote helper failed");
 }
 
 static const char *remove_ext_force(const char *url)
@@ -106,9 +106,6 @@ static struct child_process *get_helper(struct transport *transport)
        struct helper_data *data = transport->data;
        struct strbuf buf = STRBUF_INIT;
        struct child_process *helper;
-       const char **refspecs = NULL;
-       int refspec_nr = 0;
-       int refspec_alloc = 0;
        int duped;
        int code;
 
@@ -132,12 +129,13 @@ static struct child_process *get_helper(struct transport *transport)
 
        code = start_command(helper);
        if (code < 0 && errno == ENOENT)
-               die("Unable to find remote helper for '%s'", data->name);
+               die("unable to find remote helper for '%s'", data->name);
        else if (code != 0)
                exit(code);
 
        data->helper = helper;
        data->no_disconnect_req = 0;
+       refspec_init(&data->rs, REFSPEC_FETCH);
 
        /*
         * Open the output as FILE* so strbuf_getline_*() family of
@@ -147,7 +145,7 @@ static struct child_process *get_helper(struct transport *transport)
         */
        duped = dup(helper->out);
        if (duped < 0)
-               die_errno("Can't dup helper output fd");
+               die_errno("can't dup helper output fd");
        data->out = xfdopen(duped, "r");
 
        write_constant(helper->in, "capabilities\n");
@@ -183,11 +181,8 @@ static struct child_process *get_helper(struct transport *transport)
                        data->export = 1;
                else if (!strcmp(capname, "check-connectivity"))
                        data->check_connectivity = 1;
-               else if (!data->refspecs && skip_prefix(capname, "refspec ", &arg)) {
-                       ALLOC_GROW(refspecs,
-                                  refspec_nr + 1,
-                                  refspec_alloc);
-                       refspecs[refspec_nr++] = xstrdup(arg);
+               else if (skip_prefix(capname, "refspec ", &arg)) {
+                       refspec_append(&data->rs, arg);
                } else if (!strcmp(capname, "connect")) {
                        data->connect = 1;
                } else if (!strcmp(capname, "stateless-connect")) {
@@ -201,20 +196,13 @@ static struct child_process *get_helper(struct transport *transport)
                } else if (starts_with(capname, "no-private-update")) {
                        data->no_private_update = 1;
                } else if (mandatory) {
-                       die("Unknown mandatory capability %s. This remote "
-                           "helper probably needs newer version of Git.",
+                       die("unknown mandatory capability %s; this remote "
+                           "helper probably needs newer version of Git",
                            capname);
                }
        }
-       if (refspecs) {
-               int i;
-               data->refspec_nr = refspec_nr;
-               data->refspecs = parse_fetch_refspec(refspec_nr, refspecs);
-               for (i = 0; i < refspec_nr; i++)
-                       free((char *)refspecs[i]);
-               free(refspecs);
-       } else if (data->import || data->bidi_import || data->export) {
-               warning("This remote helper should implement refspec capability.");
+       if (!data->rs.nr && (data->import || data->bidi_import || data->export)) {
+               warning("this remote helper should implement refspec capability");
        }
        strbuf_release(&buf);
        if (debug)
@@ -377,8 +365,7 @@ static int release_helper(struct transport *transport)
 {
        int res = 0;
        struct helper_data *data = transport->data;
-       free_refspec(data->refspec_nr, data->refspecs);
-       data->refspecs = NULL;
+       refspec_clear(&data->rs);
        res = disconnect_helper(transport);
        free(transport->data);
        return res;
@@ -489,7 +476,7 @@ static int fetch_with_import(struct transport *transport,
        get_helper(transport);
 
        if (get_importer(transport, &fastimport))
-               die("Couldn't run fast-import");
+               die("couldn't run fast-import");
 
        for (i = 0; i < nr_heads; i++) {
                posn = to_fetch[i];
@@ -512,7 +499,7 @@ static int fetch_with_import(struct transport *transport,
         */
 
        if (finish_command(&fastimport))
-               die("Error while running fast-import");
+               die("error while running fast-import");
 
        /*
         * The fast-import stream of a remote helper that advertises
@@ -535,13 +522,13 @@ static int fetch_with_import(struct transport *transport,
                if (posn->status & REF_STATUS_UPTODATE)
                        continue;
                name = posn->symref ? posn->symref : posn->name;
-               if (data->refspecs)
-                       private = apply_refspecs(data->refspecs, data->refspec_nr, name);
+               if (data->rs.nr)
+                       private = apply_refspecs(&data->rs, name);
                else
                        private = xstrdup(name);
                if (private) {
                        if (read_ref(private, &posn->old_oid) < 0)
-                               die("Could not read ref %s", private);
+                               die("could not read ref %s", private);
                        free(private);
                }
        }
@@ -567,7 +554,7 @@ static int run_connect(struct transport *transport, struct strbuf *cmdbuf)
         */
        duped = dup(helper->out);
        if (duped < 0)
-               die_errno("Can't dup helper output fd");
+               die_errno("can't dup helper output fd");
        input = xfdopen(duped, "r");
        setvbuf(input, NULL, _IONBF, 0);
 
@@ -586,7 +573,7 @@ static int run_connect(struct transport *transport, struct strbuf *cmdbuf)
                        fprintf(stderr, "Debug: Falling back to dumb "
                                "transport.\n");
        } else {
-               die("Unknown response to connect: %s",
+               die("unknown response to connect: %s",
                        cmdbuf->buf);
        }
 
@@ -608,9 +595,9 @@ static int process_connect_service(struct transport *transport,
        if (strcmp(name, exec)) {
                int r = set_helper_option(transport, "servpath", exec);
                if (r > 0)
-                       warning("Setting remote service path not supported by protocol.");
+                       warning("setting remote service path not supported by protocol");
                else if (r < 0)
-                       warning("Invalid remote service path.");
+                       warning("invalid remote service path");
        }
 
        if (data->connect) {
@@ -653,10 +640,10 @@ static int connect_helper(struct transport *transport, const char *name,
        /* Get_helper so connect is inited. */
        get_helper(transport);
        if (!data->connect)
-               die("Operation not supported by protocol.");
+               die("operation not supported by protocol");
 
        if (!process_connect_service(transport, name, exec))
-               die("Can't connect to subservice %s.", name);
+               die("can't connect to subservice %s", name);
 
        fd[0] = data->helper->out;
        fd[1] = data->helper->in;
@@ -814,11 +801,11 @@ static int push_update_refs_status(struct helper_data *data,
                if (push_update_ref_status(&buf, &ref, remote_refs))
                        continue;
 
-               if (flags & TRANSPORT_PUSH_DRY_RUN || !data->refspecs || data->no_private_update)
+               if (flags & TRANSPORT_PUSH_DRY_RUN || !data->rs.nr || data->no_private_update)
                        continue;
 
                /* propagate back the update to the remote namespace */
-               private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
+               private = apply_refspecs(&data->rs, ref->name);
                if (!private)
                        continue;
                update_ref("update by helper", private, &ref->new_oid, NULL,
@@ -938,7 +925,7 @@ static int push_refs_with_export(struct transport *transport,
        struct string_list revlist_args = STRING_LIST_INIT_DUP;
        struct strbuf buf = STRBUF_INIT;
 
-       if (!data->refspecs)
+       if (!data->rs.nr)
                die("remote-helper doesn't support push; refspec needed");
 
        set_common_push_options(transport, data->name, flags);
@@ -955,7 +942,7 @@ static int push_refs_with_export(struct transport *transport,
                char *private;
                struct object_id oid;
 
-               private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
+               private = apply_refspecs(&data->rs, ref->name);
                if (private && !get_oid(private, &oid)) {
                        strbuf_addf(&buf, "^%s", private);
                        string_list_append_nodup(&revlist_args,
@@ -991,12 +978,12 @@ static int push_refs_with_export(struct transport *transport,
        }
 
        if (get_exporter(transport, &exporter, &revlist_args))
-               die("Couldn't run fast-export");
+               die("couldn't run fast-export");
 
        string_list_clear(&revlist_args, 1);
 
        if (finish_command(&exporter))
-               die("Error while running fast-export");
+               die("error while running fast-export");
        if (push_update_refs_status(data, remote_refs, flags))
                return 1;
 
@@ -1083,7 +1070,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push,
 
                eov = strchr(buf.buf, ' ');
                if (!eov)
-                       die("Malformed response in ref list: %s", buf.buf);
+                       die("malformed response in ref list: %s", buf.buf);
                eon = strchr(eov + 1, ' ');
                *eov = '\0';
                if (eon)
@@ -1097,7 +1084,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push,
                        if (has_attribute(eon + 1, "unchanged")) {
                                (*tail)->status |= REF_STATUS_UPTODATE;
                                if (read_ref((*tail)->name, &(*tail)->old_oid) < 0)
-                                       die(_("Could not read ref %s"),
+                                       die(_("could not read ref %s"),
                                            (*tail)->name);
                        }
                }
@@ -1335,11 +1322,11 @@ static int tloop_spawnwait_tasks(struct bidirectional_transfer_state *s)
        err = pthread_create(&gtp_thread, NULL, udt_copy_task_routine,
                &s->gtp);
        if (err)
-               die("Can't start thread for copying data: %s", strerror(err));
+               die("can't start thread for copying data: %s", strerror(err));
        err = pthread_create(&ptg_thread, NULL, udt_copy_task_routine,
                &s->ptg);
        if (err)
-               die("Can't start thread for copying data: %s", strerror(err));
+               die("can't start thread for copying data: %s", strerror(err));
 
        ret |= tloop_join(gtp_thread, "Git to program copy");
        ret |= tloop_join(ptg_thread, "Program to git copy");
@@ -1398,7 +1385,7 @@ static int tloop_spawnwait_tasks(struct bidirectional_transfer_state *s)
        /* Fork thread #1: git to program. */
        pid1 = fork();
        if (pid1 < 0)
-               die_errno("Can't start thread for copying data");
+               die_errno("can't start thread for copying data");
        else if (pid1 == 0) {
                udt_kill_transfer(&s->ptg);
                exit(udt_copy_task_routine(&s->gtp) ? 0 : 1);
@@ -1407,7 +1394,7 @@ static int tloop_spawnwait_tasks(struct bidirectional_transfer_state *s)
        /* Fork thread #2: program to git. */
        pid2 = fork();
        if (pid2 < 0)
-               die_errno("Can't start thread for copying data");
+               die_errno("can't start thread for copying data");
        else if (pid2 == 0) {
                udt_kill_transfer(&s->gtp);
                exit(udt_copy_task_routine(&s->ptg) ? 0 : 1);