Merge branch 'pb/rename-rowin32'
[gitweb.git] / xdiff-interface.c
index 944ad9887f5c94ca0e63f9a6c901447634f871ce..49e06af710ceee5538eb10f0c6cf9c30f31748b4 100644 (file)
@@ -191,34 +191,57 @@ struct ff_regs {
 static long ff_regexp(const char *line, long len,
                char *buffer, long buffer_size, void *priv)
 {
-       char *line_buffer = xstrndup(line, len); /* make NUL terminated */
+       char *line_buffer;
        struct ff_regs *regs = priv;
        regmatch_t pmatch[2];
-       int result = 0, i;
+       int i;
+       int result = -1;
+
+       /* Exclude terminating newline (and cr) from matching */
+       if (len > 0 && line[len-1] == '\n') {
+               if (len > 1 && line[len-2] == '\r')
+                       len -= 2;
+               else
+                       len--;
+       }
+
+       line_buffer = xstrndup(line, len); /* make NUL terminated */
+
+       /* Exclude terminating newline (and cr) from matching */
+       if (len > 0 && line[len-1] == '\n') {
+               if (len > 1 && line[len-2] == '\r')
+                       len -= 2;
+               else
+                       len--;
+       }
+
+       line_buffer = xstrndup(line, len); /* make NUL terminated */
 
        for (i = 0; i < regs->nr; i++) {
                struct ff_reg *reg = regs->array + i;
-               if (reg->negate ^ !!regexec(&reg->re,
-                                       line_buffer, 2, pmatch, 0)) {
-                       free(line_buffer);
-                       return -1;
+               if (!regexec(&reg->re, line_buffer, 2, pmatch, 0)) {
+                       if (reg->negate)
+                               goto fail;
+                       break;
                }
        }
+       if (regs->nr <= i)
+               goto fail;
        i = pmatch[1].rm_so >= 0 ? 1 : 0;
        line += pmatch[i].rm_so;
        result = pmatch[i].rm_eo - pmatch[i].rm_so;
        if (result > buffer_size)
                result = buffer_size;
        else
-               while (result > 0 && (isspace(line[result - 1]) ||
-                                       line[result - 1] == '\n'))
+               while (result > 0 && (isspace(line[result - 1])))
                        result--;
        memcpy(buffer, line, result);
+ fail:
        free(line_buffer);
        return result;
 }
 
-void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value)
+void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value, int cflags)
 {
        int i;
        struct ff_regs *regs;
@@ -243,9 +266,29 @@ void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value)
                        expression = buffer = xstrndup(value, ep - value);
                else
                        expression = value;
-               if (regcomp(&reg->re, expression, 0))
+               if (regcomp(&reg->re, expression, cflags))
                        die("Invalid regexp to look for hunk header: %s", expression);
                free(buffer);
                value = ep + 1;
        }
 }
+
+int git_xmerge_style = -1;
+
+int git_xmerge_config(const char *var, const char *value, void *cb)
+{
+       if (!strcasecmp(var, "merge.conflictstyle")) {
+               if (!value)
+                       die("'%s' is not a boolean", var);
+               if (!strcmp(value, "diff3"))
+                       git_xmerge_style = XDL_MERGE_DIFF3;
+               else if (!strcmp(value, "merge"))
+                       git_xmerge_style = 0;
+               else
+                       die("unknown style '%s' given for '%s'",
+                           value, var);
+               return 0;
+       }
+       return git_default_config(var, value, cb);
+}
+