diffcore-pickaxe: Add regcomp_or_die()
There's another regcomp code block coming in this function that needs the same error handling. This function can help avoid duplicating error handling code. Helped-by: Jeff King <peff@peff.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jun 25, 2016 at 07:22 UTC
3d5b23a36218b0417a056fa7b5e6d25d595ccaf2
1 file changed
+13
-9
diffcore-pickaxe.c
+13
-9
@@ -198,6 +198,18 @@ static void pickaxe(struct diff_queue_struct *q, struct diff_options *o,
198
*q = outq;
199
}
200
201
+static void regcomp_or_die(regex_t *regex, const char *needle, int cflags)
202
+{
203
+ int err = regcomp(regex, needle, cflags);
204
+ if (err) {
205
+ /* The POSIX.2 people are surely sick */
206
+ char errbuf[1024];
207
+ regerror(err, regex, errbuf, 1024);
208
+ regfree(regex);
209
+ die("invalid regex: %s", errbuf);
210
+ }
211
+}
212
+
213
void diffcore_pickaxe(struct diff_options *o)
214
{
215
const char *needle = o->pickaxe;
@@ -206,18 +218,10 @@ void diffcore_pickaxe(struct diff_options *o)
218
kwset_t kws = NULL;
219
220
if (opts & (DIFF_PICKAXE_REGEX | DIFF_PICKAXE_KIND_G)) {
209
- int err;
221
int cflags = REG_EXTENDED | REG_NEWLINE;
222
if (DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE))
223
cflags |= REG_ICASE;
213
- err = regcomp(®ex, needle, cflags);
214
- if (err) {
215
- /* The POSIX.2 people are surely sick */
216
- char errbuf[1024];
217
- regerror(err, ®ex, errbuf, 1024);
218
- regfree(®ex);
219
- die("invalid regex: %s", errbuf);
220
- }
224
+ regcomp_or_die(®ex, needle, cflags);
225
regexp = ®ex;
226
} else {
227
kws = kwsalloc(DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE)