|
| 1 | +diff --git a/git-xdiff.h b/git-xdiff.h |
| 2 | +new file mode 100644 |
| 3 | +index 0000000..d812d0d |
| 4 | +--- /dev/null |
| 5 | ++++ b/git-xdiff.h |
| 6 | +@@ -0,0 +1,63 @@ |
| 7 | ++/* |
| 8 | ++ * This file provides the necessary indirection between xdiff and |
| 9 | ++ * the calling application. Callers can use this file to avoid modifying |
| 10 | ++ * xdiff itself with application-specific code, while still using their |
| 11 | ++ * bespoke runtime. For example: callers may wish to use a specific |
| 12 | ++ * `malloc` function, and can do so by defining `xdl_malloc` in this |
| 13 | ++ * file. |
| 14 | ++ */ |
| 15 | ++ |
| 16 | ++#ifndef __GIT_XDIFF_H__ |
| 17 | ++#define __GIT_XDIFF_H__ |
| 18 | ++ |
| 19 | ++#include <ctype.h> |
| 20 | ++#include <limits.h> |
| 21 | ++#include <stdlib.h> |
| 22 | ++#include <stdint.h> |
| 23 | ++#include <stdio.h> |
| 24 | ++#include <string.h> |
| 25 | ++#include <regex.h> |
| 26 | ++ |
| 27 | ++/* Work around C90-conformance issues */ |
| 28 | ++#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) |
| 29 | ++# if defined(_MSC_VER) |
| 30 | ++# define inline __inline |
| 31 | ++# elif defined(__GNUC__) |
| 32 | ++# define inline __inline__ |
| 33 | ++# else |
| 34 | ++# define inline |
| 35 | ++# endif |
| 36 | ++#endif |
| 37 | ++ |
| 38 | ++#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \ |
| 39 | ++ ((__GNUC__ << 16) + __GNUC_MINOR__ >= (4 << 16) + 5) |
| 40 | ++# define XDL_UNUSED __attribute__((unused)) \ |
| 41 | ++ __attribute__((deprecated ("parameter declared as UNUSED"))) |
| 42 | ++#elif defined(__GNUC__) |
| 43 | ++# define XDL_UNUSED __attribute__((unused)) \ |
| 44 | ++ __attribute__((deprecated)) |
| 45 | ++#else |
| 46 | ++# define XDL_UNUSED |
| 47 | ++#endif |
| 48 | ++ |
| 49 | ++#define xdl_malloc(x) malloc(x) |
| 50 | ++#define xdl_calloc(n, sz) calloc(n, sz) |
| 51 | ++#define xdl_free(ptr) free(ptr) |
| 52 | ++#define xdl_realloc(ptr, x) realloc(ptr, x) |
| 53 | ++ |
| 54 | ++#define XDL_BUG(msg) do { fprintf(stderr, "fatal: %s\n", msg); exit(128); } while(0) |
| 55 | ++ |
| 56 | ++#define xdl_regex_t regex_t |
| 57 | ++#define xdl_regmatch_t regmatch_t |
| 58 | ++ |
| 59 | ++inline int xdl_regexec_buf( |
| 60 | ++ const xdl_regex_t *preg, const char *buf, size_t size, |
| 61 | ++ size_t nmatch, xdl_regmatch_t pmatch[], int eflags) |
| 62 | ++{ |
| 63 | ++ pmatch[0].rm_so = 0; |
| 64 | ++ pmatch[0].rm_eo = size; |
| 65 | ++ |
| 66 | ++ return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND); |
| 67 | ++} |
| 68 | ++ |
| 69 | ++#endif |
| 70 | +diff --git a/xdiff.h b/xdiff.h |
| 71 | +index bb56b23..fb47f63 100644 |
| 72 | +--- a/xdiff.h |
| 73 | ++++ b/xdiff.h |
| 74 | +@@ -27,6 +27,8 @@ |
| 75 | + extern "C" { |
| 76 | + #endif /* #ifdef __cplusplus */ |
| 77 | + |
| 78 | ++#include "git-xdiff.h" |
| 79 | ++ |
| 80 | + /* xpparm_t.flags */ |
| 81 | + #define XDF_NEED_MINIMAL (1 << 0) |
| 82 | + |
| 83 | +@@ -82,7 +84,7 @@ typedef struct s_xpparam { |
| 84 | + unsigned long flags; |
| 85 | + |
| 86 | + /* -I<regex> */ |
| 87 | +- regex_t **ignore_regex; |
| 88 | ++ xdl_regex_t **ignore_regex; |
| 89 | + size_t ignore_regex_nr; |
| 90 | + |
| 91 | + /* See Documentation/diff-options.txt. */ |
| 92 | +@@ -119,11 +121,6 @@ typedef struct s_bdiffparam { |
| 93 | + } bdiffparam_t; |
| 94 | + |
| 95 | + |
| 96 | +-#define xdl_malloc(x) xmalloc(x) |
| 97 | +-#define xdl_calloc(n, sz) xcalloc(n, sz) |
| 98 | +-#define xdl_free(ptr) free(ptr) |
| 99 | +-#define xdl_realloc(ptr,x) xrealloc(ptr,x) |
| 100 | +- |
| 101 | + void *xdl_mmfile_first(mmfile_t *mmf, long *size); |
| 102 | + long xdl_mmfile_size(mmfile_t *mmf); |
| 103 | + |
| 104 | +diff --git a/xdiffi.c b/xdiffi.c |
| 105 | +index 344c2df..ea36143 100644 |
| 106 | +--- a/xdiffi.c |
| 107 | ++++ b/xdiffi.c |
| 108 | +@@ -833,7 +833,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { |
| 109 | + /* Shift the group backward as much as possible: */ |
| 110 | + while (!group_slide_up(xdf, &g)) |
| 111 | + if (group_previous(xdfo, &go)) |
| 112 | +- BUG("group sync broken sliding up"); |
| 113 | ++ XDL_BUG("group sync broken sliding up"); |
| 114 | + |
| 115 | + /* |
| 116 | + * This is this highest that this group can be shifted. |
| 117 | +@@ -849,7 +849,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { |
| 118 | + if (group_slide_down(xdf, &g)) |
| 119 | + break; |
| 120 | + if (group_next(xdfo, &go)) |
| 121 | +- BUG("group sync broken sliding down"); |
| 122 | ++ XDL_BUG("group sync broken sliding down"); |
| 123 | + |
| 124 | + if (go.end > go.start) |
| 125 | + end_matching_other = g.end; |
| 126 | +@@ -874,9 +874,9 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { |
| 127 | + */ |
| 128 | + while (go.end == go.start) { |
| 129 | + if (group_slide_up(xdf, &g)) |
| 130 | +- BUG("match disappeared"); |
| 131 | ++ XDL_BUG("match disappeared"); |
| 132 | + if (group_previous(xdfo, &go)) |
| 133 | +- BUG("group sync broken sliding to match"); |
| 134 | ++ XDL_BUG("group sync broken sliding to match"); |
| 135 | + } |
| 136 | + } else if (flags & XDF_INDENT_HEURISTIC) { |
| 137 | + /* |
| 138 | +@@ -917,9 +917,9 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { |
| 139 | + |
| 140 | + while (g.end > best_shift) { |
| 141 | + if (group_slide_up(xdf, &g)) |
| 142 | +- BUG("best shift unreached"); |
| 143 | ++ XDL_BUG("best shift unreached"); |
| 144 | + if (group_previous(xdfo, &go)) |
| 145 | +- BUG("group sync broken sliding to blank line"); |
| 146 | ++ XDL_BUG("group sync broken sliding to blank line"); |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | +@@ -928,11 +928,11 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { |
| 151 | + if (group_next(xdf, &g)) |
| 152 | + break; |
| 153 | + if (group_next(xdfo, &go)) |
| 154 | +- BUG("group sync broken moving to next group"); |
| 155 | ++ XDL_BUG("group sync broken moving to next group"); |
| 156 | + } |
| 157 | + |
| 158 | + if (!group_next(xdfo, &go)) |
| 159 | +- BUG("group sync broken at end of file"); |
| 160 | ++ XDL_BUG("group sync broken at end of file"); |
| 161 | + |
| 162 | + return 0; |
| 163 | + } |
| 164 | +@@ -973,7 +973,7 @@ void xdl_free_script(xdchange_t *xscr) { |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | +-static int xdl_call_hunk_func(xdfenv_t *xe UNUSED, xdchange_t *xscr, xdemitcb_t *ecb, |
| 169 | ++static int xdl_call_hunk_func(xdfenv_t *xe XDL_UNUSED, xdchange_t *xscr, xdemitcb_t *ecb, |
| 170 | + xdemitconf_t const *xecfg) |
| 171 | + { |
| 172 | + xdchange_t *xch, *xche; |
| 173 | +@@ -1012,11 +1012,11 @@ static void xdl_mark_ignorable_lines(xdchange_t *xscr, xdfenv_t *xe, long flags) |
| 174 | + } |
| 175 | + |
| 176 | + static int record_matches_regex(xrecord_t *rec, xpparam_t const *xpp) { |
| 177 | +- regmatch_t regmatch; |
| 178 | ++ xdl_regmatch_t regmatch; |
| 179 | + int i; |
| 180 | + |
| 181 | + for (i = 0; i < xpp->ignore_regex_nr; i++) |
| 182 | +- if (!regexec_buf(xpp->ignore_regex[i], rec->ptr, rec->size, 1, |
| 183 | ++ if (!xdl_regexec_buf(xpp->ignore_regex[i], rec->ptr, rec->size, 1, |
| 184 | + ®match, 0)) |
| 185 | + return 1; |
| 186 | + |
| 187 | +diff --git a/xinclude.h b/xinclude.h |
| 188 | +index a4285ac..75db1d8 100644 |
| 189 | +--- a/xinclude.h |
| 190 | ++++ b/xinclude.h |
| 191 | +@@ -23,7 +23,7 @@ |
| 192 | + #if !defined(XINCLUDE_H) |
| 193 | + #define XINCLUDE_H |
| 194 | + |
| 195 | +-#include "git-compat-util.h" |
| 196 | ++#include "git-xdiff.h" |
| 197 | + #include "xmacros.h" |
| 198 | + #include "xdiff.h" |
| 199 | + #include "xtypes.h" |
0 commit comments