static int is_active(int argc, const char **argv, const char *prefix) { if (argc != 2) die("submodule--helper is-active takes exactly 1 argument"); gitmodules_config(); return !is_submodule_initialized(argv[1]); }
/* * Prep grep structures for a submodule grep * sha1: the sha1 of the submodule or NULL if using the working tree * filename: name of the submodule including tree name of parent * path: location of the submodule */ static int grep_submodule(struct grep_opt *opt, const unsigned char *sha1, const char *filename, const char *path) { if (!is_submodule_initialized(path)) return 0; if (!is_submodule_populated(path)) { /* * If searching history, check for the presense of the * submodule's gitdir before skipping the submodule. */ if (sha1) { const struct submodule *sub = submodule_from_path(null_sha1, path); if (sub) path = git_path("modules/%s", sub->name); if (!(is_directory(path) && is_git_directory(path))) return 0; } else { return 0; } } #ifndef NO_PTHREADS if (num_threads) { add_work(opt, GREP_SOURCE_SUBMODULE, filename, path, sha1); return 0; } else #endif { struct work_item w; int hit; grep_source_init(&w.source, GREP_SOURCE_SUBMODULE, filename, path, sha1); strbuf_init(&w.out, 0); opt->output_priv = &w; hit = grep_submodule_launch(opt, &w.source); write_or_die(1, w.out.buf, w.out.len); grep_source_clear(&w.source); strbuf_release(&w.out); return hit; } }
static void module_list_active(struct module_list *list) { int i; struct module_list active_modules = MODULE_LIST_INIT; gitmodules_config(); for (i = 0; i < list->nr; i++) { const struct cache_entry *ce = list->entries[i]; if (!is_submodule_initialized(ce->name)) continue; ALLOC_GROW(active_modules.entries, active_modules.nr + 1, active_modules.alloc); active_modules.entries[active_modules.nr++] = ce; } free(list->entries); *list = active_modules; }
/** * 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; }
static void init_submodule(const char *path, const char *prefix, int quiet) { const struct submodule *sub; struct strbuf sb = STRBUF_INIT; char *upd = NULL, *url = NULL, *displaypath; /* Only loads from .gitmodules, no overlay with .git/config */ gitmodules_config(); if (prefix && get_super_prefix()) die("BUG: cannot have prefix and superprefix"); else if (prefix) displaypath = xstrdup(relative_path(path, prefix, &sb)); else if (get_super_prefix()) { strbuf_addf(&sb, "%s%s", get_super_prefix(), path); displaypath = strbuf_detach(&sb, NULL); } else displaypath = xstrdup(path); sub = submodule_from_path(null_sha1, path); if (!sub) die(_("No url found for submodule path '%s' in .gitmodules"), displaypath); /* * NEEDSWORK: In a multi-working-tree world, this needs to be * set in the per-worktree config. * * Set active flag for the submodule being initialized */ if (!is_submodule_initialized(path)) { strbuf_reset(&sb); strbuf_addf(&sb, "submodule.%s.active", sub->name); git_config_set_gently(sb.buf, "true"); } /* * Copy url setting when it is not set yet. * To look up the url in .git/config, we must not fall back to * .gitmodules, so look it up directly. */ strbuf_reset(&sb); strbuf_addf(&sb, "submodule.%s.url", sub->name); if (git_config_get_string(sb.buf, &url)) { url = xstrdup(sub->url); if (!url) die(_("No url found for submodule path '%s' in .gitmodules"), displaypath); /* Possibly a url relative to parent */ if (starts_with_dot_dot_slash(url) || starts_with_dot_slash(url)) { char *remoteurl, *relurl; char *remote = get_default_remote(); struct strbuf remotesb = STRBUF_INIT; strbuf_addf(&remotesb, "remote.%s.url", remote); free(remote); if (git_config_get_string(remotesb.buf, &remoteurl)) { warning(_("could not lookup configuration '%s'. Assuming this repository is its own authoritative upstream."), remotesb.buf); remoteurl = xgetcwd(); } relurl = relative_url(remoteurl, url, NULL); strbuf_release(&remotesb); free(remoteurl); free(url); url = relurl; } if (git_config_set_gently(sb.buf, url)) die(_("Failed to register url for submodule path '%s'"), displaypath); if (!quiet) fprintf(stderr, _("Submodule '%s' (%s) registered for path '%s'\n"), sub->name, url, displaypath); } /* Copy "update" setting when it is not set yet */ strbuf_reset(&sb); strbuf_addf(&sb, "submodule.%s.update", sub->name); if (git_config_get_string(sb.buf, &upd) && sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) { if (sub->update_strategy.type == SM_UPDATE_COMMAND) { fprintf(stderr, _("warning: command update mode suggested for submodule '%s'\n"), sub->name); upd = xstrdup("none"); } else upd = xstrdup(submodule_strategy_to_string(&sub->update_strategy)); if (git_config_set_gently(sb.buf, upd)) die(_("Failed to register update mode for submodule path '%s'"), displaypath); } strbuf_release(&sb); free(displaypath); free(url); free(upd); }