Code

fast-import: die_nicely() back to vsnprintf (reverts part of ebaa79f)
[git.git] / builtin-grep.c
index 46ffc1d1d917dd9388ae76899630b717811205a6..40b9a93127482bebf6dc8c9eb39b2104711a543a 100644 (file)
@@ -409,15 +409,25 @@ static int pathspec_matches(const char **paths, const char *name, int max_depth)
        return 0;
 }
 
+static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
+{
+       void *data;
+
+       if (use_threads) {
+               read_sha1_lock();
+               data = read_sha1_file(sha1, type, size);
+               read_sha1_unlock();
+       } else {
+               data = read_sha1_file(sha1, type, size);
+       }
+       return data;
+}
+
 static void *load_sha1(const unsigned char *sha1, unsigned long *size,
                       const char *name)
 {
        enum object_type type;
-       char *data;
-
-       read_sha1_lock();
-       data = read_sha1_file(sha1, &type, size);
-       read_sha1_unlock();
+       void *data = lock_and_read_sha1_file(sha1, &type, size);
 
        if (!data)
                error("'%s': unable to read %s", name, sha1_to_hex(sha1));
@@ -606,10 +616,7 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
                        void *data;
                        unsigned long size;
 
-                       read_sha1_lock();
-                       data = read_sha1_file(entry.sha1, &type, &size);
-                       read_sha1_unlock();
-
+                       data = lock_and_read_sha1_file(entry.sha1, &type, &size);
                        if (!data)
                                die("unable to read tree (%s)",
                                    sha1_to_hex(entry.sha1));
@@ -804,7 +811,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                        "print NUL after filenames"),
                OPT_BOOLEAN('c', "count", &opt.count,
                        "show the number of matches instead of matching lines"),
-               OPT_SET_INT(0, "color", &opt.color, "highlight matches", 1),
+               OPT__COLOR(&opt.color, "highlight matches"),
                OPT_GROUP(""),
                OPT_CALLBACK('C', NULL, &opt, "n",
                        "show <n> context lines before and after matches",
@@ -861,6 +868,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
        opt.relative = 1;
        opt.pathname = 1;
        opt.pattern_tail = &opt.pattern_list;
+       opt.header_tail = &opt.header_list;
        opt.regflags = REG_NEWLINE;
        opt.max_depth = -1;