Merge branch 'bw/grep-recurse-submodules' into next
authorJunio C Hamano <gitster@pobox.com>
Mon, 14 Aug 2017 22:22:51 +0000 (15:22 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 Aug 2017 22:22:51 +0000 (15:22 -0700)
"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

12 files changed:
1  2 
builtin/grep.c
builtin/submodule--helper.c
cache.h
config.c
config.h
git.c
repository.c
submodule-config.c
submodule-config.h
submodule.c
submodule.h
unpack-trees.c
diff --cc builtin/grep.c
index 3cbee04dc4164255148b7f4b0c6f8f6dcd86a8fe,cd0e51f3c04b1e6fc297a8806fa663d86ebc7734..a70d8e2fba9f4e371a069bd801d20dcfe195f485
@@@ -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;
Simple merge
diff --cc cache.h
Simple merge
diff --cc config.c
Simple merge
diff --cc config.h
Simple merge
diff --cc git.c
Simple merge
diff --cc repository.c
Simple merge
Simple merge
Simple merge
diff --cc submodule.c
index 27de65a4a04a45c75479ae60d43dfdab0cf6d1aa,9d5eacaf9f2ffad4a7f5d17ced4137e0162215d5..5139b9256b589a6524e6158dbb1c2ae492ea4f70
@@@ -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);
  }
diff --cc submodule.h
Simple merge
diff --cc unpack-trees.c
Simple merge