From: Junio C Hamano <gitster@pobox.com> Date: Tue, 22 Aug 2017 17:29:01 +0000 (-0700) Subject: Merge branch 'bw/grep-recurse-submodules' X-Git-Tag: v2.15.0-rc0~179 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/5aa0b6c506c1f1336d0e713bf8225509e9ebb9f5 Merge branch 'bw/grep-recurse-submodules' "git grep --recurse-submodules" has been reworked to give a more consistent output across submodule boundary (and do its thing without having to fork a separate process). * bw/grep-recurse-submodules: grep: recurse in-process using 'struct repository' submodule: merge repo_read_gitmodules and gitmodules_config submodule: check for unmerged .gitmodules outside of config parsing submodule: check for unstaged .gitmodules outside of config parsing submodule: remove fetch.recursesubmodules from submodule-config parsing submodule: remove submodule.fetchjobs from submodule-config parsing config: add config_from_gitmodules cache.h: add GITMODULES_FILE macro repository: have the_repository use the_index repo_read_index: don't discard the index --- 5aa0b6c506c1f1336d0e713bf8225509e9ebb9f5 diff --cc builtin/grep.c index 3cbee04dc4,cd0e51f3c0..a70d8e2fba --- a/builtin/grep.c +++ b/builtin/grep.c @@@ -862,9 -643,10 +643,10 @@@ static int grep_objects(struct grep_op /* load the gitmodules file for this rev */ if (recurse_submodules) { submodule_free(); - gitmodules_config_sha1(real_obj->oid.hash); + gitmodules_config_oid(&real_obj->oid); } - if (grep_object(opt, pathspec, real_obj, list->objects[i].name, list->objects[i].path)) { + if (grep_object(opt, pathspec, real_obj, list->objects[i].name, list->objects[i].path, + repo)) { hit = 1; if (opt->status_only) break; diff --cc submodule.c index 6ba15b4137,9d5eacaf9f..e072036e79 --- a/submodule.c +++ b/submodule.c @@@ -63,13 -79,13 +79,13 @@@ int update_path_in_gitmodules(const cha struct strbuf entry = STRBUF_INIT; const struct submodule *submodule; - if (!file_exists(".gitmodules")) /* Do nothing without .gitmodules */ + if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */ return -1; - if (gitmodules_is_unmerged) + if (is_gitmodules_unmerged(&the_index)) die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first")); - submodule = submodule_from_path(null_sha1, oldpath); + submodule = submodule_from_path(&null_oid, oldpath); if (!submodule || !submodule->name) { warning(_("Could not find section in .gitmodules where path=%s"), oldpath); return -1; @@@ -97,13 -113,13 +113,13 @@@ int remove_path_from_gitmodules(const c struct strbuf sect = STRBUF_INIT; const struct submodule *submodule; - if (!file_exists(".gitmodules")) /* Do nothing without .gitmodules */ + if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */ return -1; - if (gitmodules_is_unmerged) + if (is_gitmodules_unmerged(&the_index)) die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first")); - submodule = submodule_from_path(null_sha1, path); + submodule = submodule_from_path(&null_oid, path); if (!submodule || !submodule->name) { warning(_("Could not find section in .gitmodules where path=%s"), path); return -1; @@@ -264,20 -238,34 +238,34 @@@ static int gitmodules_cb(const char *va void repo_read_gitmodules(struct repository *repo) { - char *gitmodules_path = repo_worktree_path(repo, ".gitmodules"); + if (repo->worktree) { + char *gitmodules; + + if (repo_read_index(repo) < 0) + return; + + gitmodules = repo_worktree_path(repo, GITMODULES_FILE); + + if (!is_gitmodules_unmerged(repo->index)) + git_config_from_file(gitmodules_cb, gitmodules, repo); + + free(gitmodules); + } + } - git_config_from_file(gitmodules_cb, gitmodules_path, repo); - free(gitmodules_path); + void gitmodules_config(void) + { + repo_read_gitmodules(the_repository); } -void gitmodules_config_sha1(const unsigned char *commit_sha1) +void gitmodules_config_oid(const struct object_id *commit_oid) { struct strbuf rev = STRBUF_INIT; - unsigned char sha1[20]; + struct object_id oid; - if (gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) { - git_config_from_blob_sha1(git_modules_config, rev.buf, - sha1, NULL); + if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) { + git_config_from_blob_oid(submodule_config, rev.buf, + &oid, NULL); } strbuf_release(&rev); }