mirror of
https://github.com/git-for-windows/git.git
synced 2026-06-13 08:57:56 -05:00
Add support for external diff processes that communicate via the
long-running process protocol (pkt-line over stdin/stdout).
A diff process is configured per userdiff driver:
[diff "cdiff"]
process = /path/to/diff-tool
The tool provides custom line-matching: it receives file pairs
and returns hunks that reference line numbers in the content.
When textconv is also configured, the tool receives the
textconv-transformed content. The tool controls which lines
are marked as changed while the display shows the file content.
Patch output features (word diff, function context, color) work
normally; summary formats like --stat use their own diff path
and are not affected.
The handshake negotiates version=1 and capability=hunks. Per-file
requests send command=hunks, pathname, and both file contents as
packetized data. The tool responds with hunk lines and a status
packet (success, error, or abort). On error, Git warns and falls
back to the builtin diff algorithm for that file. On abort, Git
silently falls back for the current file and stops sending further
requests to the tool for the remainder of the session.
When the tool returns no hunks followed by status=success, Git
treats the file as having no changes and produces no diff output.
This also means --exit-code reports no changes for that file.
The subprocess is stored on the userdiff_driver struct and
launched on first use. If the process fails to start, the
handshake fails, or a communication error occurs mid-stream,
the failure is cached on the driver to avoid retrying and
re-warning on every subsequent file.
diff_process_fill_hunks() is the sole public entry point. It
handles driver lookup, flag checks, subprocess management, and
error reporting, returning an enum that lets callers distinguish
"hunks populated" from "files equivalent" from "not applicable"
from "tool failure."
Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
67 lines
1.7 KiB
C
67 lines
1.7 KiB
C
#ifndef USERDIFF_H
|
|
#define USERDIFF_H
|
|
|
|
#include "notes-cache.h"
|
|
|
|
struct diff_subprocess;
|
|
struct index_state;
|
|
struct repository;
|
|
|
|
struct userdiff_funcname {
|
|
const char *pattern;
|
|
char *pattern_owned;
|
|
int cflags;
|
|
};
|
|
|
|
struct external_diff {
|
|
char *cmd;
|
|
unsigned trust_exit_code:1;
|
|
};
|
|
|
|
struct userdiff_driver {
|
|
const char *name;
|
|
struct external_diff external;
|
|
const char *algorithm;
|
|
char *algorithm_owned;
|
|
int binary;
|
|
struct userdiff_funcname funcname;
|
|
const char *word_regex;
|
|
char *word_regex_owned;
|
|
const char *word_regex_multi_byte;
|
|
const char *textconv;
|
|
char *textconv_owned;
|
|
struct notes_cache *textconv_cache;
|
|
int textconv_want_cache;
|
|
const char *process;
|
|
char *process_owned;
|
|
struct diff_subprocess *diff_subprocess;
|
|
unsigned diff_process_failed : 1;
|
|
};
|
|
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 */
|