request-pull: quote regex metacharacters in local ref
[gitweb.git] / builtin / grep.c
index 0cc671f7d6396dc03986a27d30b0149db1ebd9be..580fd38f41704b6d534c04f2dee1bf85eee67c3c 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (c) 2006 Junio C Hamano
  */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "repository.h"
 #include "config.h"
@@ -404,8 +405,10 @@ static int grep_submodule(struct grep_opt *opt,
                          const struct object_id *oid,
                          const char *filename, const char *path)
 {
+       struct repository subrepo;
        struct repository *superproject = opt->repo;
-       struct repository submodule;
+       const struct submodule *sub = submodule_from_path(superproject,
+                                                         &null_oid, path);
        struct grep_opt subopt;
        int hit;
 
@@ -422,12 +425,12 @@ static int grep_submodule(struct grep_opt *opt,
                return 0;
        }
 
-       if (repo_submodule_init(&submodule, superproject, path)) {
+       if (repo_submodule_init(&subrepo, superproject, sub)) {
                grep_read_unlock();
                return 0;
        }
 
-       repo_read_gitmodules(&submodule);
+       repo_read_gitmodules(&subrepo);
 
        /*
         * NEEDSWORK: This adds the submodule's object directory to the list of
@@ -439,11 +442,11 @@ static int grep_submodule(struct grep_opt *opt,
         * store is no longer global and instead is a member of the repository
         * object.
         */
-       add_to_alternates_memory(submodule.objects->odb->path);
+       add_to_alternates_memory(subrepo.objects->odb->path);
        grep_read_unlock();
 
        memcpy(&subopt, opt, sizeof(subopt));
-       subopt.repo = &submodule;
+       subopt.repo = &subrepo;
 
        if (oid) {
                struct object *object;
@@ -474,7 +477,7 @@ static int grep_submodule(struct grep_opt *opt,
                hit = grep_cache(&subopt, pathspec, 1);
        }
 
-       repo_clear(&submodule);
+       repo_clear(&subrepo);
        return hit;
 }
 
@@ -560,7 +563,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
 
                if (match != all_entries_interesting) {
                        strbuf_addstr(&name, base->buf + tn_len);
-                       match = tree_entry_interesting(&entry, &name,
+                       match = tree_entry_interesting(repo->index,
+                                                      &entry, &name,
                                                       0, pathspec);
                        strbuf_setlen(&name, name_base_len);
 
@@ -573,7 +577,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
                strbuf_add(base, entry.path, te_len);
 
                if (S_ISREG(entry.mode)) {
-                       hit |= grep_oid(opt, entry.oid, base->buf, tn_len,
+                       hit |= grep_oid(opt, &entry.oid, base->buf, tn_len,
                                         check_attr ? base->buf + tn_len : NULL);
                } else if (S_ISDIR(entry.mode)) {
                        enum object_type type;
@@ -581,10 +585,10 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
                        void *data;
                        unsigned long size;
 
-                       data = lock_and_read_oid_file(entry.oid, &type, &size);
+                       data = lock_and_read_oid_file(&entry.oid, &type, &size);
                        if (!data)
                                die(_("unable to read tree (%s)"),
-                                   oid_to_hex(entry.oid));
+                                   oid_to_hex(&entry.oid));
 
                        strbuf_addch(base, '/');
                        init_tree_desc(&sub, data, size);
@@ -592,7 +596,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
                                         check_attr);
                        free(data);
                } else if (recurse_submodules && S_ISGITLINK(entry.mode)) {
-                       hit |= grep_submodule(opt, pathspec, entry.oid,
+                       hit |= grep_submodule(opt, pathspec, &entry.oid,
                                              base->buf, base->buf + tn_len);
                }
 
@@ -1021,7 +1025,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                        break;
                }
 
-               if (get_oid_with_context(arg, GET_OID_RECORD_PATH,
+               if (get_oid_with_context(the_repository, arg,
+                                        GET_OID_RECORD_PATH,
                                         &oid, &oc)) {
                        if (seen_dashdash)
                                die(_("unable to resolve revision: %s"), arg);