X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=transport.c;h=56831c57c5cf6500714c46c63581ca98662d58c3;hb=6e13921b4f7adcc7316a76c0c4955b85b1589a65;hp=497f85372173f6f270a4c0ee9474f165bb884413;hpb=f1a8cc635455a65567d040349327b9ea4adb479b;p=git.git diff --git a/transport.c b/transport.c index 497f85372..56831c57c 100644 --- a/transport.c +++ b/transport.c @@ -75,7 +75,7 @@ static int read_loose_refs(struct strbuf *path, int name_offset, if (fd < 0) continue; - next = alloc_ref(path->len - name_offset + 1); + next = alloc_ref(path->buf + name_offset); if (read_in_full(fd, buffer, 40) != 40 || get_sha1_hex(buffer, next->old_sha1)) { close(fd); @@ -83,7 +83,6 @@ static int read_loose_refs(struct strbuf *path, int name_offset, continue; } close(fd); - strcpy(next->name, path->buf + name_offset); (*tail)->next = next; *tail = next; } @@ -127,14 +126,13 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list) (*list)->next->name)) > 0) list = &(*list)->next; if (!(*list)->next || cmp < 0) { - struct ref *next = alloc_ref(len - 40); + struct ref *next = alloc_ref(buffer + 41); buffer[40] = '\0'; if (get_sha1_hex(buffer, next->old_sha1)) { warning ("invalid SHA-1: %s", buffer); free(next); continue; } - strcpy(next->name, buffer + 41); next->next = (*list)->next; (*list)->next = next; list = &(*list)->next; @@ -203,7 +201,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport) } static int fetch_objs_via_rsync(struct transport *transport, - int nr_objs, struct ref **to_fetch) + int nr_objs, const struct ref **to_fetch) { struct strbuf buf = STRBUF_INIT; struct child_process rsync; @@ -350,7 +348,7 @@ static int rsync_transport_push(struct transport *transport, #ifndef NO_CURL /* http fetch is the only user */ static int fetch_objs_via_walker(struct transport *transport, - int nr_objs, struct ref **to_fetch) + int nr_objs, const struct ref **to_fetch) { char *dest = xstrdup(transport->url); struct walker *walker = transport->data; @@ -441,8 +439,13 @@ static struct ref *get_refs_via_curl(struct transport *transport) struct ref *ref = NULL; struct ref *last_ref = NULL; + struct walker *walker; + if (!transport->data) - transport->data = get_http_walker(transport->url); + transport->data = get_http_walker(transport->url, + transport->remote); + + walker = transport->data; refs_url = xmalloc(strlen(transport->url) + 11); sprintf(refs_url, "%s/info/refs", transport->url); @@ -453,25 +456,19 @@ static struct ref *get_refs_via_curl(struct transport *transport) curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer); curl_easy_setopt(slot->curl, CURLOPT_URL, refs_url); curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL); - if (transport->remote->http_proxy) - curl_easy_setopt(slot->curl, CURLOPT_PROXY, - transport->remote->http_proxy); if (start_active_slot(slot)) { run_active_slot(slot); if (results.curl_result != CURLE_OK) { strbuf_release(&buffer); - if (missing_target(&results)) { - return NULL; - } else { - error("%s", curl_errorstr); - return NULL; - } + if (missing_target(&results)) + die("%s not found: did you run git update-server-info on the server?", refs_url); + else + die("%s download error - %s", refs_url, curl_errorstr); } } else { strbuf_release(&buffer); - error("Unable to start request"); - return NULL; + die("Unable to start HTTP request"); } data = buffer.buf; @@ -502,14 +499,24 @@ static struct ref *get_refs_via_curl(struct transport *transport) strbuf_release(&buffer); + ref = alloc_ref("HEAD"); + if (!walker->fetch_ref(walker, ref) && + !resolve_remote_symref(ref, refs)) { + ref->next = refs; + refs = ref; + } else { + free(ref); + } + return refs; } static int fetch_objs_via_curl(struct transport *transport, - int nr_objs, struct ref **to_fetch) + int nr_objs, const struct ref **to_fetch) { if (!transport->data) - transport->data = get_http_walker(transport->url); + transport->data = get_http_walker(transport->url, + transport->remote); return fetch_objs_via_walker(transport, nr_objs, to_fetch); } @@ -533,9 +540,8 @@ static struct ref *get_refs_from_bundle(struct transport *transport) die ("Could not read bundle '%s'.", transport->url); for (i = 0; i < data->header.references.nr; i++) { struct ref_list_entry *e = data->header.references.list + i; - struct ref *ref = alloc_ref(strlen(e->name) + 1); + struct ref *ref = alloc_ref(e->name); hashcpy(ref->old_sha1, e->sha1); - strcpy(ref->name, e->name); ref->next = result; result = ref; } @@ -543,7 +549,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport) } static int fetch_refs_from_bundle(struct transport *transport, - int nr_heads, struct ref **to_fetch) + int nr_heads, const struct ref **to_fetch) { struct bundle_transport_data *data = transport->data; return unbundle(&data->header, data->fd); @@ -561,7 +567,10 @@ static int close_bundle(struct transport *transport) struct git_transport_data { unsigned thin : 1; unsigned keep : 1; + unsigned followtags : 1; int depth; + struct child_process *conn; + int fd[2]; const char *uploadpack; const char *receivepack; }; @@ -579,6 +588,9 @@ static int set_git_option(struct transport *connection, } else if (!strcmp(name, TRANS_OPT_THIN)) { data->thin = !!value; return 0; + } else if (!strcmp(name, TRANS_OPT_FOLLOWTAGS)) { + data->followtags = !!value; + return 0; } else if (!strcmp(name, TRANS_OPT_KEEP)) { data->keep = !!value; return 0; @@ -592,52 +604,70 @@ static int set_git_option(struct transport *connection, return 1; } +static int connect_setup(struct transport *transport) +{ + struct git_transport_data *data = transport->data; + data->conn = git_connect(data->fd, transport->url, data->uploadpack, 0); + return 0; +} + static struct ref *get_refs_via_connect(struct transport *transport) { struct git_transport_data *data = transport->data; struct ref *refs; - int fd[2]; - char *dest = xstrdup(transport->url); - struct child_process *conn = git_connect(fd, dest, data->uploadpack, 0); - get_remote_heads(fd[0], &refs, 0, NULL, 0); - packet_flush(fd[1]); - - finish_connect(conn); - - free(dest); + connect_setup(transport); + get_remote_heads(data->fd[0], &refs, 0, NULL, 0, NULL); return refs; } static int fetch_refs_via_pack(struct transport *transport, - int nr_heads, struct ref **to_fetch) + int nr_heads, const struct ref **to_fetch) { struct git_transport_data *data = transport->data; char **heads = xmalloc(nr_heads * sizeof(*heads)); char **origh = xmalloc(nr_heads * sizeof(*origh)); - struct ref *refs; + const struct ref *refs; char *dest = xstrdup(transport->url); struct fetch_pack_args args; int i; + struct ref *refs_tmp = NULL; memset(&args, 0, sizeof(args)); args.uploadpack = data->uploadpack; args.keep_pack = data->keep; args.lock_pack = 1; args.use_thin_pack = data->thin; - args.verbose = transport->verbose > 0; + args.include_tag = data->followtags; + args.verbose = (transport->verbose > 0); + args.quiet = (transport->verbose < 0); + args.no_progress = args.quiet || (!transport->progress && !isatty(1)); args.depth = data->depth; for (i = 0; i < nr_heads; i++) origh[i] = heads[i] = xstrdup(to_fetch[i]->name); - refs = fetch_pack(&args, dest, nr_heads, heads, &transport->pack_lockfile); + + if (!data->conn) { + connect_setup(transport); + get_remote_heads(data->fd[0], &refs_tmp, 0, NULL, 0, NULL); + } + + refs = fetch_pack(&args, data->fd, data->conn, + refs_tmp ? refs_tmp : transport->remote_refs, + dest, nr_heads, heads, &transport->pack_lockfile); + close(data->fd[0]); + close(data->fd[1]); + if (finish_connect(data->conn)) + refs = NULL; + data->conn = NULL; + + free_refs(refs_tmp); for (i = 0; i < nr_heads; i++) free(origh[i]); free(origh); free(heads); - free_refs(refs); free(dest); return (refs ? 0 : -1); } @@ -660,7 +690,15 @@ static int git_transport_push(struct transport *transport, int refspec_nr, const static int disconnect_git(struct transport *transport) { - free(transport->data); + struct git_transport_data *data = transport->data; + if (data->conn) { + packet_flush(data->fd[1]); + close(data->fd[0]); + close(data->fd[1]); + finish_connect(data->conn); + } + + free(data); return 0; } @@ -668,7 +706,8 @@ static int is_local(const char *url) { const char *colon = strchr(url, ':'); const char *slash = strchr(url, '/'); - return !colon || (slash && slash < colon); + return !colon || (slash && slash < colon) || + has_dos_drive_prefix(url); } static int is_file(const char *url) @@ -720,6 +759,7 @@ struct transport *transport_get(struct remote *remote, const char *url) ret->disconnect = disconnect_git; data->thin = 1; + data->conn = NULL; data->uploadpack = "git-upload-pack"; if (remote && remote->uploadpack) data->uploadpack = remote->uploadpack; @@ -754,12 +794,12 @@ const struct ref *transport_get_remote_refs(struct transport *transport) return transport->remote_refs; } -int transport_fetch_refs(struct transport *transport, struct ref *refs) +int transport_fetch_refs(struct transport *transport, const struct ref *refs) { int rc; int nr_heads = 0, nr_alloc = 0; - struct ref **heads = NULL; - struct ref *rm; + const struct ref **heads = NULL; + const struct ref *rm; for (rm = refs; rm; rm = rm->next) { if (rm->peer_ref &&