pickaxe: merge diffcore_pickaxe_grep() and diffcore_pickaxe_count() into diffcore_pickaxe()
diffcore_pickaxe_count() initializes the regular expression or kwset for the search term, calls pickaxe() with the callback has_changes() and cleans up afterwards. diffcore_pickaxe_grep() does the same, only it doesn't support kwset and uses the callback diff_grep() instead. Merge the two functions to form the new diffcore_pickaxe() and thus get rid of the duplicate regex setup and cleanup code. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Mar 22, 2014 at 18:15 UTC
63b52afaa88bf89c781fe11c6803ff1dcc47d424
1 file changed
+7
-37
diffcore-pickaxe.c
+7
-37
@@ -108,29 +108,6 @@ static int diff_grep(mmfile_t *one, mmfile_t *two,
108
return ecbdata.hit;
109
}
110
111
-static void diffcore_pickaxe_grep(struct diff_options *o)
112
-{
113
- int err;
114
- regex_t regex;
115
- int cflags = REG_EXTENDED | REG_NEWLINE;
116
-
117
- if (DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE))
118
- cflags |= REG_ICASE;
119
-
120
- err = regcomp(®ex, o->pickaxe, cflags);
121
- if (err) {
122
- char errbuf[1024];
123
- regerror(err, ®ex, errbuf, 1024);
124
- regfree(®ex);
125
- die("invalid regex: %s", errbuf);
126
- }
127
-
128
- pickaxe(&diff_queued_diff, o, ®ex, NULL, diff_grep);
129
-
130
- regfree(®ex);
131
- return;
132
-}
133
-
111
static unsigned int contains(mmfile_t *mf, regex_t *regexp, kwset_t kws)
112
{
113
unsigned int cnt;
@@ -227,7 +204,7 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
204
return ret;
205
}
206
230
-static void diffcore_pickaxe_count(struct diff_options *o)
207
+void diffcore_pickaxe(struct diff_options *o)
208
{
209
const char *needle = o->pickaxe;
210
int opts = o->pickaxe_opts;
@@ -235,7 +212,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
212
regex_t regex, *regexp = NULL;
213
kwset_t kws = NULL;
214
238
- if (opts & DIFF_PICKAXE_REGEX) {
215
+ if (opts & (DIFF_PICKAXE_REGEX | DIFF_PICKAXE_KIND_G)) {
216
int err;
217
int cflags = REG_EXTENDED | REG_NEWLINE;
218
if (DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE))
@@ -256,20 +233,13 @@ static void diffcore_pickaxe_count(struct diff_options *o)
233
kwsprep(kws);
234
}
235
259
- pickaxe(&diff_queued_diff, o, regexp, kws, has_changes);
236
+ /* Might want to warn when both S and G are on; I don't care... */
237
+ pickaxe(&diff_queued_diff, o, regexp, kws,
238
+ (opts & DIFF_PICKAXE_KIND_G) ? diff_grep : has_changes);
239
261
- if (opts & DIFF_PICKAXE_REGEX)
262
- regfree(®ex);
240
+ if (regexp)
241
+ regfree(regexp);
242
else
243
kwsfree(kws);
244
return;
245
}
267
-
268
-void diffcore_pickaxe(struct diff_options *o)
269
-{
270
- /* Might want to warn when both S and G are on; I don't care... */
271
- if (o->pickaxe_opts & DIFF_PICKAXE_KIND_G)
272
- diffcore_pickaxe_grep(o);
273
- else
274
- diffcore_pickaxe_count(o);
275
-}