Merge branch 'ps/test-chmtime-get'
[gitweb.git] / builtin / grep.c
index aad422bb6481cac4a37f40845bba533c8f90e285..5f32d2ce84f27bca725c12aa51d2d91a0c38be8b 100644 (file)
@@ -22,6 +22,7 @@
 #include "pathspec.h"
 #include "submodule.h"
 #include "submodule-config.h"
+#include "object-store.h"
 
 static char const * const grep_usage[] = {
        N_("git grep [<options>] [-e] <pattern> [<rev>...] [[--] <path>...]"),
@@ -306,7 +307,7 @@ static void *lock_and_read_oid_file(const struct object_id *oid, enum object_typ
        void *data;
 
        grep_read_lock();
-       data = read_sha1_file(oid->hash, type, size);
+       data = read_object_file(oid, type, size);
        grep_read_unlock();
        return data;
 }
@@ -326,6 +327,7 @@ static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
        }
 
        grep_source_init(&gs, GREP_SOURCE_OID, pathbuf.buf, path, oid);
+       strbuf_release(&pathbuf);
 
 #ifndef NO_PTHREADS
        if (num_threads) {
@@ -334,14 +336,12 @@ static int grep_oid(struct grep_opt *opt, const struct object_id *oid,
                 * its fields, so do not call grep_source_clear()
                 */
                add_work(opt, &gs);
-               strbuf_release(&pathbuf);
                return 0;
        } else
 #endif
        {
                int hit;
 
-               strbuf_release(&pathbuf);
                hit = grep_source(opt, &gs);
 
                grep_source_clear(&gs);
@@ -360,6 +360,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
                strbuf_addstr(&buf, filename);
 
        grep_source_init(&gs, GREP_SOURCE_FILE, buf.buf, filename, filename);
+       strbuf_release(&buf);
 
 #ifndef NO_PTHREADS
        if (num_threads) {
@@ -368,14 +369,12 @@ static int grep_file(struct grep_opt *opt, const char *filename)
                 * its fields, so do not call grep_source_clear()
                 */
                add_work(opt, &gs);
-               strbuf_release(&buf);
                return 0;
        } else
 #endif
        {
                int hit;
 
-               strbuf_release(&buf);
                hit = grep_source(opt, &gs);
 
                grep_source_clear(&gs);
@@ -441,7 +440,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
         * object.
         */
        grep_read_lock();
-       add_to_alternates_memory(submodule.objectdir);
+       add_to_alternates_memory(submodule.objects->objectdir);
        grep_read_unlock();
 
        if (oid) {
@@ -454,7 +453,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
                object = parse_object_or_die(oid, oid_to_hex(oid));
 
                grep_read_lock();
-               data = read_object_with_reference(object->oid.hash, tree_type,
+               data = read_object_with_reference(&object->oid, tree_type,
                                                  &size, NULL);
                grep_read_unlock();
 
@@ -616,7 +615,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
                int hit, len;
 
                grep_read_lock();
-               data = read_object_with_reference(obj->oid.hash, tree_type,
+               data = read_object_with_reference(&obj->oid, tree_type,
                                                  &size, NULL);
                grep_read_unlock();
 
@@ -636,7 +635,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
                free(data);
                return hit;
        }
-       die(_("unable to grep from object of type %s"), typename(obj->type));
+       die(_("unable to grep from object of type %s"), type_name(obj->type));
 }
 
 static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
@@ -841,8 +840,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                OPT_BOOL('L', "files-without-match",
                        &opt.unmatch_name_only,
                        N_("show only the names of files without match")),
-               OPT_BOOL('z', "null", &opt.null_following_name,
-                       N_("print NUL after filenames")),
+               OPT_BOOL_F('z', "null", &opt.null_following_name,
+                          N_("print NUL after filenames"),
+                          PARSE_OPT_NOCOMPLETE),
                OPT_BOOL('c', "count", &opt.count,
                        N_("show the number of matches instead of matching lines")),
                OPT__COLOR(&opt.color, N_("highlight matches")),
@@ -893,9 +893,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                OPT_GROUP(""),
                { OPTION_STRING, 'O', "open-files-in-pager", &show_in_pager,
                        N_("pager"), N_("show matching files in the pager"),
-                       PARSE_OPT_OPTARG, NULL, (intptr_t)default_pager },
-               OPT_BOOL(0, "ext-grep", &external_grep_allowed__ignored,
-                        N_("allow calling of grep(1) (ignored by this build)")),
+                       PARSE_OPT_OPTARG | PARSE_OPT_NOCOMPLETE,
+                       NULL, (intptr_t)default_pager },
+               OPT_BOOL_F(0, "ext-grep", &external_grep_allowed__ignored,
+                          N_("allow calling of grep(1) (ignored by this build)"),
+                          PARSE_OPT_NOCOMPLETE),
                OPT_END()
        };