Code

user-manual: update for new default --track behavior
[git.git] / diff.c
diff --git a/diff.c b/diff.c
index b8473f58fbde20516bcfa1e0c1dcb2de16be819f..a5fc56bdad5d96b2a4e0e1140206b8367a257867 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1216,9 +1216,22 @@ static const char *funcname_pattern(const char *ident)
        return NULL;
 }
 
+static struct builtin_funcname_pattern {
+       const char *name;
+       const char *pattern;
+} builtin_funcname_pattern[] = {
+       { "java", "!^[  ]*\\(catch\\|do\\|for\\|if\\|instanceof\\|"
+                       "new\\|return\\|switch\\|throw\\|while\\)\n"
+                       "^[     ]*\\(\\([       ]*"
+                       "[A-Za-z_][A-Za-z_0-9]*\\)\\{2,\\}"
+                       "[      ]*([^;]*$\\)" },
+       { "tex", "^\\(\\\\\\(sub\\)*section{.*\\)$" },
+};
+
 static const char *diff_funcname_pattern(struct diff_filespec *one)
 {
        const char *ident, *pattern;
+       int i;
 
        diff_filespec_check_attr(one);
        ident = one->funcname_pattern_ident;
@@ -1240,12 +1253,9 @@ static const char *diff_funcname_pattern(struct diff_filespec *one)
         * And define built-in fallback patterns here.  Note that
         * these can be overriden by the user's config settings.
         */
-       if (!strcmp(ident, "java"))
-               return "!^[     ]*\\(catch\\|do\\|for\\|if\\|instanceof\\|"
-                       "new\\|return\\|switch\\|throw\\|while\\)\n"
-                       "^[     ]*\\(\\([       ]*"
-                       "[A-Za-z_][A-Za-z_0-9]*\\)\\{2,\\}"
-                       "[      ]*([^;]*$\\)";
+       for (i = 0; i < ARRAY_SIZE(builtin_funcname_pattern); i++)
+               if (!strcmp(ident, builtin_funcname_pattern[i].name))
+                       return builtin_funcname_pattern[i].pattern;
 
        return NULL;
 }
@@ -1685,7 +1695,7 @@ static void prep_temp_blob(struct diff_tempfile *temp,
 
        fd = git_mkstemp(temp->tmp_path, PATH_MAX, ".diff_XXXXXX");
        if (fd < 0)
-               die("unable to create temp-file");
+               die("unable to create temp-file: %s", strerror(errno));
        if (write_in_full(fd, blob, size) != size)
                die("unable to write temp-file");
        close(fd);