void init_display_notes(struct display_notes_opt *opt) { char *display_ref_env; int load_config_refs = 0; display_notes_refs.strdup_strings = 1; assert(!display_notes_trees); if (!opt || opt->use_default_notes > 0 || (opt->use_default_notes == -1 && !opt->extra_notes_refs.nr)) { string_list_append(&display_notes_refs, default_notes_ref()); display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT); if (display_ref_env) { string_list_add_refs_from_colon_sep(&display_notes_refs, display_ref_env); load_config_refs = 0; } else load_config_refs = 1; } git_config(notes_display_config, &load_config_refs); if (opt) { struct string_list_item *item; for_each_string_list_item(item, &opt->extra_notes_refs) string_list_add_refs_by_glob(&display_notes_refs, item->string); } display_notes_trees = load_notes_trees(&display_notes_refs, 0); string_list_clear(&display_notes_refs, 0); }
static int clone_submodule(const char *path, const char *gitdir, const char *url, const char *depth, struct string_list *reference, int quiet, int progress) { struct child_process cp = CHILD_PROCESS_INIT; argv_array_push(&cp.args, "clone"); argv_array_push(&cp.args, "--no-checkout"); if (quiet) argv_array_push(&cp.args, "--quiet"); if (progress) argv_array_push(&cp.args, "--progress"); if (depth && *depth) argv_array_pushl(&cp.args, "--depth", depth, NULL); if (reference->nr) { struct string_list_item *item; for_each_string_list_item(item, reference) argv_array_pushl(&cp.args, "--reference", item->string, NULL); } if (gitdir && *gitdir) argv_array_pushl(&cp.args, "--separate-git-dir", gitdir, NULL); argv_array_push(&cp.args, url); argv_array_push(&cp.args, path); cp.git_cmd = 1; prepare_submodule_repo_env(&cp.env_array); cp.no_stdin = 1; return run_command(&cp); }
static void format_symref_info(struct strbuf *buf, struct string_list *symref) { struct string_list_item *item; if (!symref->nr) return; for_each_string_list_item(item, symref) strbuf_addf(buf, " symref=%s:%s", item->string, (char *)item->util); }
static int generate_push_cert(struct strbuf *req_buf, const struct ref *remote_refs, struct send_pack_args *args, const char *cap_string, const char *push_cert_nonce) { const struct ref *ref; struct string_list_item *item; char *signing_key = xstrdup(get_signing_key()); const char *cp, *np; struct strbuf cert = STRBUF_INIT; int update_seen = 0; strbuf_addstr(&cert, "certificate version 0.1\n"); strbuf_addf(&cert, "pusher %s ", signing_key); datestamp(&cert); strbuf_addch(&cert, '\n'); if (args->url && *args->url) { char *anon_url = transport_anonymize_url(args->url); strbuf_addf(&cert, "pushee %s\n", anon_url); free(anon_url); } if (push_cert_nonce[0]) strbuf_addf(&cert, "nonce %s\n", push_cert_nonce); if (args->push_options) for_each_string_list_item(item, args->push_options) strbuf_addf(&cert, "push-option %s\n", item->string); strbuf_addstr(&cert, "\n"); for (ref = remote_refs; ref; ref = ref->next) { if (check_to_send_update(ref, args) < 0) continue; update_seen = 1; strbuf_addf(&cert, "%s %s %s\n", oid_to_hex(&ref->old_oid), oid_to_hex(&ref->new_oid), ref->name); } if (!update_seen) goto free_return; if (sign_buffer(&cert, &cert, signing_key)) die(_("failed to sign the push certificate")); packet_buf_write(req_buf, "push-cert%c%s", 0, cap_string); for (cp = cert.buf; cp < cert.buf + cert.len; cp = np) { np = next_line(cp, cert.buf + cert.len - cp); packet_buf_write(req_buf, "%.*s", (int)(np - cp), cp); } packet_buf_write(req_buf, "push-cert-end\n"); free_return: free(signing_key); strbuf_release(&cert); return update_seen; }
static int push_git(struct discovery *heads, int nr_spec, char **specs) { struct rpc_state rpc; int i, err; struct argv_array args; struct string_list_item *cas_option; struct strbuf preamble = STRBUF_INIT; argv_array_init(&args); argv_array_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status", NULL); if (options.thin) argv_array_push(&args, "--thin"); if (options.dry_run) argv_array_push(&args, "--dry-run"); if (options.push_cert == SEND_PACK_PUSH_CERT_ALWAYS) argv_array_push(&args, "--signed=yes"); else if (options.push_cert == SEND_PACK_PUSH_CERT_IF_ASKED) argv_array_push(&args, "--signed=if-asked"); if (options.verbosity == 0) argv_array_push(&args, "--quiet"); else if (options.verbosity > 1) argv_array_push(&args, "--verbose"); for (i = 0; i < options.push_options.nr; i++) argv_array_pushf(&args, "--push-option=%s", options.push_options.items[i].string); argv_array_push(&args, options.progress ? "--progress" : "--no-progress"); for_each_string_list_item(cas_option, &cas_options) argv_array_push(&args, cas_option->string); argv_array_push(&args, url.buf); argv_array_push(&args, "--stdin"); for (i = 0; i < nr_spec; i++) packet_buf_write(&preamble, "%s\n", specs[i]); packet_buf_flush(&preamble); memset(&rpc, 0, sizeof(rpc)); rpc.service_name = "git-receive-pack", rpc.argv = args.argv; rpc.stdin_preamble = &preamble; err = rpc_service(&rpc, heads); if (rpc.result.len) write_or_die(1, rpc.result.buf, rpc.result.len); strbuf_release(&rpc.result); strbuf_release(&preamble); argv_array_clear(&args); return err; }
static int do_command(struct strbuf *line) { const struct input_command_entry *p = input_command_list; static struct string_list batchlines = STRING_LIST_INIT_DUP; static const struct input_command_entry *batch_cmd; /* * commands can be grouped together in a batch. * Batches are ended by \n. If no batch is active the program ends. * During a batch all lines are buffered and passed to the handler function * when the batch is terminated. */ if (line->len == 0) { if (batch_cmd) { struct string_list_item *item; for_each_string_list_item(item, &batchlines) batch_cmd->fn(item->string); terminate_batch(); batch_cmd = NULL; string_list_clear(&batchlines, 0); return 0; /* end of the batch, continue reading other commands. */ } return 1; /* end of command stream, quit */ } if (batch_cmd) { if (!starts_with(batch_cmd->name, line->buf)) die("Active %s batch interrupted by %s", batch_cmd->name, line->buf); /* buffer batch lines */ string_list_append(&batchlines, line->buf); return 0; } for (p = input_command_list; p->name; p++) { if (starts_with(line->buf, p->name) && (strlen(p->name) == line->len || line->buf[strlen(p->name)] == ' ')) { if (p->batchable) { batch_cmd = p; string_list_append(&batchlines, line->buf); return 0; } return p->fn(line->buf); } } die("Unknown command '%s'\n", line->buf); return 0; }
static int push_git(struct discovery *heads, int nr_spec, char **specs) { struct rpc_state rpc; int i, err; struct argv_array args; struct string_list_item *cas_option; argv_array_init(&args); argv_array_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status", NULL); if (options.thin) argv_array_push(&args, "--thin"); if (options.dry_run) argv_array_push(&args, "--dry-run"); if (options.verbosity == 0) argv_array_push(&args, "--quiet"); else if (options.verbosity > 1) argv_array_push(&args, "--verbose"); argv_array_push(&args, options.progress ? "--progress" : "--no-progress"); for_each_string_list_item(cas_option, &cas_options) argv_array_push(&args, cas_option->string); argv_array_push(&args, url.buf); for (i = 0; i < nr_spec; i++) argv_array_push(&args, specs[i]); memset(&rpc, 0, sizeof(rpc)); rpc.service_name = "git-receive-pack", rpc.argv = args.argv; err = rpc_service(&rpc, heads); if (rpc.result.len) write_or_die(1, rpc.result.buf, rpc.result.len); strbuf_release(&rpc.result); argv_array_clear(&args); return err; }
int send_pack(struct send_pack_args *args, int fd[], struct child_process *conn, struct ref *remote_refs, struct sha1_array *extra_have) { int in = fd[0]; int out = fd[1]; struct strbuf req_buf = STRBUF_INIT; struct strbuf cap_buf = STRBUF_INIT; struct ref *ref; int need_pack_data = 0; int allow_deleting_refs = 0; int status_report = 0; int use_sideband = 0; int quiet_supported = 0; int agent_supported = 0; int use_atomic = 0; int atomic_supported = 0; int use_push_options = 0; int push_options_supported = 0; unsigned cmds_sent = 0; int ret; struct async demux; const char *push_cert_nonce = NULL; git_config(send_pack_config, NULL); /* Does the other end support the reporting? */ if (server_supports("report-status")) status_report = 1; if (server_supports("delete-refs")) allow_deleting_refs = 1; if (server_supports("ofs-delta")) args->use_ofs_delta = 1; if (config_use_sideband && server_supports("side-band-64k")) use_sideband = 1; if (server_supports("quiet")) quiet_supported = 1; if (server_supports("agent")) agent_supported = 1; if (server_supports("no-thin")) args->use_thin_pack = 0; if (server_supports("atomic")) atomic_supported = 1; if (server_supports("push-options")) push_options_supported = 1; if (args->push_cert != SEND_PACK_PUSH_CERT_NEVER) { int len; push_cert_nonce = server_feature_value("push-cert", &len); if (push_cert_nonce) { reject_invalid_nonce(push_cert_nonce, len); push_cert_nonce = xmemdupz(push_cert_nonce, len); } else if (args->push_cert == SEND_PACK_PUSH_CERT_ALWAYS) { die(_("the receiving end does not support --signed push")); } else if (args->push_cert == SEND_PACK_PUSH_CERT_IF_ASKED) { warning(_("not sending a push certificate since the" " receiving end does not support --signed" " push")); } } if (!remote_refs) { fprintf(stderr, "No refs in common and none specified; doing nothing.\n" "Perhaps you should specify a branch such as 'master'.\n"); return 0; } if (args->atomic && !atomic_supported) die(_("the receiving end does not support --atomic push")); use_atomic = atomic_supported && args->atomic; if (args->push_options && !push_options_supported) die(_("the receiving end does not support push options")); use_push_options = push_options_supported && args->push_options; if (status_report) strbuf_addstr(&cap_buf, " report-status"); if (use_sideband) strbuf_addstr(&cap_buf, " side-band-64k"); if (quiet_supported && (args->quiet || !args->progress)) strbuf_addstr(&cap_buf, " quiet"); if (use_atomic) strbuf_addstr(&cap_buf, " atomic"); if (use_push_options) strbuf_addstr(&cap_buf, " push-options"); if (agent_supported) strbuf_addf(&cap_buf, " agent=%s", git_user_agent_sanitized()); /* * NEEDSWORK: why does delete-refs have to be so specific to * send-pack machinery that set_ref_status_for_push() cannot * set this bit for us??? */ for (ref = remote_refs; ref; ref = ref->next) if (ref->deletion && !allow_deleting_refs) ref->status = REF_STATUS_REJECT_NODELETE; if (!args->dry_run) advertise_shallow_grafts_buf(&req_buf); if (!args->dry_run && push_cert_nonce) cmds_sent = generate_push_cert(&req_buf, remote_refs, args, cap_buf.buf, push_cert_nonce); /* * Clear the status for each ref and see if we need to send * the pack data. */ for (ref = remote_refs; ref; ref = ref->next) { switch (check_to_send_update(ref, args)) { case 0: /* no error */ break; case CHECK_REF_STATUS_REJECTED: /* * When we know the server would reject a ref update if * we were to send it and we're trying to send the refs * atomically, abort the whole operation. */ if (use_atomic) return atomic_push_failure(args, remote_refs, ref); /* Fallthrough for non atomic case. */ default: continue; } if (!ref->deletion) need_pack_data = 1; if (args->dry_run || !status_report) ref->status = REF_STATUS_OK; else ref->status = REF_STATUS_EXPECTING_REPORT; } /* * Finally, tell the other end! */ for (ref = remote_refs; ref; ref = ref->next) { char *old_hex, *new_hex; if (args->dry_run || push_cert_nonce) continue; if (check_to_send_update(ref, args) < 0) continue; old_hex = oid_to_hex(&ref->old_oid); new_hex = oid_to_hex(&ref->new_oid); if (!cmds_sent) { packet_buf_write(&req_buf, "%s %s %s%c%s", old_hex, new_hex, ref->name, 0, cap_buf.buf); cmds_sent = 1; } else { packet_buf_write(&req_buf, "%s %s %s", old_hex, new_hex, ref->name); } } if (args->stateless_rpc) { if (!args->dry_run && (cmds_sent || is_repository_shallow())) { packet_buf_flush(&req_buf); send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX); } } else { write_or_die(out, req_buf.buf, req_buf.len); packet_flush(out); } strbuf_release(&req_buf); strbuf_release(&cap_buf); if (use_push_options) { struct string_list_item *item; struct strbuf sb = STRBUF_INIT; for_each_string_list_item(item, args->push_options) packet_buf_write(&sb, "%s", item->string); write_or_die(out, sb.buf, sb.len); packet_flush(out); strbuf_release(&sb); } if (use_sideband && cmds_sent) { memset(&demux, 0, sizeof(demux)); demux.proc = sideband_demux; demux.data = fd; demux.out = -1; demux.isolate_sigpipe = 1; if (start_async(&demux)) die("send-pack: unable to fork off sideband demultiplexer"); in = demux.out; } if (need_pack_data && cmds_sent) { if (pack_objects(out, remote_refs, extra_have, args) < 0) { for (ref = remote_refs; ref; ref = ref->next) ref->status = REF_STATUS_NONE; if (args->stateless_rpc) close(out); if (git_connection_is_socket(conn)) shutdown(fd[0], SHUT_WR); if (use_sideband) { close(demux.out); finish_async(&demux); } fd[1] = -1; return -1; } if (!args->stateless_rpc) /* Closed by pack_objects() via start_command() */ fd[1] = -1; } if (args->stateless_rpc && cmds_sent) packet_flush(out); if (status_report && cmds_sent) ret = receive_status(in, remote_refs); else ret = 0; if (args->stateless_rpc) packet_flush(out); if (use_sideband && cmds_sent) { close(demux.out); if (finish_async(&demux)) { error("error in sideband demultiplexer"); ret = -1; } } if (ret < 0) return ret; if (args->porcelain) return 0; for (ref = remote_refs; ref; ref = ref->next) { switch (ref->status) { case REF_STATUS_NONE: case REF_STATUS_UPTODATE: case REF_STATUS_OK: break; default: return -1; } } return 0; }
static int update_clone(int argc, const char **argv, const char *prefix) { const char *update = NULL; int max_jobs = -1; struct string_list_item *item; struct pathspec pathspec; struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT; struct option module_update_clone_options[] = { OPT_STRING(0, "prefix", &prefix, N_("path"), N_("path into the working tree")), OPT_STRING(0, "recursive-prefix", &suc.recursive_prefix, N_("path"), N_("path into the working tree, across nested " "submodule boundaries")), OPT_STRING(0, "update", &update, N_("string"), N_("rebase, merge, checkout or none")), OPT_STRING_LIST(0, "reference", &suc.references, N_("repo"), N_("reference repository")), OPT_STRING(0, "depth", &suc.depth, "<depth>", N_("Create a shallow clone truncated to the " "specified number of revisions")), OPT_INTEGER('j', "jobs", &max_jobs, N_("parallel jobs")), OPT_BOOL(0, "recommend-shallow", &suc.recommend_shallow, N_("whether the initial clone should follow the shallow recommendation")), OPT__QUIET(&suc.quiet, N_("don't print cloning progress")), OPT_BOOL(0, "progress", &suc.progress, N_("force cloning progress")), OPT_END() }; const char *const git_submodule_helper_usage[] = { N_("git submodule--helper update_clone [--prefix=<path>] [<path>...]"), NULL }; suc.prefix = prefix; argc = parse_options(argc, argv, prefix, module_update_clone_options, git_submodule_helper_usage, 0); if (update) if (parse_submodule_update_strategy(update, &suc.update) < 0) die(_("bad value for update parameter")); if (module_list_compute(argc, argv, prefix, &pathspec, &suc.list) < 0) return 1; if (pathspec.nr) suc.warn_if_uninitialized = 1; /* Overlay the parsed .gitmodules file with .git/config */ gitmodules_config(); git_config(submodule_config, NULL); if (max_jobs < 0) max_jobs = parallel_submodules(); run_processes_parallel(max_jobs, update_clone_get_next_task, update_clone_start_failure, update_clone_task_finished, &suc); /* * We saved the output and put it out all at once now. * That means: * - the listener does not have to interleave their (checkout) * work with our fetching. The writes involved in a * checkout involve more straightforward sequential I/O. * - the listener can avoid doing any work if fetching failed. */ if (suc.quickstop) return 1; for_each_string_list_item(item, &suc.projectlines) utf8_fprintf(stdout, "%s", item->string); return 0; }
/** * Determine whether 'ce' needs to be cloned. If so, prepare the 'child' to * run the clone. Returns 1 if 'ce' needs to be cloned, 0 otherwise. */ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, struct child_process *child, struct submodule_update_clone *suc, struct strbuf *out) { const struct submodule *sub = NULL; struct strbuf displaypath_sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT; const char *displaypath = NULL; int needs_cloning = 0; if (ce_stage(ce)) { if (suc->recursive_prefix) strbuf_addf(&sb, "%s/%s", suc->recursive_prefix, ce->name); else strbuf_addstr(&sb, ce->name); strbuf_addf(out, _("Skipping unmerged submodule %s"), sb.buf); strbuf_addch(out, '\n'); goto cleanup; } sub = submodule_from_path(null_sha1, ce->name); if (suc->recursive_prefix) displaypath = relative_path(suc->recursive_prefix, ce->name, &displaypath_sb); else displaypath = ce->name; if (!sub) { next_submodule_warn_missing(suc, out, displaypath); goto cleanup; } if (suc->update.type == SM_UPDATE_NONE || (suc->update.type == SM_UPDATE_UNSPECIFIED && sub->update_strategy.type == SM_UPDATE_NONE)) { strbuf_addf(out, _("Skipping submodule '%s'"), displaypath); strbuf_addch(out, '\n'); goto cleanup; } /* Check if the submodule has been initialized. */ if (!is_submodule_initialized(ce->name)) { next_submodule_warn_missing(suc, out, displaypath); goto cleanup; } strbuf_reset(&sb); strbuf_addf(&sb, "%s/.git", ce->name); needs_cloning = !file_exists(sb.buf); strbuf_reset(&sb); strbuf_addf(&sb, "%06o %s %d %d\t%s\n", ce->ce_mode, oid_to_hex(&ce->oid), ce_stage(ce), needs_cloning, ce->name); string_list_append(&suc->projectlines, sb.buf); if (!needs_cloning) goto cleanup; child->git_cmd = 1; child->no_stdin = 1; child->stdout_to_stderr = 1; child->err = -1; argv_array_push(&child->args, "submodule--helper"); argv_array_push(&child->args, "clone"); if (suc->progress) argv_array_push(&child->args, "--progress"); if (suc->quiet) argv_array_push(&child->args, "--quiet"); if (suc->prefix) argv_array_pushl(&child->args, "--prefix", suc->prefix, NULL); if (suc->recommend_shallow && sub->recommend_shallow == 1) argv_array_push(&child->args, "--depth=1"); argv_array_pushl(&child->args, "--path", sub->path, NULL); argv_array_pushl(&child->args, "--name", sub->name, NULL); argv_array_pushl(&child->args, "--url", sub->url, NULL); if (suc->references.nr) { struct string_list_item *item; for_each_string_list_item(item, &suc->references) argv_array_pushl(&child->args, "--reference", item->string, NULL); } if (suc->depth) argv_array_push(&child->args, suc->depth); cleanup: strbuf_reset(&displaypath_sb); strbuf_reset(&sb); return needs_cloning; }