]> git.ipfire.org Git - thirdparty/git.git/blobdiff - transport.c
strvec: drop argv_array compatibility layer
[thirdparty/git.git] / transport.c
index 7d50c502adfb6c24be91c8b07260c61a0add5340..2d4fd851dc0f8f317e3925e84d2567ff7467fc7f 100644 (file)
@@ -127,7 +127,7 @@ struct bundle_transport_data {
 
 static struct ref *get_refs_from_bundle(struct transport *transport,
                                        int for_push,
-                                       const struct argv_array *ref_prefixes)
+                                       const struct strvec *ref_prefixes)
 {
        struct bundle_transport_data *data = transport->data;
        struct ref *result = NULL;
@@ -143,6 +143,9 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
        data->fd = read_bundle_header(transport->url, &data->header);
        if (data->fd < 0)
                die(_("could not read bundle '%s'"), transport->url);
+
+       transport->hash_algo = data->header.hash_algo;
+
        for (i = 0; i < data->header.references.nr; i++) {
                struct ref_list_entry *e = data->header.references.list + i;
                struct ref *ref = alloc_ref(e->name);
@@ -157,11 +160,14 @@ static int fetch_refs_from_bundle(struct transport *transport,
                               int nr_heads, struct ref **to_fetch)
 {
        struct bundle_transport_data *data = transport->data;
+       int ret;
 
        if (!data->get_refs_from_bundle_called)
                get_refs_from_bundle(transport, 0, NULL);
-       return unbundle(the_repository, &data->header, data->fd,
-                       transport->progress ? BUNDLE_VERBOSE : 0);
+       ret = unbundle(the_repository, &data->header, data->fd,
+                          transport->progress ? BUNDLE_VERBOSE : 0);
+       transport->hash_algo = data->header.hash_algo;
+       return ret;
 }
 
 static int close_bundle(struct transport *transport)
@@ -277,7 +283,7 @@ static void die_if_server_options(struct transport *transport)
  * remote refs.
  */
 static struct ref *handshake(struct transport *transport, int for_push,
-                            const struct argv_array *ref_prefixes,
+                            const struct strvec *ref_prefixes,
                             int must_list_refs)
 {
        struct git_transport_data *data = transport->data;
@@ -312,6 +318,7 @@ static struct ref *handshake(struct transport *transport, int for_push,
                BUG("unknown protocol version");
        }
        data->got_remote_heads = 1;
+       transport->hash_algo = reader.hash_algo;
 
        if (reader.line_peeked)
                BUG("buffer must be empty at the end of handshake()");
@@ -320,7 +327,7 @@ static struct ref *handshake(struct transport *transport, int for_push,
 }
 
 static struct ref *get_refs_via_connect(struct transport *transport, int for_push,
-                                       const struct argv_array *ref_prefixes)
+                                       const struct strvec *ref_prefixes)
 {
        return handshake(transport, for_push, ref_prefixes, 1);
 }
@@ -378,7 +385,7 @@ static int fetch_refs_via_pack(struct transport *transport,
        refs = fetch_pack(&args, data->fd,
                          refs_tmp ? refs_tmp : transport->remote_refs,
                          to_fetch, nr_heads, &data->shallow,
-                         &transport->pack_lockfile, data->version);
+                         &transport->pack_lockfiles, data->version);
 
        close(data->fd[0]);
        close(data->fd[1]);
@@ -921,6 +928,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
        struct transport *ret = xcalloc(1, sizeof(*ret));
 
        ret->progress = isatty(2);
+       string_list_init(&ret->pack_lockfiles, 1);
 
        if (!remote)
                BUG("No remote provided to transport_get()");
@@ -988,9 +996,16 @@ struct transport *transport_get(struct remote *remote, const char *url)
                        ret->smart_options->receivepack = remote->receivepack;
        }
 
+       ret->hash_algo = &hash_algos[GIT_HASH_SHA1];
+
        return ret;
 }
 
+const struct git_hash_algo *transport_get_hash_algo(struct transport *transport)
+{
+       return transport->hash_algo;
+}
+
 int transport_set_option(struct transport *transport,
                         const char *name, const char *value)
 {
@@ -1138,7 +1153,7 @@ int transport_push(struct repository *r,
                int porcelain = flags & TRANSPORT_PUSH_PORCELAIN;
                int pretend = flags & TRANSPORT_PUSH_DRY_RUN;
                int push_ret, ret, err;
-               struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
+               struct strvec ref_prefixes = STRVEC_INIT;
 
                if (check_push_refs(local_refs, rs) < 0)
                        return -1;
@@ -1150,7 +1165,7 @@ int transport_push(struct repository *r,
                                                               &ref_prefixes);
                trace2_region_leave("transport_push", "get_refs_list", r);
 
-               argv_array_clear(&ref_prefixes);
+               strvec_clear(&ref_prefixes);
 
                if (flags & TRANSPORT_PUSH_ALL)
                        match_flags |= MATCH_REFS_ALL;
@@ -1266,7 +1281,7 @@ int transport_push(struct repository *r,
 }
 
 const struct ref *transport_get_remote_refs(struct transport *transport,
-                                           const struct argv_array *ref_prefixes)
+                                           const struct strvec *ref_prefixes)
 {
        if (!transport->got_remote_refs) {
                transport->remote_refs =
@@ -1316,10 +1331,11 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
 
 void transport_unlock_pack(struct transport *transport)
 {
-       if (transport->pack_lockfile) {
-               unlink_or_warn(transport->pack_lockfile);
-               FREE_AND_NULL(transport->pack_lockfile);
-       }
+       int i;
+
+       for (i = 0; i < transport->pack_lockfiles.nr; i++)
+               unlink_or_warn(transport->pack_lockfiles.items[i].string);
+       string_list_clear(&transport->pack_lockfiles, 0);
 }
 
 int transport_connect(struct transport *transport, const char *name,