diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt index e30c602f476da2da632d2cd04396d168c80ab233..b43458eae6787caab163fadab113dff61e577498 100644 --- a/Documentation/technical/api-parse-options.txt +++ b/Documentation/technical/api-parse-options.txt @@ -137,6 +137,10 @@ There are some macros to easily define options: Introduce a boolean option. If used, `int_var` is bitwise-ored with `mask`. +`OPT_NEGBIT(short, long, &int_var, description, mask)`:: + Introduce a boolean option. + If used, `int_var` is bitwise-anded with the inverted `mask`. + `OPT_SET_INT(short, long, &int_var, description, integer)`:: Introduce a boolean option. If used, set `int_var` to `integer`. @@ -166,6 +170,14 @@ There are some macros to easily define options: `OPT_ARGUMENT(long, description)`:: Introduce a long-option argument that will be kept in `argv[]`. +`OPT_NUMBER_CALLBACK(&var, description, func_ptr)`:: + Recognize numerical options like -123 and feed the integer as + if it was an argument to the function given by `func_ptr`. + The result will be put into `var`. There can be only one such + option definition. It cannot be negated and it takes no + arguments. Short options that happen to be digits take + precedence over it. + The last element of the array must be `OPT_END()`. diff --git a/builtin-grep.c b/builtin-grep.c index f88a912ace9195c387566770432a904e2d7adcb7..5308b346e69a50d7695b26f3b8e00bfdf71e1dd2 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -10,6 +10,7 @@ #include "tag.h" #include "tree-walk.h" #include "builtin.h" +#include "parse-options.h" #include "grep.h" #ifndef NO_EXTERNAL_GREP @@ -20,7 +21,10 @@ #endif #endif -static int builtin_grep; +static char const * const grep_usage[] = { + "git grep [options] [-e] [...] [[--] path...]", + NULL +}; static int grep_config(const char *var, const char *value, void *cb) { @@ -432,7 +436,8 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached) } #endif -static int grep_cache(struct grep_opt *opt, const char **paths, int cached) +static int grep_cache(struct grep_opt *opt, const char **paths, int cached, + int external_grep_allowed) { int hit = 0; int nr; @@ -444,7 +449,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached) * we grep through the checked-out files. It tends to * be a lot more optimized */ - if (!cached && !builtin_grep) { + if (!cached && external_grep_allowed) { hit = external_grep(opt, paths, cached); if (hit >= 0) return hit; @@ -560,25 +565,182 @@ static int grep_object(struct grep_opt *opt, const char **paths, die("unable to grep from object of type %s", typename(obj->type)); } -static const char builtin_grep_usage[] = -"git grep