2010-04-02 02:12:15 +02:00
|
|
|
#include "cache.h"
|
2017-06-14 20:07:36 +02:00
|
|
|
#include "config.h"
|
2008-10-05 23:43:21 +02:00
|
|
|
#include "userdiff.h"
|
|
|
|
#include "attr.h"
|
|
|
|
|
|
|
|
static struct userdiff_driver *drivers;
|
|
|
|
static int ndrivers;
|
|
|
|
static int drivers_alloc;
|
|
|
|
|
2022-02-24 10:33:03 +01:00
|
|
|
#define PATTERNS(lang, rx, wrx) { \
|
|
|
|
.name = lang, \
|
|
|
|
.binary = -1, \
|
|
|
|
.funcname = { \
|
|
|
|
.pattern = rx, \
|
|
|
|
.cflags = REG_EXTENDED, \
|
|
|
|
}, \
|
|
|
|
.word_regex = wrx "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+", \
|
|
|
|
}
|
|
|
|
#define IPATTERN(lang, rx, wrx) { \
|
|
|
|
.name = lang, \
|
|
|
|
.binary = -1, \
|
|
|
|
.funcname = { \
|
|
|
|
.pattern = rx, \
|
|
|
|
.cflags = REG_EXTENDED | REG_ICASE, \
|
|
|
|
}, \
|
|
|
|
.word_regex = wrx "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+", \
|
|
|
|
}
|
2021-08-11 00:12:01 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Built-in drivers for various languages, sorted by their names
|
|
|
|
* (except that the "default" is left at the end).
|
|
|
|
*
|
|
|
|
* When writing or updating patterns, assume that the contents these
|
|
|
|
* patterns are applied to are syntactically correct. The patterns
|
|
|
|
* can be simple without implementing all syntactical corner cases, as
|
|
|
|
* long as they are sufficiently permissive.
|
|
|
|
*/
|
2008-10-05 23:43:21 +02:00
|
|
|
static struct userdiff_driver builtin_drivers[] = {
|
2012-09-16 05:54:15 +02:00
|
|
|
IPATTERN("ada",
|
2014-02-03 12:33:16 +01:00
|
|
|
"!^(.*[ \t])?(is[ \t]+new|renames|is[ \t]+separate)([ \t].*)?$\n"
|
2012-09-16 05:54:15 +02:00
|
|
|
"!^[ \t]*with[ \t].*$\n"
|
|
|
|
"^[ \t]*((procedure|function)[ \t]+.*)$\n"
|
|
|
|
"^[ \t]*((package|protected|task)[ \t]+.*)$",
|
|
|
|
/* -- */
|
|
|
|
"[a-zA-Z][a-zA-Z0-9_]*"
|
2014-02-03 12:33:16 +01:00
|
|
|
"|[-+]?[0-9][0-9#_.aAbBcCdDeEfF]*([eE][+-]?[0-9_]+)?"
|
2012-09-16 05:54:15 +02:00
|
|
|
"|=>|\\.\\.|\\*\\*|:=|/=|>=|<=|<<|>>|<>"),
|
2020-10-22 01:45:08 +02:00
|
|
|
PATTERNS("bash",
|
|
|
|
/* Optional leading indentation */
|
|
|
|
"^[ \t]*"
|
|
|
|
/* Start of captured text */
|
|
|
|
"("
|
|
|
|
"("
|
|
|
|
/* POSIX identifier with mandatory parentheses */
|
|
|
|
"[a-zA-Z_][a-zA-Z0-9_]*[ \t]*\\([ \t]*\\))"
|
|
|
|
"|"
|
|
|
|
/* Bashism identifier with optional parentheses */
|
|
|
|
"(function[ \t]+[a-zA-Z_][a-zA-Z0-9_]*(([ \t]*\\([ \t]*\\))|([ \t]+))"
|
|
|
|
")"
|
|
|
|
/* Optional whitespace */
|
|
|
|
"[ \t]*"
|
|
|
|
/* Compound command starting with `{`, `(`, `((` or `[[` */
|
|
|
|
"(\\{|\\(\\(?|\\[\\[)"
|
|
|
|
/* End of captured text */
|
|
|
|
")",
|
|
|
|
/* -- */
|
|
|
|
/* Characters not in the default $IFS value */
|
|
|
|
"[^ \t]+"),
|
2021-04-08 17:04:17 +02:00
|
|
|
PATTERNS("bibtex",
|
|
|
|
"(@[a-zA-Z]{1,}[ \t]*\\{{0,1}[ \t]*[^ \t\"@',\\#}{~%]*).*$",
|
|
|
|
/* -- */
|
2021-04-08 17:04:16 +02:00
|
|
|
"[={}\"]|[^={}\" \t]+"),
|
|
|
|
PATTERNS("cpp",
|
|
|
|
/* Jump targets or access declarations */
|
|
|
|
"!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:[[:space:]]*($|/[/*])\n"
|
|
|
|
/* functions/methods, variables, and compounds at top level */
|
|
|
|
"^((::[[:space:]]*)?[A-Za-z_].*)$",
|
|
|
|
/* -- */
|
2021-10-08 21:09:55 +02:00
|
|
|
/* identifiers and keywords */
|
2021-04-08 17:04:16 +02:00
|
|
|
"[a-zA-Z_][a-zA-Z0-9_]*"
|
2021-10-08 21:09:55 +02:00
|
|
|
/* decimal and octal integers as well as floatingpoint numbers */
|
2021-10-24 11:56:43 +02:00
|
|
|
"|[0-9][0-9.]*([Ee][-+]?[0-9]+)?[fFlLuU]*"
|
2021-10-08 21:09:55 +02:00
|
|
|
/* hexadecimal and binary integers */
|
2021-10-24 11:56:43 +02:00
|
|
|
"|0[xXbB][0-9a-fA-F]+[lLuU]*"
|
2021-10-08 21:09:55 +02:00
|
|
|
/* floatingpoint numbers that begin with a decimal point */
|
2021-10-24 11:56:43 +02:00
|
|
|
"|\\.[0-9][0-9]*([Ee][-+]?[0-9]+)?[fFlL]?"
|
2021-10-10 19:03:04 +02:00
|
|
|
"|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->\\*?|\\.\\*|<=>"),
|
2021-04-08 17:04:16 +02:00
|
|
|
PATTERNS("csharp",
|
|
|
|
/* Keywords */
|
|
|
|
"!^[ \t]*(do|while|for|if|else|instanceof|new|return|switch|case|throw|catch|using)\n"
|
|
|
|
/* Methods and constructors */
|
|
|
|
"^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe|async)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[<>@._[:alnum:]]+[ \t]*\\(.*\\))[ \t]*$\n"
|
|
|
|
/* Properties */
|
|
|
|
"^[ \t]*(((static|public|internal|private|protected|new|virtual|sealed|override|unsafe)[ \t]+)*[][<>@.~_[:alnum:]]+[ \t]+[@._[:alnum:]]+)[ \t]*$\n"
|
|
|
|
/* Type definitions */
|
2021-03-02 01:58:09 +01:00
|
|
|
"^[ \t]*(((static|public|internal|private|protected|new|unsafe|sealed|abstract|partial)[ \t]+)*(class|enum|interface|struct|record)[ \t]+.*)$\n"
|
2021-04-08 17:04:16 +02:00
|
|
|
/* Namespace */
|
|
|
|
"^[ \t]*(namespace[ \t]+.*)$",
|
|
|
|
/* -- */
|
|
|
|
"[a-zA-Z_][a-zA-Z0-9_]*"
|
|
|
|
"|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
|
|
|
|
"|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
|
|
|
|
IPATTERN("css",
|
|
|
|
"![:;][[:space:]]*$\n"
|
|
|
|
"^[:[@.#]?[_a-z0-9].*$",
|
|
|
|
/* -- */
|
|
|
|
/*
|
|
|
|
* This regex comes from W3C CSS specs. Should theoretically also
|
|
|
|
* allow ISO 10646 characters U+00A0 and higher,
|
|
|
|
* but they are not handled in this regex.
|
|
|
|
*/
|
|
|
|
"-?[_a-zA-Z][-_a-zA-Z0-9]*" /* identifiers */
|
|
|
|
"|-?[0-9]+|\\#[0-9a-fA-F]+" /* numbers */
|
|
|
|
),
|
2019-08-19 23:22:43 +02:00
|
|
|
PATTERNS("dts",
|
|
|
|
"!;\n"
|
2019-10-20 20:52:30 +02:00
|
|
|
"!=\n"
|
2019-08-19 23:22:43 +02:00
|
|
|
/* lines beginning with a word optionally preceded by '&' or the root */
|
2019-10-20 20:52:30 +02:00
|
|
|
"^[ \t]*((/[ \t]*\\{|&?[a-zA-Z_]).*)",
|
2019-08-19 23:22:43 +02:00
|
|
|
/* -- */
|
|
|
|
/* Property names and math operators */
|
|
|
|
"[a-zA-Z0-9,._+?#-]+"
|
|
|
|
"|[-+*/%&^|!~]|>>|<<|&&|\\|\\|"),
|
2019-11-08 22:38:24 +01:00
|
|
|
PATTERNS("elixir",
|
|
|
|
"^[ \t]*((def(macro|module|impl|protocol|p)?|test)[ \t].*)$",
|
2019-12-13 18:55:35 +01:00
|
|
|
/* -- */
|
2019-11-08 22:38:24 +01:00
|
|
|
/* Atoms, names, and module attributes */
|
2019-12-13 18:55:35 +01:00
|
|
|
"[@:]?[a-zA-Z0-9@_?!]+"
|
2019-11-08 22:38:24 +01:00
|
|
|
/* 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_.]\\{\\}?"),
|
2010-09-10 18:18:14 +02:00
|
|
|
IPATTERN("fortran",
|
2020-08-13 00:30:28 +02:00
|
|
|
/* Don't match comment lines */
|
2010-09-10 18:18:14 +02:00
|
|
|
"!^([C*]|[ \t]*!)\n"
|
2020-08-13 00:30:28 +02:00
|
|
|
/* Don't match 'module procedure' lines */
|
2010-09-10 18:18:14 +02:00
|
|
|
"!^[ \t]*MODULE[ \t]+PROCEDURE[ \t]\n"
|
2020-08-13 00:30:28 +02:00
|
|
|
/* Program, module, block data */
|
2010-09-10 18:18:14 +02:00
|
|
|
"^[ \t]*((END[ \t]+)?(PROGRAM|MODULE|BLOCK[ \t]+DATA"
|
2020-08-13 00:30:28 +02:00
|
|
|
/* Subroutines and functions */
|
2020-08-13 00:30:29 +02:00
|
|
|
"|([^!'\" \t]+[ \t]+)*(SUBROUTINE|FUNCTION))[ \t]+[A-Z].*)$",
|
2010-09-10 18:18:14 +02:00
|
|
|
/* -- */
|
|
|
|
"[a-zA-Z][a-zA-Z0-9_]*"
|
|
|
|
"|\\.([Ee][Qq]|[Nn][Ee]|[Gg][TtEe]|[Ll][TtEe]|[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]|[Aa][Nn][Dd]|[Oo][Rr]|[Nn]?[Ee][Qq][Vv]|[Nn][Oo][Tt])\\."
|
|
|
|
/* numbers and format statements like 2E14.4, or ES12.6, 9X.
|
|
|
|
* Don't worry about format statements without leading digits since
|
|
|
|
* they would have been matched above as a variable anyway. */
|
|
|
|
"|[-+]?[0-9.]+([AaIiDdEeFfLlTtXx][Ss]?[-+]?[0-9.]*)?(_[a-zA-Z0-9][a-zA-Z0-9_]*)?"
|
2011-01-11 22:48:50 +01:00
|
|
|
"|//|\\*\\*|::|[/<>=]="),
|
2021-04-08 17:04:17 +02:00
|
|
|
IPATTERN("fountain",
|
|
|
|
"^((\\.[^.]|(int|ext|est|int\\.?/ext|i/e)[. ]).*)$",
|
|
|
|
/* -- */
|
2015-07-21 15:22:46 +02:00
|
|
|
"[^ \t-]+"),
|
2018-03-01 12:19:07 +01:00
|
|
|
PATTERNS("golang",
|
|
|
|
/* Functions */
|
|
|
|
"^[ \t]*(func[ \t]*.*(\\{[ \t]*)?)\n"
|
|
|
|
/* Structs and interfaces */
|
|
|
|
"^[ \t]*(type[ \t].*(struct|interface)[ \t]*(\\{[ \t]*)?)",
|
|
|
|
/* -- */
|
|
|
|
"[a-zA-Z_][a-zA-Z0-9_]*"
|
|
|
|
"|[-+0-9.eE]+i?|0[xX]?[0-9a-fA-F]+i?"
|
|
|
|
"|[-+*/<>%&^|=!:]=|--|\\+\\+|<<=?|>>=?|&\\^=?|&&|\\|\\||<-|\\.{3}"),
|
2021-04-08 17:04:17 +02:00
|
|
|
PATTERNS("html",
|
|
|
|
"^[ \t]*(<[Hh][1-6]([ \t].*)?>.*)$",
|
|
|
|
/* -- */
|
2011-01-11 22:48:50 +01:00
|
|
|
"[^<>= \t]+"),
|
2009-01-17 17:29:48 +01:00
|
|
|
PATTERNS("java",
|
2008-10-05 23:43:21 +02:00
|
|
|
"!^[ \t]*(catch|do|for|if|instanceof|new|return|switch|throw|while)\n"
|
2023-02-08 00:42:58 +01:00
|
|
|
/* Class, enum, interface, and record declarations */
|
2023-02-08 00:42:59 +01:00
|
|
|
"^[ \t]*(([a-z-]+[ \t]+)*(class|enum|interface|record)[ \t]+.*)$\n"
|
2021-08-11 19:51:04 +02:00
|
|
|
/* Method definitions; note that constructor signatures are not */
|
|
|
|
/* matched because they are indistinguishable from method calls. */
|
|
|
|
"^[ \t]*(([A-Za-z_<>&][][?&<>.,A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$",
|
2009-06-17 16:26:06 +02:00
|
|
|
/* -- */
|
2009-01-17 17:29:48 +01:00
|
|
|
"[a-zA-Z_][a-zA-Z0-9_]*"
|
|
|
|
"|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
|
|
|
|
"|[-+*/<>%&^|=!]="
|
2011-01-11 22:48:50 +01:00
|
|
|
"|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
|
2022-03-12 05:48:32 +01:00
|
|
|
PATTERNS("kotlin",
|
|
|
|
"^[ \t]*(([a-z]+[ \t]+)*(fun|class|interface)[ \t]+.*)$",
|
|
|
|
/* -- */
|
|
|
|
"[a-zA-Z_][a-zA-Z0-9_]*"
|
|
|
|
/* hexadecimal and binary numbers */
|
|
|
|
"|0[xXbB][0-9a-fA-F_]+[lLuU]*"
|
|
|
|
/* integers and floats */
|
|
|
|
"|[0-9][0-9_]*([.][0-9_]*)?([Ee][-+]?[0-9]+)?[fFlLuU]*"
|
|
|
|
/* floating point numbers beginning with decimal point */
|
|
|
|
"|[.][0-9][0-9_]*([Ee][-+]?[0-9]+)?[fFlLuU]?"
|
|
|
|
/* unary and binary operators */
|
|
|
|
"|[-+*/<>%&^|=!]==?|--|\\+\\+|<<=|>>=|&&|\\|\\||->|\\.\\*|!!|[?:.][.:]"),
|
2020-05-02 15:15:43 +02:00
|
|
|
PATTERNS("markdown",
|
|
|
|
"^ {0,3}#{1,6}[ \t].*",
|
2021-04-08 17:04:17 +02:00
|
|
|
/* -- */
|
2020-05-02 15:15:43 +02:00
|
|
|
"[^<>= \t]+"),
|
2011-11-15 21:15:03 +01:00
|
|
|
PATTERNS("matlab",
|
2019-05-29 18:15:39 +02:00
|
|
|
/*
|
|
|
|
* Octave pattern is mostly the same as matlab, except that '%%%' and
|
2019-05-18 05:46:23 +02:00
|
|
|
* '##' can also be used to begin code sections, in addition to '%%'
|
2019-05-29 18:15:39 +02:00
|
|
|
* that is understood by both.
|
|
|
|
*/
|
2019-05-18 05:46:23 +02:00
|
|
|
"^[[:space:]]*((classdef|function)[[:space:]].*)$|^(%%%?|##)[[:space:]].*$",
|
2021-04-08 17:04:17 +02:00
|
|
|
/* -- */
|
2011-11-15 21:15:03 +01:00
|
|
|
"[a-zA-Z_][a-zA-Z0-9_]*|[-+0-9.e]+|[=~<>]=|\\.[*/\\^']|\\|\\||&&"),
|
2009-01-17 17:29:48 +01:00
|
|
|
PATTERNS("objc",
|
2008-10-05 23:43:21 +02:00
|
|
|
/* Negate C statements that can look like functions */
|
|
|
|
"!^[ \t]*(do|for|if|else|return|switch|while)\n"
|
|
|
|
/* Objective-C methods */
|
|
|
|
"^[ \t]*([-+][ \t]*\\([ \t]*[A-Za-z_][A-Za-z_0-9* \t]*\\)[ \t]*[A-Za-z_].*)$\n"
|
|
|
|
/* C functions */
|
2009-06-17 16:26:06 +02:00
|
|
|
"^[ \t]*(([A-Za-z_][A-Za-z_0-9]*[ \t]+)+[A-Za-z_][A-Za-z_0-9]*[ \t]*\\([^;]*)$\n"
|
2008-10-05 23:43:21 +02:00
|
|
|
/* Objective-C class/protocol definitions */
|
2009-01-17 17:29:48 +01:00
|
|
|
"^(@(implementation|interface|protocol)[ \t].*)$",
|
|
|
|
/* -- */
|
|
|
|
"[a-zA-Z_][a-zA-Z0-9_]*"
|
|
|
|
"|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
|
2011-01-11 22:48:50 +01:00
|
|
|
"|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
|
2009-01-17 17:29:48 +01:00
|
|
|
PATTERNS("pascal",
|
2021-04-08 17:04:18 +02:00
|
|
|
"^(((class[ \t]+)?(procedure|function)|constructor|destructor|interface"
|
|
|
|
"|implementation|initialization|finalization)[ \t]*.*)$\n"
|
2009-01-17 17:29:48 +01:00
|
|
|
"^(.*=[ \t]*(class|record).*)$",
|
|
|
|
/* -- */
|
|
|
|
"[a-zA-Z_][a-zA-Z0-9_]*"
|
|
|
|
"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
|
2011-01-11 22:48:50 +01:00
|
|
|
"|<>|<=|>=|:=|\\.\\."),
|
2010-12-26 10:07:31 +01:00
|
|
|
PATTERNS("perl",
|
2011-05-21 21:38:26 +02:00
|
|
|
"^package .*\n"
|
|
|
|
"^sub [[:alnum:]_':]+[ \t]*"
|
|
|
|
"(\\([^)]*\\)[ \t]*)?" /* prototype */
|
|
|
|
/*
|
|
|
|
* Attributes. A regex can't count nested parentheses,
|
|
|
|
* so just slurp up whatever we see, taking care not
|
|
|
|
* to accept lines like "sub foo; # defined elsewhere".
|
|
|
|
*
|
|
|
|
* An attribute could contain a semicolon, but at that
|
|
|
|
* point it seems reasonable enough to give up.
|
|
|
|
*/
|
|
|
|
"(:[^;#]*)?"
|
|
|
|
"(\\{[ \t]*)?" /* brace can come here or on the next line */
|
|
|
|
"(#.*)?$\n" /* comment */
|
2011-05-22 19:29:32 +02:00
|
|
|
"^(BEGIN|END|INIT|CHECK|UNITCHECK|AUTOLOAD|DESTROY)[ \t]*"
|
2011-05-21 21:38:26 +02:00
|
|
|
"(\\{[ \t]*)?" /* brace can come here or on the next line */
|
|
|
|
"(#.*)?$\n"
|
2011-05-21 21:35:51 +02:00
|
|
|
"^=head[0-9] .*", /* POD */
|
2010-12-26 10:07:31 +01:00
|
|
|
/* -- */
|
|
|
|
"[[:alpha:]_'][[:alnum:]_']*"
|
|
|
|
"|0[xb]?[0-9a-fA-F_]*"
|
|
|
|
/* taking care not to interpret 3..5 as (3.)(.5) */
|
|
|
|
"|[0-9a-fA-F_]+(\\.[0-9a-fA-F_]+)?([eE][-+]?[0-9_]+)?"
|
|
|
|
"|=>|-[rwxoRWXOezsfdlpSugkbctTBMAC>]|~~|::"
|
|
|
|
"|&&=|\\|\\|=|//=|\\*\\*="
|
|
|
|
"|&&|\\|\\||//|\\+\\+|--|\\*\\*|\\.\\.\\.?"
|
|
|
|
"|[-+*/%.^&<>=!|]="
|
|
|
|
"|=~|!~"
|
2011-01-11 22:48:50 +01:00
|
|
|
"|<<|<>|<=>|>>"),
|
2010-05-23 20:05:40 +02:00
|
|
|
PATTERNS("php",
|
2020-10-07 05:38:18 +02:00
|
|
|
"^[\t ]*(((public|protected|private|static|abstract|final)[\t ]+)*function.*)$\n"
|
2021-08-31 08:01:25 +02:00
|
|
|
"^[\t ]*((((final|abstract)[\t ]+)?class|enum|interface|trait).*)$",
|
2009-01-17 17:29:48 +01:00
|
|
|
/* -- */
|
|
|
|
"[a-zA-Z_][a-zA-Z0-9_]*"
|
|
|
|
"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
|
2011-01-11 22:48:50 +01:00
|
|
|
"|[-+*/<>%&^|=!.]=|--|\\+\\+|<<=?|>>=?|===|&&|\\|\\||::|->"),
|
2021-04-08 17:04:17 +02:00
|
|
|
PATTERNS("python",
|
|
|
|
"^[ \t]*((class|(async[ \t]+)?def)[ \t].*)$",
|
2009-01-17 17:29:48 +01:00
|
|
|
/* -- */
|
|
|
|
"[a-zA-Z_][a-zA-Z0-9_]*"
|
|
|
|
"|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
|
2011-01-11 22:48:50 +01:00
|
|
|
"|[-+*/<>%&^|=!]=|//=?|<<=?|>>=?|\\*\\*=?"),
|
2009-01-17 17:29:48 +01:00
|
|
|
/* -- */
|
2021-04-08 17:04:17 +02:00
|
|
|
PATTERNS("ruby",
|
|
|
|
"^[ \t]*((class|module|def)[ \t].*)$",
|
2009-01-17 17:29:48 +01:00
|
|
|
/* -- */
|
|
|
|
"(@|@@|\\$)?[a-zA-Z_][a-zA-Z0-9_]*"
|
|
|
|
"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?."
|
2011-01-11 22:48:50 +01:00
|
|
|
"|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"),
|
2019-05-17 01:58:15 +02:00
|
|
|
PATTERNS("rust",
|
2020-10-07 15:26:11 +02:00
|
|
|
"^[\t ]*((pub(\\([^\\)]+\\))?[\t ]+)?((async|const|unsafe|extern([\t ]+\"[^\"]+\"))[\t ]+)?(struct|enum|union|mod|trait|fn|impl|macro_rules!)[< \t]+[^;]*)$",
|
2019-05-17 01:58:15 +02:00
|
|
|
/* -- */
|
|
|
|
"[a-zA-Z_][a-zA-Z0-9_]*"
|
2019-05-30 18:44:35 +02:00
|
|
|
"|[0-9][0-9_a-fA-Fiosuxz]*(\\.([0-9]*[eE][+-]?)?[0-9_fF]*)?"
|
2019-05-17 01:58:15 +02:00
|
|
|
"|[-+*\\/<>%&^|=!:]=|<<=?|>>=?|&&|\\|\\||->|=>|\\.{2}=|\\.{3}|::"),
|
userdiff: add support for Scheme
Add a diff driver for Scheme-like languages which recognizes top level
and local `define` forms, whether it is a function definition, binding,
syntax definition or a user-defined `define-xyzzy` form.
Also supports R6RS `library` forms, `module` forms along with class and
struct declarations used in Racket (PLT Scheme).
Alternate "def" syntax such as those in Gerbil Scheme are also
supported, like defstruct, defsyntax and so on.
The rationale for picking `define` forms for the hunk headers is because
it is usually the only significant form for defining the structure of
the program, and it is a common pattern for schemers to have local
function definitions to hide their visibility, so it is not only the top
level `define`'s that are of interest. Schemers also extend the language
with macros to provide their own define forms (for example, something
like a `define-test-suite`) which is also captured in the hunk header.
Since it is common practice to extend syntax with variants of a form
like `module+`, `class*` etc, those have been supported as well.
The word regex is a best-effort attempt to conform to R7RS[1] valid
identifiers, symbols and numbers.
[1] https://small.r7rs.org/attachment/r7rs.pdf (section 2.1)
Signed-off-by: Atharva Raykar <raykar.ath@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-04-08 11:14:43 +02:00
|
|
|
PATTERNS("scheme",
|
|
|
|
"^[\t ]*(\\(((define|def(struct|syntax|class|method|rules|record|proto|alias)?)[-*/ \t]|(library|module|struct|class)[*+ \t]).*)$",
|
|
|
|
/*
|
|
|
|
* R7RS valid identifiers include any sequence enclosed
|
|
|
|
* within vertical lines having no backslashes
|
|
|
|
*/
|
|
|
|
"\\|([^\\\\]*)\\|"
|
|
|
|
/* All other words should be delimited by spaces or parentheses */
|
|
|
|
"|([^][)(}{[ \t])+"),
|
2009-01-17 17:29:48 +01:00
|
|
|
PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
|
2011-01-11 22:48:50 +01:00
|
|
|
"\\\\[a-zA-Z@]+|\\\\.|[a-zA-Z0-9\x80-\xff]+"),
|
2023-02-20 22:04:42 +01:00
|
|
|
{ "default", NULL, NULL, -1, { NULL, 0 } },
|
2008-10-05 23:43:21 +02:00
|
|
|
};
|
2009-01-17 17:29:48 +01:00
|
|
|
#undef PATTERNS
|
2010-09-10 18:18:14 +02:00
|
|
|
#undef IPATTERN
|
2008-10-05 23:43:21 +02:00
|
|
|
|
|
|
|
static struct userdiff_driver driver_true = {
|
2022-02-24 10:33:03 +01:00
|
|
|
.name = "diff=true",
|
|
|
|
.binary = 0,
|
2008-10-05 23:43:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct userdiff_driver driver_false = {
|
2022-02-24 10:33:03 +01:00
|
|
|
.name = "!diff",
|
|
|
|
.binary = 1,
|
2008-10-05 23:43:21 +02:00
|
|
|
};
|
|
|
|
|
2021-04-08 17:04:19 +02:00
|
|
|
struct find_by_namelen_data {
|
|
|
|
const char *name;
|
|
|
|
size_t len;
|
|
|
|
struct userdiff_driver *driver;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int userdiff_find_by_namelen_cb(struct userdiff_driver *driver,
|
2022-12-13 12:16:57 +01:00
|
|
|
enum userdiff_driver_type type UNUSED,
|
|
|
|
void *priv)
|
2008-10-05 23:43:21 +02:00
|
|
|
{
|
2021-04-08 17:04:19 +02:00
|
|
|
struct find_by_namelen_data *cb_data = priv;
|
|
|
|
|
|
|
|
if (!strncmp(driver->name, cb_data->name, cb_data->len) &&
|
|
|
|
!driver->name[cb_data->len]) {
|
|
|
|
cb_data->driver = driver;
|
|
|
|
return 1; /* tell the caller to stop iterating */
|
2008-10-05 23:43:21 +02:00
|
|
|
}
|
2021-04-08 17:04:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct userdiff_driver *userdiff_find_by_namelen(const char *name, size_t len)
|
|
|
|
{
|
|
|
|
struct find_by_namelen_data udcbdata = {
|
|
|
|
.name = name,
|
|
|
|
.len = len,
|
|
|
|
};
|
|
|
|
for_each_userdiff_driver(userdiff_find_by_namelen_cb, &udcbdata);
|
|
|
|
return udcbdata.driver;
|
2008-10-05 23:43:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_funcname(struct userdiff_funcname *f, const char *k,
|
|
|
|
const char *v, int cflags)
|
|
|
|
{
|
|
|
|
if (git_config_string(&f->pattern, k, v) < 0)
|
|
|
|
return -1;
|
|
|
|
f->cflags = cflags;
|
drop odd return value semantics from userdiff_config
When the userdiff_config function was introduced in be58e70
(diff: unify external diff and funcname parsing code,
2008-10-05), it used a return value convention unlike any
other config callback. Like other callbacks, it used "-1" to
signal error. But it returned "1" to indicate that it found
something, and "0" otherwise; other callbacks simply
returned "0" to indicate that no error occurred.
This distinction was necessary at the time, because the
userdiff namespace overlapped slightly with the color
configuration namespace. So "diff.color.foo" could mean "the
'foo' slot of diff coloring" or "the 'foo' component of the
"color" userdiff driver". Because the color-parsing code
would die on an unknown color slot, we needed the userdiff
code to indicate that it had matched the variable, letting
us bypass the color-parsing code entirely.
Later, in 8b8e862 (ignore unknown color configuration,
2009-12-12), the color-parsing code learned to silently
ignore unknown slots. This means we no longer need to
protect userdiff-matched variables from reaching the
color-parsing code.
We can therefore change the userdiff_config calling
convention to a more normal one. This drops some code from
each caller, which is nice. But more importantly, it reduces
the cognitive load for readers who may wonder why
userdiff_config is unlike every other config callback.
There's no need to add a new test confirming that this
works; t4020 already contains a test that sets
diff.color.external.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-07 19:23:02 +01:00
|
|
|
return 0;
|
2008-10-05 23:43:21 +02:00
|
|
|
}
|
|
|
|
|
diff: introduce diff.<driver>.binary
The "diff" gitattribute is somewhat overloaded right now. It
can say one of three things:
1. this file is definitely binary, or definitely not
(i.e., diff or !diff)
2. this file should use an external diff engine (i.e.,
diff=foo, diff.foo.command = custom-script)
3. this file should use particular funcname patterns
(i.e., diff=foo, diff.foo.(x?)funcname = some-regex)
Most of the time, there is no conflict between these uses,
since using one implies that the other is irrelevant (e.g.,
an external diff engine will decide for itself whether the
file is binary).
However, there is at least one conflicting situation: there
is no way to say "use the regular rules to determine whether
this file is binary, but if we do diff it textually, use
this funcname pattern." That is, currently setting diff=foo
indicates that the file is definitely text.
This patch introduces a "binary" config option for a diff
driver, so that one can explicitly set diff.foo.binary. We
default this value to "don't know". That is, setting a diff
attribute to "foo" and using "diff.foo.funcname" will have
no effect on the binaryness of a file. To get the current
behavior, one can set diff.foo.binary to true.
This patch also has one additional advantage: it cleans up
the interface to the userdiff code a bit. Before, calling
code had to know more about whether attributes were false,
true, or unset to determine binaryness. Now that binaryness
is a property of a driver, we can represent these situations
just by passing back a driver struct.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-10-05 23:43:36 +02:00
|
|
|
static int parse_tristate(int *b, const char *k, const char *v)
|
|
|
|
{
|
|
|
|
if (v && !strcasecmp(v, "auto"))
|
|
|
|
*b = -1;
|
|
|
|
else
|
|
|
|
*b = git_config_bool(k, v);
|
drop odd return value semantics from userdiff_config
When the userdiff_config function was introduced in be58e70
(diff: unify external diff and funcname parsing code,
2008-10-05), it used a return value convention unlike any
other config callback. Like other callbacks, it used "-1" to
signal error. But it returned "1" to indicate that it found
something, and "0" otherwise; other callbacks simply
returned "0" to indicate that no error occurred.
This distinction was necessary at the time, because the
userdiff namespace overlapped slightly with the color
configuration namespace. So "diff.color.foo" could mean "the
'foo' slot of diff coloring" or "the 'foo' component of the
"color" userdiff driver". Because the color-parsing code
would die on an unknown color slot, we needed the userdiff
code to indicate that it had matched the variable, letting
us bypass the color-parsing code entirely.
Later, in 8b8e862 (ignore unknown color configuration,
2009-12-12), the color-parsing code learned to silently
ignore unknown slots. This means we no longer need to
protect userdiff-matched variables from reaching the
color-parsing code.
We can therefore change the userdiff_config calling
convention to a more normal one. This drops some code from
each caller, which is nice. But more importantly, it reduces
the cognitive load for readers who may wonder why
userdiff_config is unlike every other config callback.
There's no need to add a new test confirming that this
works; t4020 already contains a test that sets
diff.color.external.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-07 19:23:02 +01:00
|
|
|
return 0;
|
diff: introduce diff.<driver>.binary
The "diff" gitattribute is somewhat overloaded right now. It
can say one of three things:
1. this file is definitely binary, or definitely not
(i.e., diff or !diff)
2. this file should use an external diff engine (i.e.,
diff=foo, diff.foo.command = custom-script)
3. this file should use particular funcname patterns
(i.e., diff=foo, diff.foo.(x?)funcname = some-regex)
Most of the time, there is no conflict between these uses,
since using one implies that the other is irrelevant (e.g.,
an external diff engine will decide for itself whether the
file is binary).
However, there is at least one conflicting situation: there
is no way to say "use the regular rules to determine whether
this file is binary, but if we do diff it textually, use
this funcname pattern." That is, currently setting diff=foo
indicates that the file is definitely text.
This patch introduces a "binary" config option for a diff
driver, so that one can explicitly set diff.foo.binary. We
default this value to "don't know". That is, setting a diff
attribute to "foo" and using "diff.foo.funcname" will have
no effect on the binaryness of a file. To get the current
behavior, one can set diff.foo.binary to true.
This patch also has one additional advantage: it cleans up
the interface to the userdiff code a bit. Before, calling
code had to know more about whether attributes were false,
true, or unset to determine binaryness. Now that binaryness
is a property of a driver, we can represent these situations
just by passing back a driver struct.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-10-05 23:43:36 +02:00
|
|
|
}
|
|
|
|
|
2010-04-02 02:12:15 +02:00
|
|
|
static int parse_bool(int *b, const char *k, const char *v)
|
|
|
|
{
|
|
|
|
*b = git_config_bool(k, v);
|
drop odd return value semantics from userdiff_config
When the userdiff_config function was introduced in be58e70
(diff: unify external diff and funcname parsing code,
2008-10-05), it used a return value convention unlike any
other config callback. Like other callbacks, it used "-1" to
signal error. But it returned "1" to indicate that it found
something, and "0" otherwise; other callbacks simply
returned "0" to indicate that no error occurred.
This distinction was necessary at the time, because the
userdiff namespace overlapped slightly with the color
configuration namespace. So "diff.color.foo" could mean "the
'foo' slot of diff coloring" or "the 'foo' component of the
"color" userdiff driver". Because the color-parsing code
would die on an unknown color slot, we needed the userdiff
code to indicate that it had matched the variable, letting
us bypass the color-parsing code entirely.
Later, in 8b8e862 (ignore unknown color configuration,
2009-12-12), the color-parsing code learned to silently
ignore unknown slots. This means we no longer need to
protect userdiff-matched variables from reaching the
color-parsing code.
We can therefore change the userdiff_config calling
convention to a more normal one. This drops some code from
each caller, which is nice. But more importantly, it reduces
the cognitive load for readers who may wonder why
userdiff_config is unlike every other config callback.
There's no need to add a new test confirming that this
works; t4020 already contains a test that sets
diff.color.external.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-07 19:23:02 +01:00
|
|
|
return 0;
|
2010-04-02 02:12:15 +02:00
|
|
|
}
|
|
|
|
|
2008-10-26 05:45:55 +01:00
|
|
|
int userdiff_config(const char *k, const char *v)
|
2008-10-05 23:43:21 +02:00
|
|
|
{
|
|
|
|
struct userdiff_driver *drv;
|
2013-01-23 07:25:07 +01:00
|
|
|
const char *name, *type;
|
2020-04-10 21:44:28 +02:00
|
|
|
size_t namelen;
|
2013-01-23 07:25:07 +01:00
|
|
|
|
|
|
|
if (parse_config_key(k, "diff", &name, &namelen, &type) || !name)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
drv = userdiff_find_by_namelen(name, namelen);
|
|
|
|
if (!drv) {
|
|
|
|
ALLOC_GROW(drivers, ndrivers+1, drivers_alloc);
|
|
|
|
drv = &drivers[ndrivers++];
|
|
|
|
memset(drv, 0, sizeof(*drv));
|
|
|
|
drv->name = xmemdupz(name, namelen);
|
|
|
|
drv->binary = -1;
|
|
|
|
}
|
2008-10-05 23:43:21 +02:00
|
|
|
|
2013-01-23 07:25:07 +01:00
|
|
|
if (!strcmp(type, "funcname"))
|
2008-10-05 23:43:21 +02:00
|
|
|
return parse_funcname(&drv->funcname, k, v, 0);
|
2013-01-23 07:25:07 +01:00
|
|
|
if (!strcmp(type, "xfuncname"))
|
2008-10-05 23:43:21 +02:00
|
|
|
return parse_funcname(&drv->funcname, k, v, REG_EXTENDED);
|
2013-01-23 07:25:07 +01:00
|
|
|
if (!strcmp(type, "binary"))
|
diff: introduce diff.<driver>.binary
The "diff" gitattribute is somewhat overloaded right now. It
can say one of three things:
1. this file is definitely binary, or definitely not
(i.e., diff or !diff)
2. this file should use an external diff engine (i.e.,
diff=foo, diff.foo.command = custom-script)
3. this file should use particular funcname patterns
(i.e., diff=foo, diff.foo.(x?)funcname = some-regex)
Most of the time, there is no conflict between these uses,
since using one implies that the other is irrelevant (e.g.,
an external diff engine will decide for itself whether the
file is binary).
However, there is at least one conflicting situation: there
is no way to say "use the regular rules to determine whether
this file is binary, but if we do diff it textually, use
this funcname pattern." That is, currently setting diff=foo
indicates that the file is definitely text.
This patch introduces a "binary" config option for a diff
driver, so that one can explicitly set diff.foo.binary. We
default this value to "don't know". That is, setting a diff
attribute to "foo" and using "diff.foo.funcname" will have
no effect on the binaryness of a file. To get the current
behavior, one can set diff.foo.binary to true.
This patch also has one additional advantage: it cleans up
the interface to the userdiff code a bit. Before, calling
code had to know more about whether attributes were false,
true, or unset to determine binaryness. Now that binaryness
is a property of a driver, we can represent these situations
just by passing back a driver struct.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-10-05 23:43:36 +02:00
|
|
|
return parse_tristate(&drv->binary, k, v);
|
2013-01-23 07:25:07 +01:00
|
|
|
if (!strcmp(type, "command"))
|
drop odd return value semantics from userdiff_config
When the userdiff_config function was introduced in be58e70
(diff: unify external diff and funcname parsing code,
2008-10-05), it used a return value convention unlike any
other config callback. Like other callbacks, it used "-1" to
signal error. But it returned "1" to indicate that it found
something, and "0" otherwise; other callbacks simply
returned "0" to indicate that no error occurred.
This distinction was necessary at the time, because the
userdiff namespace overlapped slightly with the color
configuration namespace. So "diff.color.foo" could mean "the
'foo' slot of diff coloring" or "the 'foo' component of the
"color" userdiff driver". Because the color-parsing code
would die on an unknown color slot, we needed the userdiff
code to indicate that it had matched the variable, letting
us bypass the color-parsing code entirely.
Later, in 8b8e862 (ignore unknown color configuration,
2009-12-12), the color-parsing code learned to silently
ignore unknown slots. This means we no longer need to
protect userdiff-matched variables from reaching the
color-parsing code.
We can therefore change the userdiff_config calling
convention to a more normal one. This drops some code from
each caller, which is nice. But more importantly, it reduces
the cognitive load for readers who may wonder why
userdiff_config is unlike every other config callback.
There's no need to add a new test confirming that this
works; t4020 already contains a test that sets
diff.color.external.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-07 19:23:02 +01:00
|
|
|
return git_config_string(&drv->external, k, v);
|
2013-01-23 07:25:07 +01:00
|
|
|
if (!strcmp(type, "textconv"))
|
drop odd return value semantics from userdiff_config
When the userdiff_config function was introduced in be58e70
(diff: unify external diff and funcname parsing code,
2008-10-05), it used a return value convention unlike any
other config callback. Like other callbacks, it used "-1" to
signal error. But it returned "1" to indicate that it found
something, and "0" otherwise; other callbacks simply
returned "0" to indicate that no error occurred.
This distinction was necessary at the time, because the
userdiff namespace overlapped slightly with the color
configuration namespace. So "diff.color.foo" could mean "the
'foo' slot of diff coloring" or "the 'foo' component of the
"color" userdiff driver". Because the color-parsing code
would die on an unknown color slot, we needed the userdiff
code to indicate that it had matched the variable, letting
us bypass the color-parsing code entirely.
Later, in 8b8e862 (ignore unknown color configuration,
2009-12-12), the color-parsing code learned to silently
ignore unknown slots. This means we no longer need to
protect userdiff-matched variables from reaching the
color-parsing code.
We can therefore change the userdiff_config calling
convention to a more normal one. This drops some code from
each caller, which is nice. But more importantly, it reduces
the cognitive load for readers who may wonder why
userdiff_config is unlike every other config callback.
There's no need to add a new test confirming that this
works; t4020 already contains a test that sets
diff.color.external.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-07 19:23:02 +01:00
|
|
|
return git_config_string(&drv->textconv, k, v);
|
2013-01-23 07:25:07 +01:00
|
|
|
if (!strcmp(type, "cachetextconv"))
|
2010-04-02 02:12:15 +02:00
|
|
|
return parse_bool(&drv->textconv_want_cache, k, v);
|
2013-01-23 07:25:07 +01:00
|
|
|
if (!strcmp(type, "wordregex"))
|
drop odd return value semantics from userdiff_config
When the userdiff_config function was introduced in be58e70
(diff: unify external diff and funcname parsing code,
2008-10-05), it used a return value convention unlike any
other config callback. Like other callbacks, it used "-1" to
signal error. But it returned "1" to indicate that it found
something, and "0" otherwise; other callbacks simply
returned "0" to indicate that no error occurred.
This distinction was necessary at the time, because the
userdiff namespace overlapped slightly with the color
configuration namespace. So "diff.color.foo" could mean "the
'foo' slot of diff coloring" or "the 'foo' component of the
"color" userdiff driver". Because the color-parsing code
would die on an unknown color slot, we needed the userdiff
code to indicate that it had matched the variable, letting
us bypass the color-parsing code entirely.
Later, in 8b8e862 (ignore unknown color configuration,
2009-12-12), the color-parsing code learned to silently
ignore unknown slots. This means we no longer need to
protect userdiff-matched variables from reaching the
color-parsing code.
We can therefore change the userdiff_config calling
convention to a more normal one. This drops some code from
each caller, which is nice. But more importantly, it reduces
the cognitive load for readers who may wonder why
userdiff_config is unlike every other config callback.
There's no need to add a new test confirming that this
works; t4020 already contains a test that sets
diff.color.external.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-07 19:23:02 +01:00
|
|
|
return git_config_string(&drv->word_regex, k, v);
|
2023-02-20 22:04:42 +01:00
|
|
|
if (!strcmp(type, "algorithm"))
|
|
|
|
return git_config_string(&drv->algorithm, k, v);
|
2008-10-05 23:43:21 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-09 11:25:21 +01:00
|
|
|
struct userdiff_driver *userdiff_find_by_name(const char *name)
|
|
|
|
{
|
2008-10-05 23:43:21 +02:00
|
|
|
int len = strlen(name);
|
|
|
|
return userdiff_find_by_namelen(name, len);
|
|
|
|
}
|
|
|
|
|
2018-09-21 17:57:33 +02:00
|
|
|
struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,
|
|
|
|
const char *path)
|
2008-10-05 23:43:21 +02:00
|
|
|
{
|
2017-01-28 03:01:57 +01:00
|
|
|
static struct attr_check *check;
|
2008-10-05 23:43:21 +02:00
|
|
|
|
2017-01-28 03:01:57 +01:00
|
|
|
if (!check)
|
|
|
|
check = attr_check_initl("diff", NULL);
|
2008-10-05 23:43:21 +02:00
|
|
|
if (!path)
|
|
|
|
return NULL;
|
2023-01-14 09:30:38 +01:00
|
|
|
git_check_attr(istate, NULL, path, check);
|
2008-10-05 23:43:21 +02:00
|
|
|
|
2017-01-28 03:01:57 +01:00
|
|
|
if (ATTR_TRUE(check->items[0].value))
|
2008-10-05 23:43:21 +02:00
|
|
|
return &driver_true;
|
2017-01-28 03:01:57 +01:00
|
|
|
if (ATTR_FALSE(check->items[0].value))
|
2008-10-05 23:43:21 +02:00
|
|
|
return &driver_false;
|
2017-01-28 03:01:57 +01:00
|
|
|
if (ATTR_UNSET(check->items[0].value))
|
2008-10-05 23:43:21 +02:00
|
|
|
return NULL;
|
2017-01-28 03:01:57 +01:00
|
|
|
return userdiff_find_by_name(check->items[0].value);
|
2008-10-05 23:43:21 +02:00
|
|
|
}
|
2011-05-23 22:30:14 +02:00
|
|
|
|
2018-11-10 06:49:06 +01:00
|
|
|
struct userdiff_driver *userdiff_get_textconv(struct repository *r,
|
|
|
|
struct userdiff_driver *driver)
|
2011-05-23 22:30:14 +02:00
|
|
|
{
|
|
|
|
if (!driver->textconv)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (driver->textconv_want_cache && !driver->textconv_cache) {
|
|
|
|
struct notes_cache *c = xmalloc(sizeof(*c));
|
|
|
|
struct strbuf name = STRBUF_INIT;
|
|
|
|
|
|
|
|
strbuf_addf(&name, "textconv/%s", driver->name);
|
2018-11-10 06:49:06 +01:00
|
|
|
notes_cache_init(r, c, name.buf, driver->textconv);
|
2011-05-23 22:30:14 +02:00
|
|
|
driver->textconv_cache = c;
|
2017-08-30 20:20:15 +02:00
|
|
|
strbuf_release(&name);
|
2011-05-23 22:30:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return driver;
|
|
|
|
}
|
2021-04-08 17:04:19 +02:00
|
|
|
|
|
|
|
static int for_each_userdiff_driver_list(each_userdiff_driver_fn fn,
|
|
|
|
enum userdiff_driver_type type, void *cb_data,
|
|
|
|
struct userdiff_driver *drv,
|
|
|
|
int drv_size)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int ret;
|
|
|
|
for (i = 0; i < drv_size; i++) {
|
|
|
|
struct userdiff_driver *item = drv + i;
|
|
|
|
if ((ret = fn(item, type, cb_data)))
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int for_each_userdiff_driver(each_userdiff_driver_fn fn, void *cb_data)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = for_each_userdiff_driver_list(fn, USERDIFF_DRIVER_TYPE_CUSTOM,
|
|
|
|
cb_data, drivers, ndrivers);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = for_each_userdiff_driver_list(fn, USERDIFF_DRIVER_TYPE_BUILTIN,
|
|
|
|
cb_data, builtin_drivers,
|
|
|
|
ARRAY_SIZE(builtin_drivers));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|