From: Junio C Hamano Date: Thu, 25 Apr 2019 07:41:16 +0000 (+0900) Subject: Merge branch 'jt/fetch-pack-wanted-refs-optim' X-Git-Tag: v2.22.0-rc0~61 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/abd7ccdd4ddcc2d2ce1d51943051c071902b159a?hp=-c Merge branch 'jt/fetch-pack-wanted-refs-optim' Performance fix around "git fetch" that grabs many refs. * jt/fetch-pack-wanted-refs-optim: fetch-pack: binary search when storing wanted-refs --- abd7ccdd4ddcc2d2ce1d51943051c071902b159a diff --combined fetch-pack.c index 8d67d4e362,e018b1c0a4..01cdee01b4 --- a/fetch-pack.c +++ b/fetch-pack.c @@@ -191,10 -191,8 +191,10 @@@ static void send_request(struct fetch_p if (args->stateless_rpc) { send_sideband(fd, -1, buf->buf, buf->len, LARGE_PACKET_MAX); packet_flush(fd); - } else - write_or_die(fd, buf->buf, buf->len); + } else { + if (write_in_full(fd, buf->buf, buf->len) < 0) + die_errno(_("unable to write to remote")); + } } static void insert_one_alternate_object(struct fetch_negotiator *negotiator, @@@ -1165,8 -1163,7 +1165,8 @@@ static int send_fetch_request(struct fe /* Send request */ packet_buf_flush(&req_buf); - write_or_die(fd_out, req_buf.buf, req_buf.len); + if (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0) + die_errno(_("unable to write request to remote")); strbuf_release(&req_buf); return ret; @@@ -1298,6 -1295,11 +1298,11 @@@ static void receive_shallow_info(struc } } + static int cmp_name_ref(const void *name, const void *ref) + { + return strcmp(name, (*(struct ref **)ref)->name); + } + static void receive_wanted_refs(struct packet_reader *reader, struct ref **sought, int nr_sought) { @@@ -1305,20 -1307,16 +1310,16 @@@ while (packet_reader_read(reader) == PACKET_READ_NORMAL) { struct object_id oid; const char *end; - int i; + struct ref **found; if (parse_oid_hex(reader->line, &oid, &end) || *end++ != ' ') die(_("expected wanted-ref, got '%s'"), reader->line); - for (i = 0; i < nr_sought; i++) { - if (!strcmp(end, sought[i]->name)) { - oidcpy(&sought[i]->old_oid, &oid); - break; - } - } - - if (i == nr_sought) + found = bsearch(end, sought, nr_sought, sizeof(*sought), + cmp_name_ref); + if (!found) die(_("unexpected wanted-ref: '%s'"), reader->line); + oidcpy(&(*found)->old_oid, &oid); } if (reader->status != PACKET_READ_DELIM) @@@ -1615,8 -1613,9 +1616,8 @@@ static int iterate_ref_map(void *cb_dat } struct ref *fetch_pack(struct fetch_pack_args *args, - int fd[], struct child_process *conn, + int fd[], const struct ref *ref, - const char *dest, struct ref **sought, int nr_sought, struct oid_array *shallow, char **pack_lockfile,