In preparation of adding --column-number to 'git-grep(1)', we extend
grep_opt to take in the requisite new members.

We additionally teach the 'grep.columnnumber' and
'color.grep.columnumber' configuration variables to configure showing
and coloring the column number, respectively. (These options remain
undocumented until 'git-grep(1)' learns the --column option in a
forthcoming commit.)

Signed-off-by: Taylor Blau <m...@ttaylorr.com>
---
 grep.c | 8 ++++++++
 grep.h | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/grep.c b/grep.c
index 29bc799ecf..7872a5d868 100644
--- a/grep.c
+++ b/grep.c
@@ -95,6 +95,10 @@ int grep_config(const char *var, const char *value, void *cb)
                opt->linenum = git_config_bool(var, value);
                return 0;
        }
+       if (!strcmp(var, "grep.columnnumber")) {
+               opt->columnnum = git_config_bool(var, value);
+               return 0;
+       }
 
        if (!strcmp(var, "grep.fullname")) {
                opt->relative = !git_config_bool(var, value);
@@ -111,6 +115,8 @@ int grep_config(const char *var, const char *value, void 
*cb)
                color = opt->color_function;
        else if (!strcmp(var, "color.grep.linenumber"))
                color = opt->color_lineno;
+       else if (!strcmp(var, "color.grep.columnumber"))
+               color = opt->color_columnno;
        else if (!strcmp(var, "color.grep.matchcontext"))
                color = opt->color_match_context;
        else if (!strcmp(var, "color.grep.matchselected"))
@@ -155,6 +161,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)
        opt->extended_regexp_option = def->extended_regexp_option;
        opt->pattern_type_option = def->pattern_type_option;
        opt->linenum = def->linenum;
+       opt->columnnum = def->columnnum;
        opt->max_depth = def->max_depth;
        opt->pathname = def->pathname;
        opt->relative = def->relative;
@@ -164,6 +171,7 @@ void grep_init(struct grep_opt *opt, const char *prefix)
        color_set(opt->color_filename, def->color_filename);
        color_set(opt->color_function, def->color_function);
        color_set(opt->color_lineno, def->color_lineno);
+       color_set(opt->color_columnno, def->color_columnno);
        color_set(opt->color_match_context, def->color_match_context);
        color_set(opt->color_match_selected, def->color_match_selected);
        color_set(opt->color_selected, def->color_selected);
diff --git a/grep.h b/grep.h
index 399381c908..08a0b391c5 100644
--- a/grep.h
+++ b/grep.h
@@ -127,6 +127,7 @@ struct grep_opt {
        int prefix_length;
        regex_t regexp;
        int linenum;
+       int columnnum;
        int invert;
        int ignore_case;
        int status_only;
@@ -159,6 +160,7 @@ struct grep_opt {
        char color_filename[COLOR_MAXLEN];
        char color_function[COLOR_MAXLEN];
        char color_lineno[COLOR_MAXLEN];
+       char color_columnno[COLOR_MAXLEN];
        char color_match_context[COLOR_MAXLEN];
        char color_match_selected[COLOR_MAXLEN];
        char color_selected[COLOR_MAXLEN];
-- 
2.17.0

Reply via email to