{"thread":{"id":"9083","subject":"[PATCH 2/3] Add bundle transport","startedAt":"2007-07-17T22:49:53Z","lastAt":"2007-07-17T22:49:53Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"47682","messageId":"Pine.LNX.4.64.0707172349360.14781@racer.site","threadId":"9083","inReplyTo":null,"subject":"[PATCH 2/3] Add bundle transport","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-17T22:49:53Z","receivedAt":"2007-07-17T22:49:53Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n transport.c |   52 +++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 51 insertions(+), 1 deletions(-)\n\ndiff --git a/transport.c b/transport.c\nindex f444c5b..1532276 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -5,6 +5,7 @@\n #include \"pkt-line.h\"\n #include \"fetch-pack.h\"\n #include \"walker.h\"\n+#include \"bundle.h\"\n \n /* Generic functions for using commit walkers */\n \n@@ -185,7 +186,55 @@ static const struct transport_ops curl_transport = {\n \t/* disconnect */\tdisconnect_walker\n };\n \n+struct bundle_transport_data {\n+\tint fd;\n+\tstruct bundle_header header;\n+};\n+\n+static struct ref *get_refs_from_bundle(const struct transport *transport)\n+{\n+\tstruct bundle_transport_data *data = transport->data;\n+\tstruct ref *result = NULL;\n+\tint i;\n+\n+\tif (data->fd > 0)\n+\t\tclose(data->fd);\n+\tdata->fd = read_bundle_header(transport->url, &data->header);\n+\tif (data->fd < 0)\n+\t\tdie (\"Could not read bundle '%s'.\", transport->url);\n+\tfor (i = 0; i < data->header.references.nr; i++) {\n+\t\tstruct ref_list_entry *e = data->header.references.list + i;\n+\t\tstruct ref *ref = alloc_ref(strlen(e->name));\n+\t\thashcpy(ref->old_sha1, e->sha1);\n+\t\tstrcpy(ref->name, e->name);\n+\t\tref->next = result;\n+\t\tresult = ref;\n+\t}\n+\treturn result;\n+}\n+\n+static int fetch_refs_from_bundle(const struct transport *transport,\n+\t\t\t       int nr_heads, char **heads)\n+{\n+\tstruct bundle_transport_data *data = transport->data;\n+\treturn unbundle(&data->header, data->fd);\n+}\n+\n+static int close_bundle(struct transport *transport)\n+{\n+\tstruct bundle_transport_data *data = transport->data;\n+\tif (data->fd > 0)\n+\t\tclose(data->fd);\n+\treturn 0;\n+}\n+\n static const struct transport_ops bundle_transport = {\n+\t/* set_option */\tNULL,\n+\t/* get_refs_list */\tget_refs_from_bundle,\n+\t/* fetch_refs */\tfetch_refs_from_bundle,\n+\t/* fetch_objs */\tNULL,\n+\t/* push */\t\tNULL,\n+\t/* disconnect */\tclose_bundle\n };\n \n struct git_transport_data {\n@@ -359,8 +408,9 @@ struct transport *transport_get(struct remote *remote, const char *url,\n \t\telse\n \t\t\tret->data = NULL;\n \t} else if (is_local(url) && is_file(url)) {\n+\t\tstruct bundle_transport_data *data = xcalloc(1, sizeof(*data));\n \t\tret = xmalloc(sizeof(*ret));\n-\t\tret->data = NULL;\n+\t\tret->data = data;\n \t\tret->ops = &bundle_transport;\n \t} else {\n \t\tstruct git_transport_data *data = xcalloc(1, sizeof(*data));\n-- \n1.5.3.rc1.16.g9d6f-dirty\n"}]}