2008-10-06 05:43:21 +08:00
|
|
|
#ifndef USERDIFF_H
|
|
|
|
#define USERDIFF_H
|
|
|
|
|
2010-04-02 08:12:15 +08:00
|
|
|
#include "notes-cache.h"
|
|
|
|
|
2018-09-21 23:57:33 +08:00
|
|
|
struct index_state;
|
2018-11-10 13:49:06 +08:00
|
|
|
struct repository;
|
2018-09-21 23:57:33 +08:00
|
|
|
|
2008-10-06 05:43:21 +08:00
|
|
|
struct userdiff_funcname {
|
global: convert intentionally-leaking config strings to consts
There are multiple cases where we intentionally leak config strings:
- `struct gpg_format` is used to track programs that can be used for
signing commits, either via gpg(1), gpgsm(1) or ssh-keygen(1). The
user can override the commands via several config variables. As the
array is populated once, only, and the struct memers are never
written to or free'd.
- `struct ll_merge_driver` is used to track merge drivers. Same as
with the GPG format, these drivers are populated once and then
reused. Its data is never written to or free'd, either.
- `struct userdiff_funcname` and `struct userdiff_driver` can be
configured via `diff.<driver>.*` to add additional drivers. Again,
these have a global lifetime and are never written to or free'd.
All of these are intentionally kept alive and are never written to.
Furthermore, all of these are being assigned both string constants in
some places, and allocated strings in other places. This will cause
warnings once we enable `-Wwrite-strings`, so let's mark the respective
fields as `const char *` and cast away the constness when assigning
those values.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-06-07 14:37:43 +08:00
|
|
|
const char *pattern;
|
2024-08-14 14:52:50 +08:00
|
|
|
char *pattern_owned;
|
2008-10-06 05:43:21 +08:00
|
|
|
int cflags;
|
|
|
|
};
|
|
|
|
|
2024-06-09 15:39:08 +08:00
|
|
|
struct external_diff {
|
|
|
|
char *cmd;
|
2024-06-09 15:41:44 +08:00
|
|
|
unsigned trust_exit_code:1;
|
2024-06-09 15:39:08 +08:00
|
|
|
};
|
|
|
|
|
2008-10-06 05:43:21 +08:00
|
|
|
struct userdiff_driver {
|
|
|
|
const char *name;
|
2024-06-09 15:39:08 +08:00
|
|
|
struct external_diff external;
|
global: convert intentionally-leaking config strings to consts
There are multiple cases where we intentionally leak config strings:
- `struct gpg_format` is used to track programs that can be used for
signing commits, either via gpg(1), gpgsm(1) or ssh-keygen(1). The
user can override the commands via several config variables. As the
array is populated once, only, and the struct memers are never
written to or free'd.
- `struct ll_merge_driver` is used to track merge drivers. Same as
with the GPG format, these drivers are populated once and then
reused. Its data is never written to or free'd, either.
- `struct userdiff_funcname` and `struct userdiff_driver` can be
configured via `diff.<driver>.*` to add additional drivers. Again,
these have a global lifetime and are never written to or free'd.
All of these are intentionally kept alive and are never written to.
Furthermore, all of these are being assigned both string constants in
some places, and allocated strings in other places. This will cause
warnings once we enable `-Wwrite-strings`, so let's mark the respective
fields as `const char *` and cast away the constness when assigning
those values.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-06-07 14:37:43 +08:00
|
|
|
const char *algorithm;
|
2024-08-14 14:52:50 +08:00
|
|
|
char *algorithm_owned;
|
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-06 05:43:36 +08:00
|
|
|
int binary;
|
2008-10-06 05:43:21 +08:00
|
|
|
struct userdiff_funcname funcname;
|
global: convert intentionally-leaking config strings to consts
There are multiple cases where we intentionally leak config strings:
- `struct gpg_format` is used to track programs that can be used for
signing commits, either via gpg(1), gpgsm(1) or ssh-keygen(1). The
user can override the commands via several config variables. As the
array is populated once, only, and the struct memers are never
written to or free'd.
- `struct ll_merge_driver` is used to track merge drivers. Same as
with the GPG format, these drivers are populated once and then
reused. Its data is never written to or free'd, either.
- `struct userdiff_funcname` and `struct userdiff_driver` can be
configured via `diff.<driver>.*` to add additional drivers. Again,
these have a global lifetime and are never written to or free'd.
All of these are intentionally kept alive and are never written to.
Furthermore, all of these are being assigned both string constants in
some places, and allocated strings in other places. This will cause
warnings once we enable `-Wwrite-strings`, so let's mark the respective
fields as `const char *` and cast away the constness when assigning
those values.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-06-07 14:37:43 +08:00
|
|
|
const char *word_regex;
|
2024-08-14 14:52:50 +08:00
|
|
|
char *word_regex_owned;
|
global: convert intentionally-leaking config strings to consts
There are multiple cases where we intentionally leak config strings:
- `struct gpg_format` is used to track programs that can be used for
signing commits, either via gpg(1), gpgsm(1) or ssh-keygen(1). The
user can override the commands via several config variables. As the
array is populated once, only, and the struct memers are never
written to or free'd.
- `struct ll_merge_driver` is used to track merge drivers. Same as
with the GPG format, these drivers are populated once and then
reused. Its data is never written to or free'd, either.
- `struct userdiff_funcname` and `struct userdiff_driver` can be
configured via `diff.<driver>.*` to add additional drivers. Again,
these have a global lifetime and are never written to or free'd.
All of these are intentionally kept alive and are never written to.
Furthermore, all of these are being assigned both string constants in
some places, and allocated strings in other places. This will cause
warnings once we enable `-Wwrite-strings`, so let's mark the respective
fields as `const char *` and cast away the constness when assigning
those values.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-06-07 14:37:43 +08:00
|
|
|
const char *word_regex_multi_byte;
|
|
|
|
const char *textconv;
|
2024-08-14 14:52:50 +08:00
|
|
|
char *textconv_owned;
|
2010-04-02 08:12:15 +08:00
|
|
|
struct notes_cache *textconv_cache;
|
|
|
|
int textconv_want_cache;
|
2008-10-06 05:43:21 +08:00
|
|
|
};
|
2021-04-08 23:04:19 +08:00
|
|
|
enum userdiff_driver_type {
|
|
|
|
USERDIFF_DRIVER_TYPE_BUILTIN = 1<<0,
|
|
|
|
USERDIFF_DRIVER_TYPE_CUSTOM = 1<<1,
|
|
|
|
};
|
|
|
|
typedef int (*each_userdiff_driver_fn)(struct userdiff_driver *,
|
|
|
|
enum userdiff_driver_type, void *);
|
2008-10-06 05:43:21 +08:00
|
|
|
|
2008-10-26 12:45:55 +08:00
|
|
|
int userdiff_config(const char *k, const char *v);
|
2008-10-06 05:43:21 +08:00
|
|
|
struct userdiff_driver *userdiff_find_by_name(const char *name);
|
2018-09-21 23:57:33 +08:00
|
|
|
struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,
|
|
|
|
const char *path);
|
2008-10-06 05:43:21 +08:00
|
|
|
|
2016-02-23 02:28:54 +08:00
|
|
|
/*
|
|
|
|
* Initialize any textconv-related fields in the driver and return it, or NULL
|
|
|
|
* if it does not have textconv enabled at all.
|
|
|
|
*/
|
2018-11-10 13:49:06 +08:00
|
|
|
struct userdiff_driver *userdiff_get_textconv(struct repository *r,
|
|
|
|
struct userdiff_driver *driver);
|
2011-05-24 04:30:14 +08:00
|
|
|
|
2021-04-08 23:04:19 +08:00
|
|
|
/*
|
|
|
|
* Iterate over all userdiff drivers. The userdiff_driver_type
|
|
|
|
* argument to each_userdiff_driver_fn indicates their type. Return
|
|
|
|
* non-zero to exit early from the loop.
|
|
|
|
*/
|
|
|
|
int for_each_userdiff_driver(each_userdiff_driver_fn, void *);
|
|
|
|
|
2008-10-06 05:43:21 +08:00
|
|
|
#endif /* USERDIFF */
|