static const char *unpack(void) { struct pack_header hdr; const char *hdr_err; char hdr_arg[38]; hdr_err = parse_pack_header(&hdr); if (hdr_err) return hdr_err; snprintf(hdr_arg, sizeof(hdr_arg), "--pack_header=%"PRIu32",%"PRIu32, ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries)); if (ntohl(hdr.hdr_entries) < unpack_limit) { int code, i = 0; const char *unpacker[4]; unpacker[i++] = "unpack-objects"; if (receive_fsck_objects) unpacker[i++] = "--strict"; unpacker[i++] = hdr_arg; unpacker[i++] = NULL; code = run_command_v_opt(unpacker, RUN_GIT_CMD); switch (code) { case 0: return NULL; case -ERR_RUN_COMMAND_FORK: return "unpack fork failed"; case -ERR_RUN_COMMAND_EXEC: return "unpack execute failed"; case -ERR_RUN_COMMAND_WAITPID: return "waitpid failed"; case -ERR_RUN_COMMAND_WAITPID_WRONG_PID: return "waitpid is confused"; case -ERR_RUN_COMMAND_WAITPID_SIGNAL: return "unpacker died of signal"; case -ERR_RUN_COMMAND_WAITPID_NOEXIT: return "unpacker died strangely"; default: return "unpacker exited with error code"; } } else { const char *keeper[7]; int s, status, i = 0; char keep_arg[256]; struct child_process ip; s = sprintf(keep_arg, "--keep=receive-pack %"PRIuMAX" on ", (uintmax_t) getpid()); if (gethostname(keep_arg + s, sizeof(keep_arg) - s)) strcpy(keep_arg + s, "localhost"); keeper[i++] = "index-pack"; keeper[i++] = "--stdin"; if (receive_fsck_objects) keeper[i++] = "--strict"; keeper[i++] = "--fix-thin"; keeper[i++] = hdr_arg; keeper[i++] = keep_arg; keeper[i++] = NULL; memset(&ip, 0, sizeof(ip)); ip.argv = keeper; ip.out = -1; ip.git_cmd = 1; if (start_command(&ip)) return "index-pack fork failed"; pack_lockfile = index_pack_lockfile(ip.out); close(ip.out); status = finish_command(&ip); if (!status) { reprepare_packed_git(); return NULL; } return "index-pack abnormal exit"; } }
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; struct child_process cmd; int ret; memset(&demux, 0, sizeof(demux)); if (use_sideband) { /* xd[] is talking with upload-pack; subprocess reads from * xd[0], spits out band#2 to stderr, and feeds us band#1 * through demux->out. */ demux.proc = sideband_demux; demux.data = xd; demux.out = -1; if (start_async(&demux)) die("fetch-pack: unable to fork off sideband" " demultiplexer"); } else demux.out = xd[0]; memset(&cmd, 0, sizeof(cmd)); 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)); if (ntohl(header.hdr_entries) < unpack_limit) do_keep = 0; else do_keep = 1; } if (alternate_shallow_file) { *av++ = "--shallow-file"; *av++ = alternate_shallow_file; } if (do_keep) { if (pack_lockfile) cmd.out = -1; *av++ = cmd_name = "index-pack"; *av++ = "--stdin"; if (!args->quiet && !args->no_progress) *av++ = "-v"; if (args->use_thin_pack) *av++ = "--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; } if (args->check_self_contained_and_connected) *av++ = "--check-self-contained-and-connected"; } else { *av++ = cmd_name = "unpack-objects"; if (args->quiet || args->no_progress) *av++ = "-q"; args->check_self_contained_and_connected = 0; } if (*hdr_arg) *av++ = hdr_arg; if (fetch_fsck_objects >= 0 ? fetch_fsck_objects : transfer_fsck_objects >= 0 ? transfer_fsck_objects : 0) *av++ = "--strict"; *av++ = NULL; cmd.in = demux.out; cmd.git_cmd = 1; if (start_command(&cmd)) die("fetch-pack: unable to fork off %s", cmd_name); if (do_keep && pack_lockfile) { *pack_lockfile = index_pack_lockfile(cmd.out); close(cmd.out); } if (!use_sideband) /* Closed by start_command() */ xd[0] = -1; ret = finish_command(&cmd); if (!ret || (args->check_self_contained_and_connected && ret == 1)) args->self_contained_and_connected = args->check_self_contained_and_connected && ret == 0; else die("%s failed", cmd_name); if (use_sideband && finish_async(&demux)) die("error in sideband demultiplexer"); return 0; }
static const char *unpack(void) { struct pack_header hdr; const char *hdr_err; char hdr_arg[38]; int fsck_objects = (receive_fsck_objects >= 0 ? receive_fsck_objects : transfer_fsck_objects >= 0 ? transfer_fsck_objects : 0); hdr_err = parse_pack_header(&hdr); if (hdr_err) return hdr_err; snprintf(hdr_arg, sizeof(hdr_arg), "--pack_header=%"PRIu32",%"PRIu32, ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries)); if (ntohl(hdr.hdr_entries) < unpack_limit) { int code, i = 0; const char *unpacker[4]; unpacker[i++] = "unpack-objects"; if (fsck_objects) unpacker[i++] = "--strict"; unpacker[i++] = hdr_arg; unpacker[i++] = NULL; code = run_command_v_opt(unpacker, RUN_GIT_CMD); if (!code) return NULL; return "unpack-objects abnormal exit"; } else { const char *keeper[7]; int s, status, i = 0; char keep_arg[256]; struct child_process ip; s = sprintf(keep_arg, "--keep=receive-pack %"PRIuMAX" on ", (uintmax_t) getpid()); if (gethostname(keep_arg + s, sizeof(keep_arg) - s)) strcpy(keep_arg + s, "localhost"); keeper[i++] = "index-pack"; keeper[i++] = "--stdin"; if (fsck_objects) keeper[i++] = "--strict"; keeper[i++] = "--fix-thin"; keeper[i++] = hdr_arg; keeper[i++] = keep_arg; keeper[i++] = NULL; memset(&ip, 0, sizeof(ip)); ip.argv = keeper; ip.out = -1; ip.git_cmd = 1; status = start_command(&ip); if (status) { return "index-pack fork failed"; } pack_lockfile = index_pack_lockfile(ip.out); close(ip.out); status = finish_command(&ip); if (!status) { reprepare_packed_git(); return NULL; } return "index-pack abnormal exit"; } }
static int get_pack(struct fetch_pack_args *args, int xd[2], char **pack_lockfile) { struct async demux; 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; memset(&demux, 0, sizeof(demux)); if (use_sideband) { /* xd[] is talking with upload-pack; subprocess reads from * xd[0], spits out band#2 to stderr, and feeds us band#1 * through demux->out. */ 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")); } else demux.out = xd[0]; if (!args->keep_pack && unpack_limit) { if (read_pack_header(demux.out, &header)) die(_("protocol error: bad pack header")); pass_header = 1; if (ntohl(header.hdr_entries) < unpack_limit) do_keep = 0; else do_keep = 1; } if (alternate_shallow_file) { argv_array_push(&cmd.args, "--shallow-file"); argv_array_push(&cmd.args, alternate_shallow_file); } if (do_keep || args->from_promisor) { if (pack_lockfile) cmd.out = -1; cmd_name = "index-pack"; argv_array_push(&cmd.args, cmd_name); argv_array_push(&cmd.args, "--stdin"); if (!args->quiet && !args->no_progress) argv_array_push(&cmd.args, "-v"); if (args->use_thin_pack) argv_array_push(&cmd.args, "--fix-thin"); if (do_keep && (args->lock_pack || unpack_limit)) { char hostname[HOST_NAME_MAX + 1]; if (xgethostname(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) argv_array_push(&cmd.args, "--check-self-contained-and-connected"); if (args->from_promisor) argv_array_push(&cmd.args, "--promisor"); } else { cmd_name = "unpack-objects"; argv_array_push(&cmd.args, cmd_name); if (args->quiet || args->no_progress) argv_array_push(&cmd.args, "-q"); args->check_self_contained_and_connected = 0; } 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) { if (args->from_promisor) /* * We cannot use --strict in index-pack because it * checks both broken objects and links, but we only * want to check for broken objects. */ argv_array_push(&cmd.args, "--fsck-objects"); else argv_array_pushf(&cmd.args, "--strict%s", fsck_msg_types.buf); } cmd.in = demux.out; cmd.git_cmd = 1; if (start_command(&cmd)) die(_("fetch-pack: unable to fork off %s"), cmd_name); if (do_keep && pack_lockfile) { *pack_lockfile = index_pack_lockfile(cmd.out); close(cmd.out); } if (!use_sideband) /* Closed by start_command() */ xd[0] = -1; ret = finish_command(&cmd); if (!ret || (args->check_self_contained_and_connected && ret == 1)) args->self_contained_and_connected = args->check_self_contained_and_connected && ret == 0; else die(_("%s failed"), cmd_name); if (use_sideband && finish_async(&demux)) die(_("error in sideband demultiplexer")); return 0; }
static const char *unpack(int err_fd, struct shallow_info *si) { struct pack_header hdr; const char *hdr_err; int status; char hdr_arg[38]; struct child_process child = CHILD_PROCESS_INIT; int fsck_objects = (receive_fsck_objects >= 0 ? receive_fsck_objects : transfer_fsck_objects >= 0 ? transfer_fsck_objects : 0); hdr_err = parse_pack_header(&hdr); if (hdr_err) { if (err_fd > 0) close(err_fd); return hdr_err; } snprintf(hdr_arg, sizeof(hdr_arg), "--pack_header=%"PRIu32",%"PRIu32, ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries)); if (si->nr_ours || si->nr_theirs) { alt_shallow_file = setup_temporary_shallow(si->shallow); argv_array_push(&child.args, "--shallow-file"); argv_array_push(&child.args, alt_shallow_file); } if (ntohl(hdr.hdr_entries) < unpack_limit) { argv_array_pushl(&child.args, "unpack-objects", hdr_arg, NULL); if (quiet) argv_array_push(&child.args, "-q"); if (fsck_objects) argv_array_pushf(&child.args, "--strict%s", fsck_msg_types.buf); child.no_stdout = 1; child.err = err_fd; child.git_cmd = 1; status = run_command(&child); if (status) return "unpack-objects abnormal exit"; } else { char hostname[256]; argv_array_pushl(&child.args, "index-pack", "--stdin", hdr_arg, NULL); if (gethostname(hostname, sizeof(hostname))) xsnprintf(hostname, sizeof(hostname), "localhost"); argv_array_pushf(&child.args, "--keep=receive-pack %"PRIuMAX" on %s", (uintmax_t)getpid(), hostname); if (!quiet && err_fd) argv_array_push(&child.args, "--show-resolving-progress"); if (use_sideband) argv_array_push(&child.args, "--report-end-of-input"); if (fsck_objects) argv_array_pushf(&child.args, "--strict%s", fsck_msg_types.buf); if (!reject_thin) argv_array_push(&child.args, "--fix-thin"); child.out = -1; child.err = err_fd; child.git_cmd = 1; status = start_command(&child); if (status) return "index-pack fork failed"; pack_lockfile = index_pack_lockfile(child.out); close(child.out); status = finish_command(&child); if (status) return "index-pack abnormal exit"; reprepare_packed_git(); } return NULL; }
static int get_pack(int xd[2], char **pack_lockfile) { struct async demux; const char *argv[20]; char keep_arg[256]; char hdr_arg[256]; const char **av; int do_keep = args.keep_pack; struct child_process cmd; memset(&demux, 0, sizeof(demux)); if (use_sideband) { /* xd[] is talking with upload-pack; subprocess reads from * xd[0], spits out band#2 to stderr, and feeds us band#1 * through demux->out. */ demux.proc = sideband_demux; demux.data = xd; if (start_async(&demux)) die("fetch-pack: unable to fork off sideband" " demultiplexer"); } else demux.out = xd[0]; memset(&cmd, 0, sizeof(cmd)); 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)); if (ntohl(header.hdr_entries) < unpack_limit) do_keep = 0; else do_keep = 1; } if (do_keep) { if (pack_lockfile) cmd.out = -1; *av++ = "index-pack"; *av++ = "--stdin"; if (!args.quiet && !args.no_progress) *av++ = "-v"; if (args.use_thin_pack) *av++ = "--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; } } else { *av++ = "unpack-objects"; if (args.quiet) *av++ = "-q"; } if (*hdr_arg) *av++ = hdr_arg; *av++ = NULL; cmd.in = demux.out; cmd.git_cmd = 1; if (start_command(&cmd)) die("fetch-pack: unable to fork off %s", argv[0]); if (do_keep && pack_lockfile) { *pack_lockfile = index_pack_lockfile(cmd.out); close(cmd.out); } if (finish_command(&cmd)) die("%s failed", argv[0]); if (use_sideband && finish_async(&demux)) die("error in sideband demultiplexer"); return 0; }
static const char *unpack(int err_fd, struct shallow_info *si) { struct pack_header hdr; struct argv_array av = ARGV_ARRAY_INIT; const char *hdr_err; int status; char hdr_arg[38]; struct child_process child; int fsck_objects = (receive_fsck_objects >= 0 ? receive_fsck_objects : transfer_fsck_objects >= 0 ? transfer_fsck_objects : 0); hdr_err = parse_pack_header(&hdr); if (hdr_err) { if (err_fd > 0) close(err_fd); return hdr_err; } snprintf(hdr_arg, sizeof(hdr_arg), "--pack_header=%"PRIu32",%"PRIu32, ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries)); if (si->nr_ours || si->nr_theirs) { alt_shallow_file = setup_temporary_shallow(si->shallow); argv_array_pushl(&av, "--shallow-file", alt_shallow_file, NULL); } memset(&child, 0, sizeof(child)); if (ntohl(hdr.hdr_entries) < unpack_limit) { argv_array_pushl(&av, "unpack-objects", hdr_arg, NULL); if (quiet) argv_array_push(&av, "-q"); if (fsck_objects) argv_array_push(&av, "--strict"); child.argv = av.argv; child.no_stdout = 1; child.err = err_fd; child.git_cmd = 1; status = run_command(&child); if (status) return "unpack-objects abnormal exit"; } else { int s; char keep_arg[256]; s = sprintf(keep_arg, "--keep=receive-pack %"PRIuMAX" on ", (uintmax_t) getpid()); if (gethostname(keep_arg + s, sizeof(keep_arg) - s)) strcpy(keep_arg + s, "localhost"); argv_array_pushl(&av, "index-pack", "--stdin", hdr_arg, keep_arg, NULL); if (fsck_objects) argv_array_push(&av, "--strict"); if (fix_thin) argv_array_push(&av, "--fix-thin"); child.argv = av.argv; child.out = -1; child.err = err_fd; child.git_cmd = 1; status = start_command(&child); if (status) return "index-pack fork failed"; pack_lockfile = index_pack_lockfile(child.out); close(child.out); status = finish_command(&child); if (status) return "index-pack abnormal exit"; reprepare_packed_git(); } return NULL; }