diff options
Diffstat (limited to 'fetch-pack.c')
-rw-r--r-- | fetch-pack.c | 116 |
1 files changed, 64 insertions, 52 deletions
diff --git a/fetch-pack.c b/fetch-pack.c index a136772152..413937e740 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -169,7 +169,7 @@ static const unsigned char *get_rev(void) } } - return commit->object.sha1; + return commit->object.oid.hash; } enum ack_type { @@ -238,21 +238,26 @@ static void send_request(struct fetch_pack_args *args, static void insert_one_alternate_ref(const struct ref *ref, void *unused) { - rev_list_insert_ref(NULL, ref->old_sha1); + rev_list_insert_ref(NULL, ref->old_oid.hash); } #define INITIAL_FLUSH 16 #define PIPESAFE_FLUSH 32 -#define LARGE_FLUSH 1024 +#define LARGE_FLUSH 16384 static int next_flush(struct fetch_pack_args *args, int count) { - int flush_limit = args->stateless_rpc ? LARGE_FLUSH : PIPESAFE_FLUSH; - - if (count < flush_limit) - count <<= 1; - else - count += flush_limit; + if (args->stateless_rpc) { + if (count < LARGE_FLUSH) + count <<= 1; + else + count = count * 11 / 10; + } else { + if (count < PIPESAFE_FLUSH) + count <<= 1; + else + count += PIPESAFE_FLUSH; + } return count; } @@ -280,7 +285,7 @@ static int find_common(struct fetch_pack_args *args, fetching = 0; for ( ; refs ; refs = refs->next) { - unsigned char *remote = refs->old_sha1; + unsigned char *remote = refs->old_oid.hash; const char *remote_hex; struct object *o; @@ -423,10 +428,17 @@ static int find_common(struct fetch_pack_args *args, const char *hex = sha1_to_hex(result_sha1); packet_buf_write(&req_buf, "have %s\n", hex); state_len = req_buf.len; - } + /* + * Reset in_vain because an ack + * for this commit has not been + * seen. + */ + in_vain = 0; + } else if (!args->stateless_rpc + || ack != ACK_common) + in_vain = 0; mark_common(commit, 0, 1); retval = 0; - in_vain = 0; got_continue = 1; if (ack == ACK_ready) { clear_prio_queue(&rev_list); @@ -487,7 +499,7 @@ static int mark_complete(const unsigned char *sha1) if (!t->tagged) break; /* broken repository */ o->flags |= COMPLETE; - o = parse_object(t->tagged->sha1); + o = parse_object(t->tagged->oid.hash); } if (o && o->type == OBJ_COMMIT) { struct commit *commit = (struct commit *)o; @@ -511,7 +523,7 @@ static void mark_recent_complete_commits(struct fetch_pack_args *args, while (complete && cutoff <= complete->item->date) { if (args->verbose) fprintf(stderr, "Marking %s as complete\n", - sha1_to_hex(complete->item->object.sha1)); + oid_to_hex(&complete->item->object.oid)); pop_most_recent_commit(&complete, COMPLETE); } } @@ -570,7 +582,7 @@ static void filter_refs(struct fetch_pack_args *args, continue; if (get_sha1_hex(ref->name, sha1) || ref->name[40] != '\0' || - hashcmp(sha1, ref->old_sha1)) + hashcmp(sha1, ref->old_oid.hash)) continue; ref->matched = 1; @@ -583,7 +595,7 @@ static void filter_refs(struct fetch_pack_args *args, static void mark_alternate_complete(const struct ref *ref, void *unused) { - mark_complete(ref->old_sha1); + mark_complete(ref->old_oid.hash); } static int everything_local(struct fetch_pack_args *args, @@ -599,10 +611,10 @@ static int everything_local(struct fetch_pack_args *args, for (ref = *refs; ref; ref = ref->next) { struct object *o; - if (!has_sha1_file(ref->old_sha1)) + if (!has_object_file(&ref->old_oid)) continue; - o = parse_object(ref->old_sha1); + o = parse_object(ref->old_oid.hash); if (!o) continue; @@ -630,7 +642,7 @@ static int everything_local(struct fetch_pack_args *args, * Don't mark them common yet; the server has to be told so first. */ for (ref = *refs; ref; ref = ref->next) { - struct object *o = deref_tag(lookup_object(ref->old_sha1), + struct object *o = deref_tag(lookup_object(ref->old_oid.hash), NULL, 0); if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE)) @@ -646,7 +658,7 @@ static int everything_local(struct fetch_pack_args *args, filter_refs(args, refs, sought, nr_sought); for (retval = 1, ref = *refs; ref ; ref = ref->next) { - const unsigned char *remote = ref->old_sha1; + const unsigned char *remote = ref->old_oid.hash; struct object *o; o = lookup_object(remote); @@ -671,8 +683,9 @@ static int everything_local(struct fetch_pack_args *args, static int sideband_demux(int in, int out, void *data) { int *xd = data; + int ret; - int ret = recv_sideband("fetch-pack", xd[0], out); + ret = recv_sideband("fetch-pack", xd[0], out); close(out); return ret; } @@ -681,11 +694,10 @@ static int get_pack(struct fetch_pack_args *args, int xd[2], char **pack_lockfile) { struct async demux; - const char *argv[22]; - char keep_arg[256]; - char hdr_arg[256]; - const char **av, *cmd_name; int do_keep = args->keep_pack; + const char *cmd_name; + struct pack_header header; + int pass_header = 0; struct child_process cmd = CHILD_PROCESS_INIT; int ret; @@ -698,6 +710,7 @@ static int get_pack(struct fetch_pack_args *args, demux.proc = sideband_demux; demux.data = xd; demux.out = -1; + demux.isolate_sigpipe = 1; if (start_async(&demux)) die("fetch-pack: unable to fork off sideband" " demultiplexer"); @@ -705,17 +718,11 @@ static int get_pack(struct fetch_pack_args *args, else demux.out = xd[0]; - cmd.argv = argv; - av = argv; - *hdr_arg = 0; if (!args->keep_pack && unpack_limit) { - struct pack_header header; if (read_pack_header(demux.out, &header)) die("protocol error: bad pack header"); - snprintf(hdr_arg, sizeof(hdr_arg), - "--pack_header=%"PRIu32",%"PRIu32, - ntohl(header.hdr_version), ntohl(header.hdr_entries)); + pass_header = 1; if (ntohl(header.hdr_entries) < unpack_limit) do_keep = 0; else @@ -723,44 +730,49 @@ static int get_pack(struct fetch_pack_args *args, } if (alternate_shallow_file) { - *av++ = "--shallow-file"; - *av++ = alternate_shallow_file; + argv_array_push(&cmd.args, "--shallow-file"); + argv_array_push(&cmd.args, alternate_shallow_file); } if (do_keep) { if (pack_lockfile) cmd.out = -1; - *av++ = cmd_name = "index-pack"; - *av++ = "--stdin"; + cmd_name = "index-pack"; + argv_array_push(&cmd.args, cmd_name); + argv_array_push(&cmd.args, "--stdin"); if (!args->quiet && !args->no_progress) - *av++ = "-v"; + argv_array_push(&cmd.args, "-v"); if (args->use_thin_pack) - *av++ = "--fix-thin"; + argv_array_push(&cmd.args, "--fix-thin"); if (args->lock_pack || unpack_limit) { - int s = sprintf(keep_arg, - "--keep=fetch-pack %"PRIuMAX " on ", (uintmax_t) getpid()); - if (gethostname(keep_arg + s, sizeof(keep_arg) - s)) - strcpy(keep_arg + s, "localhost"); - *av++ = keep_arg; + char hostname[256]; + if (gethostname(hostname, sizeof(hostname))) + xsnprintf(hostname, sizeof(hostname), "localhost"); + argv_array_pushf(&cmd.args, + "--keep=fetch-pack %"PRIuMAX " on %s", + (uintmax_t)getpid(), hostname); } if (args->check_self_contained_and_connected) - *av++ = "--check-self-contained-and-connected"; + argv_array_push(&cmd.args, "--check-self-contained-and-connected"); } else { - *av++ = cmd_name = "unpack-objects"; + cmd_name = "unpack-objects"; + argv_array_push(&cmd.args, cmd_name); if (args->quiet || args->no_progress) - *av++ = "-q"; + argv_array_push(&cmd.args, "-q"); args->check_self_contained_and_connected = 0; } - if (*hdr_arg) - *av++ = hdr_arg; + + if (pass_header) + argv_array_pushf(&cmd.args, "--pack_header=%"PRIu32",%"PRIu32, + ntohl(header.hdr_version), + ntohl(header.hdr_entries)); if (fetch_fsck_objects >= 0 ? fetch_fsck_objects : transfer_fsck_objects >= 0 ? transfer_fsck_objects : 0) - *av++ = "--strict"; - *av++ = NULL; + argv_array_push(&cmd.args, "--strict"); cmd.in = demux.out; cmd.git_cmd = 1; @@ -948,7 +960,7 @@ static void update_shallow(struct fetch_pack_args *args, if (args->depth > 0 && alternate_shallow_file) { if (*alternate_shallow_file == '\0') { /* --unshallow */ - unlink_or_warn(git_path("shallow")); + unlink_or_warn(git_path_shallow()); rollback_lock_file(&shallow_lock); } else commit_lock_file(&shallow_lock); @@ -987,7 +999,7 @@ static void update_shallow(struct fetch_pack_args *args, if (!si->nr_ours && !si->nr_theirs) return; for (i = 0; i < nr_sought; i++) - sha1_array_append(&ref, sought[i]->old_sha1); + sha1_array_append(&ref, sought[i]->old_oid.hash); si->ref = &ref; if (args->update_shallow) { |