mirror of
https://github.com/git/git.git
synced 2026-01-12 05:43:12 +09:00
The options --exit-code and --quiet instruct git diff to indicate whether it found any significant changes by exiting with code 1 if it did and 0 if there were none. Currently this doesn't work if external diff programs are involved, as we have no way to learn what they found. Add that ability in the form of the new configuration options diff.trustExitCode and diff.<driver>.trustExitCode and the environment variable GIT_EXTERNAL_DIFF_TRUST_EXIT_CODE. They pair with the config options diff.external and diff.<driver>.command and the environment variable GIT_EXTERNAL_DIFF, respectively. The new options are off by default, keeping the old behavior. Enabling them indicates that the external diff returns exit code 1 if it finds significant changes and 0 if it doesn't, like diff(1). The name of the new options is taken from the git difftool and mergetool options of similar purpose. (There they enable passing on the exit code of a diff tool and to infer whether a merge done by a merge tool is successful.) The new feature sets the diff flag diff_from_contents in diff_setup_done() if we need the exit code and are allowed to call external diffs. This disables the optimization that avoids calling the program with --quiet. Add it back by skipping the call if the external diff is not able to report empty diffs. We can only do that check after evaluating the file-specific attributes in run_external_diff(). If we do run the external diff with --quiet, send its output to /dev/null. I considered checking the output of the external diff to check whether its empty. It was added as 11be65cfa4 (diff: fix --exit-code with external diff, 2024-05-05) and quickly reverted, as it does not work with external diffs that do not write to stdout. There's no reason why a graphical diff tool would even need to write anything there at all. I also considered using a non-zero exit code for empty diffs, which could be done without adding new configuration options. We'd need to disable the optimization that allows git diff --quiet to skip calling external diffs, though -- that might be quite surprising if graphical diff programs are involved. And assigning the opposite meaning of the exit codes compared to diff(1) and git diff --exit-code to the external diff can cause unnecessary confusion. Suggested-by: Phillip Wood <phillip.wood123@gmail.com> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
58 lines
1.4 KiB
C
58 lines
1.4 KiB
C
#ifndef USERDIFF_H
|
|
#define USERDIFF_H
|
|
|
|
#include "notes-cache.h"
|
|
|
|
struct index_state;
|
|
struct repository;
|
|
|
|
struct userdiff_funcname {
|
|
char *pattern;
|
|
int cflags;
|
|
};
|
|
|
|
struct external_diff {
|
|
char *cmd;
|
|
unsigned trust_exit_code:1;
|
|
};
|
|
|
|
struct userdiff_driver {
|
|
const char *name;
|
|
struct external_diff external;
|
|
char *algorithm;
|
|
int binary;
|
|
struct userdiff_funcname funcname;
|
|
char *word_regex;
|
|
char *word_regex_multi_byte;
|
|
char *textconv;
|
|
struct notes_cache *textconv_cache;
|
|
int textconv_want_cache;
|
|
};
|
|
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 *);
|
|
|
|
int userdiff_config(const char *k, const char *v);
|
|
struct userdiff_driver *userdiff_find_by_name(const char *name);
|
|
struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,
|
|
const char *path);
|
|
|
|
/*
|
|
* Initialize any textconv-related fields in the driver and return it, or NULL
|
|
* if it does not have textconv enabled at all.
|
|
*/
|
|
struct userdiff_driver *userdiff_get_textconv(struct repository *r,
|
|
struct userdiff_driver *driver);
|
|
|
|
/*
|
|
* 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 *);
|
|
|
|
#endif /* USERDIFF */
|