]> git.ipfire.org Git - thirdparty/git.git/blobdiff - userdiff.c
t5310: factor out bitmap traversal comparison
[thirdparty/git.git] / userdiff.c
index a69241b25ddaff5b61380aa8b451a6fcb833502c..efbe05e5a5b6f1aa9a6b92365a4f987f6078dc04 100644 (file)
@@ -23,6 +23,28 @@ IPATTERN("ada",
         "[a-zA-Z][a-zA-Z0-9_]*"
         "|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"
         "|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
+PATTERNS("dts",
+        "!;\n"
+        "!=\n"
+        /* lines beginning with a word optionally preceded by '&' or the root */
+        "^[ \t]*((/[ \t]*\\{|&?[a-zA-Z_]).*)",
+        /* -- */
+        /* Property names and math operators */
+        "[a-zA-Z0-9,._+?#-]+"
+        "|[-+*/%&^|!~]|>>|<<|&&|\\|\\|"),
+PATTERNS("elixir",
+        "^[ \t]*((def(macro|module|impl|protocol|p)?|test)[ \t].*)$",
+        /* -- */
+        /* Atoms, names, and module attributes */
+        "[@:]?[a-zA-Z0-9@_?!]+"
+        /* Numbers with specific base */
+        "|[-+]?0[xob][0-9a-fA-F]+"
+        /* Numbers */
+        "|[-+]?[0-9][0-9_.]*([eE][-+]?[0-9_]+)?"
+        /* Operators and atoms that represent them */
+        "|:?(\\+\\+|--|\\.\\.|~~~|<>|\\^\\^\\^|<?\\|>|<<<?|>?>>|<<?~|~>?>|<~>|<=|>=|===?|!==?|=~|&&&?|\\|\\|\\|?|=>|<-|\\\\\\\\|->)"
+        /* Not real operators, but should be grouped */
+        "|:?%[A-Za-z0-9_.]\\{\\}?"),
 IPATTERN("fortran",
         "!^([C*]|[ \t]*!)\n"
         "!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n"
@@ -58,7 +80,12 @@ PATTERNS("java",
         "|[-+*/<>%&^|=!]="
         "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
 PATTERNS("matlab",
-        "^[[:space:]]*((classdef|function)[[:space:]].*)$|^%%[[:space:]].*$",
+        /*
+         * Octave pattern is mostly the same as matlab, except that '%%%' and
+         * '##' can also be used to begin code sections, in addition to '%%'
+         * that is understood by both.
+         */
+        "^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
         "[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
 PATTERNS("objc",
         /* Negate C statements that can look like functions */
@@ -114,12 +141,12 @@ PATTERNS("perl",
         "|<<|<>|<=>|>>"),
 PATTERNS("php",
         "^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n"
-        "^[\t ]*(class.*)$",
+        "^[\t ]*((((final|abstract)[\t ]+)?class|interface|trait).*)$",
         /* -- */
         "[a-zA-Z_][a-zA-Z0-9_]*"
         "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
         "|[-+*/<>%&^|=!.]=|--|\\+\\+|<<=?|>>=?|===|&&|\\|\\||::|->"),
-PATTERNS("python", "^[ \t]*((class|def)[ \t].*)$",
+PATTERNS("python", "^[ \t]*((class|(async[ \t]+)?def)[ \t].*)$",
         /* -- */
         "[a-zA-Z_][a-zA-Z0-9_]*"
         "|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
@@ -130,6 +157,12 @@ PATTERNS("ruby", "^[ \t]*((class|module|def)[ \t].*)$",
         "(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*"
         "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?."
         "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"),
+PATTERNS("rust",
+        "^[\t ]*((pub(\\([^\\)]+\\))?[\t ]+)?((async|const|unsafe|extern([\t ]+\"[^\"]+\"))[\t ]+)?(struct|enum|union|mod|trait|fn|impl)[< \t]+[^;]*)$",
+        /* -- */
+        "[a-zA-Z_][a-zA-Z0-9_]*"
+        "|[0-9][0-9_a-fA-Fiosuxz]*(\\.([0-9]*[eE][+-]?)?[0-9_fF]*)?"
+        "|[-+*\\/<>%&^|=!:]=|<<=?|>>=?|&&|\\|\\||->|=>|\\.{2}=|\\.{3}|::"),
 PATTERNS("bibtex", "(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$",
         "[={}\"]|[^={}\" \t]+"),
 PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
@@ -265,12 +298,14 @@ int userdiff_config(const char *k, const char *v)
        return 0;
 }
 
-struct userdiff_driver *userdiff_find_by_name(const char *name) {
+struct userdiff_driver *userdiff_find_by_name(const char *name)
+{
        int len = strlen(name);
        return userdiff_find_by_namelen(name, len);
 }
 
-struct userdiff_driver *userdiff_find_by_path(const char *path)
+struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,
+                                             const char *path)
 {
        static struct attr_check *check;
 
@@ -278,8 +313,7 @@ struct userdiff_driver *userdiff_find_by_path(const char *path)
                check = attr_check_initl("diff", NULL);
        if (!path)
                return NULL;
-       if (git_check_attr(path, check))
-               return NULL;
+       git_check_attr(istate, path, check);
 
        if (ATTR_TRUE(check->items[0].value))
                return &driver_true;
@@ -290,7 +324,8 @@ struct userdiff_driver *userdiff_find_by_path(const char *path)
        return userdiff_find_by_name(check->items[0].value);
 }
 
-struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)
+struct userdiff_driver *userdiff_get_textconv(struct repository *r,
+                                             struct userdiff_driver *driver)
 {
        if (!driver->textconv)
                return NULL;
@@ -300,7 +335,7 @@ struct userdiff_driver *userdiff_get_textconv(struct userdiff_driver *driver)
                struct strbuf name = STRBUF_INIT;
 
                strbuf_addf(&name, "textconv/%s", driver->name);
-               notes_cache_init(c, name.buf, driver->textconv);
+               notes_cache_init(r, c, name.buf, driver->textconv);
                driver->textconv_cache = c;
                strbuf_release(&name);
        }