]> git.ipfire.org Git - thirdparty/git.git/blobdiff - diffcore-pickaxe.c
diffcore-pickaxe: Add regcomp_or_die()
[thirdparty/git.git] / diffcore-pickaxe.c
index 7715c13ec4780a755ec2a6552c0aec9994691087..2093b6ab75c6348c50b016d6a157c66d733ff747 100644 (file)
@@ -198,6 +198,18 @@ static void pickaxe(struct diff_queue_struct *q, struct diff_options *o,
        *q = outq;
 }
 
+static void regcomp_or_die(regex_t *regex, const char *needle, int cflags)
+{
+       int err = regcomp(regex, needle, cflags);
+       if (err) {
+               /* The POSIX.2 people are surely sick */
+               char errbuf[1024];
+               regerror(err, regex, errbuf, 1024);
+               regfree(regex);
+               die("invalid regex: %s", errbuf);
+       }
+}
+
 void diffcore_pickaxe(struct diff_options *o)
 {
        const char *needle = o->pickaxe;
@@ -206,18 +218,10 @@ void diffcore_pickaxe(struct diff_options *o)
        kwset_t kws = NULL;
 
        if (opts & (DIFF_PICKAXE_REGEX | DIFF_PICKAXE_KIND_G)) {
-               int err;
                int cflags = REG_EXTENDED | REG_NEWLINE;
                if (DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE))
                        cflags |= REG_ICASE;
-               err = regcomp(&regex, needle, cflags);
-               if (err) {
-                       /* The POSIX.2 people are surely sick */
-                       char errbuf[1024];
-                       regerror(err, &regex, errbuf, 1024);
-                       regfree(&regex);
-                       die("invalid regex: %s", errbuf);
-               }
+               regcomp_or_die(&regex, needle, cflags);
                regexp = &regex;
        } else {
                kws = kwsalloc(DIFF_OPT_TST(o, PICKAXE_IGNORE_CASE)