Skip to content

Commit 63b52af

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 218c45a commit 63b52af

File tree

1 file changed

+7
-37
lines changed

1 file changed

+7
-37
lines changed

diffcore-pickaxe.c

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -108,29 +108,6 @@ static int diff_grep(mmfile_t *one, mmfile_t *two,
108108
return ecbdata.hit;
109109
}
110110

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(&regex, o->pickaxe, cflags);
121-
if (err) {
122-
char errbuf[1024];
123-
regerror(err, &regex, errbuf, 1024);
124-
regfree(&regex);
125-
die("invalid regex: %s", errbuf);
126-
}
127-
128-
pickaxe(&diff_queued_diff, o, &regex, NULL, diff_grep);
129-
130-
regfree(&regex);
131-
return;
132-
}
133-
134111
static unsigned int contains(mmfile_t *mf, regex_t *regexp, kwset_t kws)
135112
{
136113
unsigned int cnt;
@@ -227,15 +204,15 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
227204
return ret;
228205
}
229206

230-
static void diffcore_pickaxe_count(struct diff_options *o)
207+
void diffcore_pickaxe(struct diff_options *o)
231208
{
232209
const char *needle = o->pickaxe;
233210
int opts = o->pickaxe_opts;
234211
unsigned long len = strlen(needle);
235212
regex_t regex, *regexp = NULL;
236213
kwset_t kws = NULL;
237214

238-
if (opts & DIFF_PICKAXE_REGEX) {
215+
if (opts & (DIFF_PICKAXE_REGEX | DIFF_PICKAXE_KIND_G)) {
239216
int err;
240217
int cflags = REG_EXTENDED | REG_NEWLINE;
241218
if (DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE))
@@ -256,20 +233,13 @@ static void diffcore_pickaxe_count(struct diff_options *o)
256233
kwsprep(kws);
257234
}
258235

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);
260239

261-
if (opts & DIFF_PICKAXE_REGEX)
262-
regfree(&regex);
240+
if (regexp)
241+
regfree(regexp);
263242
else
264243
kwsfree(kws);
265244
return;
266245
}
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-
}

0 commit comments

Comments
 (0)