Show More
@@ -280,16 +280,11 b' static PyObject *xdiffblocks(PyObject *s' | |||||
280 | XDF_INDENT_HEURISTIC, /* flags */ |
|
280 | XDF_INDENT_HEURISTIC, /* flags */ | |
281 | }; |
|
281 | }; | |
282 | xdemitconf_t xecfg = { |
|
282 | xdemitconf_t xecfg = { | |
283 | 0, /* ctxlen */ |
|
|||
284 | 0, /* interhunkctxlen */ |
|
|||
285 | XDL_EMIT_BDIFFHUNK, /* flags */ |
|
283 | XDL_EMIT_BDIFFHUNK, /* flags */ | |
286 | NULL, /* find_func */ |
|
|||
287 | NULL, /* find_func_priv */ |
|
|||
288 | hunk_consumer, /* hunk_consume_func */ |
|
284 | hunk_consumer, /* hunk_consume_func */ | |
289 | }; |
|
285 | }; | |
290 | xdemitcb_t ecb = { |
|
286 | xdemitcb_t ecb = { | |
291 | NULL, /* priv */ |
|
287 | NULL, /* priv */ | |
292 | NULL, /* outf */ |
|
|||
293 | }; |
|
288 | }; | |
294 |
|
289 | |||
295 | if (!PyArg_ParseTuple(args, PY23("s#s#", "y#y#"), &a.ptr, &la, &b.ptr, |
|
290 | if (!PyArg_ParseTuple(args, PY23("s#s#", "y#y#"), &a.ptr, &la, &b.ptr, |
@@ -34,9 +34,6 b' extern "C" {' | |||||
34 |
|
34 | |||
35 | #define XDF_INDENT_HEURISTIC (1 << 23) |
|
35 | #define XDF_INDENT_HEURISTIC (1 << 23) | |
36 |
|
36 | |||
37 | /* xdemitconf_t.flags */ |
|
|||
38 | #define XDL_EMIT_FUNCNAMES (1 << 0) |
|
|||
39 | #define XDL_EMIT_FUNCCONTEXT (1 << 2) |
|
|||
40 | /* emit bdiff-style "matched" (a1, a2, b1, b2) hunks instead of "different" |
|
37 | /* emit bdiff-style "matched" (a1, a2, b1, b2) hunks instead of "different" | |
41 | * (a1, a2 - a1, b1, b2 - b1) hunks */ |
|
38 | * (a1, a2 - a1, b1, b2 - b1) hunks */ | |
42 | #define XDL_EMIT_BDIFFHUNK (1 << 4) |
|
39 | #define XDL_EMIT_BDIFFHUNK (1 << 4) | |
@@ -71,21 +68,14 b' typedef struct s_xpparam {' | |||||
71 |
|
68 | |||
72 | typedef struct s_xdemitcb { |
|
69 | typedef struct s_xdemitcb { | |
73 | void *priv; |
|
70 | void *priv; | |
74 | int (*outf)(void *, mmbuffer_t *, int); |
|
|||
75 | } xdemitcb_t; |
|
71 | } xdemitcb_t; | |
76 |
|
72 | |||
77 | typedef long (*find_func_t)(const char *line, long line_len, char *buffer, long buffer_size, void *priv); |
|
|||
78 |
|
||||
79 | typedef int (*xdl_emit_hunk_consume_func_t)(long start_a, long count_a, |
|
73 | typedef int (*xdl_emit_hunk_consume_func_t)(long start_a, long count_a, | |
80 | long start_b, long count_b, |
|
74 | long start_b, long count_b, | |
81 | void *cb_data); |
|
75 | void *cb_data); | |
82 |
|
76 | |||
83 | typedef struct s_xdemitconf { |
|
77 | typedef struct s_xdemitconf { | |
84 | long ctxlen; |
|
|||
85 | long interhunkctxlen; |
|
|||
86 | unsigned long flags; |
|
78 | unsigned long flags; | |
87 | find_func_t find_func; |
|
|||
88 | void *find_func_priv; |
|
|||
89 | xdl_emit_hunk_consume_func_t hunk_func; |
|
79 | xdl_emit_hunk_consume_func_t hunk_func; | |
90 | } xdemitconf_t; |
|
80 | } xdemitconf_t; | |
91 |
|
81 |
@@ -1007,10 +1007,66 b' void xdl_free_script(xdchange_t *xscr) {' | |||||
1007 | } |
|
1007 | } | |
1008 | } |
|
1008 | } | |
1009 |
|
1009 | |||
|
1010 | ||||
|
1011 | /* | |||
|
1012 | * Starting at the passed change atom, find the latest change atom to be included | |||
|
1013 | * inside the differential hunk according to the specified configuration. | |||
|
1014 | * Also advance xscr if the first changes must be discarded. | |||
|
1015 | */ | |||
|
1016 | xdchange_t *xdl_get_hunk(xdchange_t **xscr, xdemitconf_t const *xecfg) | |||
|
1017 | { | |||
|
1018 | xdchange_t *xch, *xchp, *lxch; | |||
|
1019 | long max_common = 0; | |||
|
1020 | long max_ignorable = 0; | |||
|
1021 | unsigned long ignored = 0; /* number of ignored blank lines */ | |||
|
1022 | ||||
|
1023 | /* remove ignorable changes that are too far before other changes */ | |||
|
1024 | for (xchp = *xscr; xchp && xchp->ignore; xchp = xchp->next) { | |||
|
1025 | xch = xchp->next; | |||
|
1026 | ||||
|
1027 | if (xch == NULL || | |||
|
1028 | xch->i1 - (xchp->i1 + xchp->chg1) >= max_ignorable) | |||
|
1029 | *xscr = xch; | |||
|
1030 | } | |||
|
1031 | ||||
|
1032 | if (*xscr == NULL) | |||
|
1033 | return NULL; | |||
|
1034 | ||||
|
1035 | lxch = *xscr; | |||
|
1036 | ||||
|
1037 | for (xchp = *xscr, xch = xchp->next; xch; xchp = xch, xch = xch->next) { | |||
|
1038 | long distance = xch->i1 - (xchp->i1 + xchp->chg1); | |||
|
1039 | if (distance > max_common) | |||
|
1040 | break; | |||
|
1041 | ||||
|
1042 | if (distance < max_ignorable && (!xch->ignore || lxch == xchp)) { | |||
|
1043 | lxch = xch; | |||
|
1044 | ignored = 0; | |||
|
1045 | } else if (distance < max_ignorable && xch->ignore) { | |||
|
1046 | ignored += xch->chg2; | |||
|
1047 | } else if (lxch != xchp && | |||
|
1048 | xch->i1 + ignored - (lxch->i1 + lxch->chg1) > max_common) { | |||
|
1049 | break; | |||
|
1050 | } else if (!xch->ignore) { | |||
|
1051 | lxch = xch; | |||
|
1052 | ignored = 0; | |||
|
1053 | } else { | |||
|
1054 | ignored += xch->chg2; | |||
|
1055 | } | |||
|
1056 | } | |||
|
1057 | ||||
|
1058 | return lxch; | |||
|
1059 | } | |||
|
1060 | ||||
|
1061 | ||||
1010 | static int xdl_call_hunk_func(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, |
|
1062 | static int xdl_call_hunk_func(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, | |
1011 | xdemitconf_t const *xecfg) |
|
1063 | xdemitconf_t const *xecfg) | |
1012 | { |
|
1064 | { | |
1013 | xdchange_t *xch, *xche; |
|
1065 | xdchange_t *xch, *xche; | |
|
1066 | ||||
|
1067 | if (!xecfg->hunk_func) | |||
|
1068 | return -1; | |||
|
1069 | ||||
1014 | if ((xecfg->flags & XDL_EMIT_BDIFFHUNK) != 0) { |
|
1070 | if ((xecfg->flags & XDL_EMIT_BDIFFHUNK) != 0) { | |
1015 | long i1 = 0, i2 = 0, n1 = xe->xdf1.nrec, n2 = xe->xdf2.nrec; |
|
1071 | long i1 = 0, i2 = 0, n1 = xe->xdf1.nrec, n2 = xe->xdf2.nrec; | |
1016 | for (xch = xscr; xch; xch = xche->next) { |
|
1072 | for (xch = xscr; xch; xch = xche->next) { | |
@@ -1045,7 +1101,6 b' int xdl_diff(mmfile_t *mf1, mmfile_t *mf' | |||||
1045 | xdemitconf_t const *xecfg, xdemitcb_t *ecb) { |
|
1101 | xdemitconf_t const *xecfg, xdemitcb_t *ecb) { | |
1046 | xdchange_t *xscr; |
|
1102 | xdchange_t *xscr; | |
1047 | xdfenv_t xe; |
|
1103 | xdfenv_t xe; | |
1048 | emit_func_t ef = xecfg->hunk_func ? xdl_call_hunk_func : xdl_emit_diff; |
|
|||
1049 |
|
1104 | |||
1050 | if (xdl_do_diff(mf1, mf2, xpp, &xe) < 0) { |
|
1105 | if (xdl_do_diff(mf1, mf2, xpp, &xe) < 0) { | |
1051 |
|
1106 | |||
@@ -1059,7 +1114,7 b' int xdl_diff(mmfile_t *mf1, mmfile_t *mf' | |||||
1059 | return -1; |
|
1114 | return -1; | |
1060 | } |
|
1115 | } | |
1061 |
|
1116 | |||
1062 |
if ( |
|
1117 | if (xdl_call_hunk_func(&xe, xscr, ecb, xecfg) < 0) { | |
1063 | xdl_free_script(xscr); |
|
1118 | xdl_free_script(xscr); | |
1064 | xdl_free_env(&xe); |
|
1119 | xdl_free_env(&xe); | |
1065 | return -1; |
|
1120 | return -1; |
@@ -54,7 +54,5 b' int xdl_do_diff(mmfile_t *mf1, mmfile_t ' | |||||
54 | int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags); |
|
54 | int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags); | |
55 | int xdl_build_script(xdfenv_t *xe, xdchange_t **xscr); |
|
55 | int xdl_build_script(xdfenv_t *xe, xdchange_t **xscr); | |
56 | void xdl_free_script(xdchange_t *xscr); |
|
56 | void xdl_free_script(xdchange_t *xscr); | |
57 | int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, |
|
|||
58 | xdemitconf_t const *xecfg); |
|
|||
59 |
|
57 | |||
60 | #endif /* #if !defined(XDIFFI_H) */ |
|
58 | #endif /* #if !defined(XDIFFI_H) */ |
@@ -35,7 +35,6 b'' | |||||
35 | #include "xutils.h" |
|
35 | #include "xutils.h" | |
36 | #include "xprepare.h" |
|
36 | #include "xprepare.h" | |
37 | #include "xdiffi.h" |
|
37 | #include "xdiffi.h" | |
38 | #include "xemit.h" |
|
|||
39 |
|
38 | |||
40 |
|
39 | |||
41 | #endif /* #if !defined(XINCLUDE_H) */ |
|
40 | #endif /* #if !defined(XINCLUDE_H) */ |
@@ -40,28 +40,6 b' long xdl_bogosqrt(long n) {' | |||||
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 |
|
42 | |||
43 | int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize, |
|
|||
44 | xdemitcb_t *ecb) { |
|
|||
45 | int i = 2; |
|
|||
46 | mmbuffer_t mb[3]; |
|
|||
47 |
|
||||
48 | mb[0].ptr = (char *) pre; |
|
|||
49 | mb[0].size = psize; |
|
|||
50 | mb[1].ptr = (char *) rec; |
|
|||
51 | mb[1].size = size; |
|
|||
52 | if (size > 0 && rec[size - 1] != '\n') { |
|
|||
53 | mb[2].ptr = (char *) "\n\\ No newline at end of file\n"; |
|
|||
54 | mb[2].size = strlen(mb[2].ptr); |
|
|||
55 | i++; |
|
|||
56 | } |
|
|||
57 | if (ecb->outf(ecb->priv, mb, i) < 0) { |
|
|||
58 |
|
||||
59 | return -1; |
|
|||
60 | } |
|
|||
61 |
|
||||
62 | return 0; |
|
|||
63 | } |
|
|||
64 |
|
||||
65 | void *xdl_mmfile_first(mmfile_t *mmf, long *size) |
|
43 | void *xdl_mmfile_first(mmfile_t *mmf, long *size) | |
66 | { |
|
44 | { | |
67 | *size = mmf->size; |
|
45 | *size = mmf->size; | |
@@ -169,75 +147,3 b' unsigned int xdl_hashbits(unsigned int s' | |||||
169 | for (; val < size && bits < CHAR_BIT * sizeof(unsigned int); val <<= 1, bits++); |
|
147 | for (; val < size && bits < CHAR_BIT * sizeof(unsigned int); val <<= 1, bits++); | |
170 | return bits ? bits: 1; |
|
148 | return bits ? bits: 1; | |
171 | } |
|
149 | } | |
172 |
|
||||
173 |
|
||||
174 | int xdl_num_out(char *out, long val) { |
|
|||
175 | char *ptr, *str = out; |
|
|||
176 | char buf[32]; |
|
|||
177 |
|
||||
178 | ptr = buf + sizeof(buf) - 1; |
|
|||
179 | *ptr = '\0'; |
|
|||
180 | if (val < 0) { |
|
|||
181 | *--ptr = '-'; |
|
|||
182 | val = -val; |
|
|||
183 | } |
|
|||
184 | for (; val && ptr > buf; val /= 10) |
|
|||
185 | *--ptr = "0123456789"[val % 10]; |
|
|||
186 | if (*ptr) |
|
|||
187 | for (; *ptr; ptr++, str++) |
|
|||
188 | *str = *ptr; |
|
|||
189 | else |
|
|||
190 | *str++ = '0'; |
|
|||
191 | *str = '\0'; |
|
|||
192 |
|
||||
193 | return str - out; |
|
|||
194 | } |
|
|||
195 |
|
||||
196 | int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2, |
|
|||
197 | const char *func, long funclen, xdemitcb_t *ecb) { |
|
|||
198 | int nb = 0; |
|
|||
199 | mmbuffer_t mb; |
|
|||
200 | char buf[128]; |
|
|||
201 |
|
||||
202 | memcpy(buf, "@@ -", 4); |
|
|||
203 | nb += 4; |
|
|||
204 |
|
||||
205 | nb += xdl_num_out(buf + nb, c1 ? s1: s1 - 1); |
|
|||
206 |
|
||||
207 | if (c1 != 1) { |
|
|||
208 | memcpy(buf + nb, ",", 1); |
|
|||
209 | nb += 1; |
|
|||
210 |
|
||||
211 | nb += xdl_num_out(buf + nb, c1); |
|
|||
212 | } |
|
|||
213 |
|
||||
214 | memcpy(buf + nb, " +", 2); |
|
|||
215 | nb += 2; |
|
|||
216 |
|
||||
217 | nb += xdl_num_out(buf + nb, c2 ? s2: s2 - 1); |
|
|||
218 |
|
||||
219 | if (c2 != 1) { |
|
|||
220 | memcpy(buf + nb, ",", 1); |
|
|||
221 | nb += 1; |
|
|||
222 |
|
||||
223 | nb += xdl_num_out(buf + nb, c2); |
|
|||
224 | } |
|
|||
225 |
|
||||
226 | memcpy(buf + nb, " @@", 3); |
|
|||
227 | nb += 3; |
|
|||
228 | if (func && funclen) { |
|
|||
229 | buf[nb++] = ' '; |
|
|||
230 | if (funclen > sizeof(buf) - nb - 1) |
|
|||
231 | funclen = sizeof(buf) - nb - 1; |
|
|||
232 | memcpy(buf + nb, func, funclen); |
|
|||
233 | nb += funclen; |
|
|||
234 | } |
|
|||
235 | buf[nb++] = '\n'; |
|
|||
236 |
|
||||
237 | mb.ptr = buf; |
|
|||
238 | mb.size = nb; |
|
|||
239 | if (ecb->outf(ecb->priv, &mb, 1) < 0) |
|
|||
240 | return -1; |
|
|||
241 |
|
||||
242 | return 0; |
|
|||
243 | } |
|
@@ -26,8 +26,6 b'' | |||||
26 |
|
26 | |||
27 |
|
27 | |||
28 | long xdl_bogosqrt(long n); |
|
28 | long xdl_bogosqrt(long n); | |
29 | int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize, |
|
|||
30 | xdemitcb_t *ecb); |
|
|||
31 | int xdl_cha_init(chastore_t *cha, long isize, long icount); |
|
29 | int xdl_cha_init(chastore_t *cha, long isize, long icount); | |
32 | void xdl_cha_free(chastore_t *cha); |
|
30 | void xdl_cha_free(chastore_t *cha); | |
33 | void *xdl_cha_alloc(chastore_t *cha); |
|
31 | void *xdl_cha_alloc(chastore_t *cha); | |
@@ -35,9 +33,6 b' long xdl_guess_lines(mmfile_t *mf, long ' | |||||
35 | int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags); |
|
33 | int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags); | |
36 | unsigned long xdl_hash_record(char const **data, char const *top, long flags); |
|
34 | unsigned long xdl_hash_record(char const **data, char const *top, long flags); | |
37 | unsigned int xdl_hashbits(unsigned int size); |
|
35 | unsigned int xdl_hashbits(unsigned int size); | |
38 | int xdl_num_out(char *out, long val); |
|
|||
39 | int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2, |
|
|||
40 | const char *func, long funclen, xdemitcb_t *ecb); |
|
|||
41 |
|
36 | |||
42 |
|
37 | |||
43 |
|
38 |
@@ -850,7 +850,6 b" if sys.platform == 'darwin':" | |||||
850 |
|
850 | |||
851 | xdiff_srcs = [ |
|
851 | xdiff_srcs = [ | |
852 | 'mercurial/thirdparty/xdiff/xdiffi.c', |
|
852 | 'mercurial/thirdparty/xdiff/xdiffi.c', | |
853 | 'mercurial/thirdparty/xdiff/xemit.c', |
|
|||
854 | 'mercurial/thirdparty/xdiff/xmerge.c', |
|
853 | 'mercurial/thirdparty/xdiff/xmerge.c', | |
855 | 'mercurial/thirdparty/xdiff/xprepare.c', |
|
854 | 'mercurial/thirdparty/xdiff/xprepare.c', | |
856 | 'mercurial/thirdparty/xdiff/xutils.c', |
|
855 | 'mercurial/thirdparty/xdiff/xutils.c', | |
@@ -859,7 +858,6 b' xdiff_srcs = [' | |||||
859 | xdiff_headers = [ |
|
858 | xdiff_headers = [ | |
860 | 'mercurial/thirdparty/xdiff/xdiff.h', |
|
859 | 'mercurial/thirdparty/xdiff/xdiff.h', | |
861 | 'mercurial/thirdparty/xdiff/xdiffi.h', |
|
860 | 'mercurial/thirdparty/xdiff/xdiffi.h', | |
862 | 'mercurial/thirdparty/xdiff/xemit.h', |
|
|||
863 | 'mercurial/thirdparty/xdiff/xinclude.h', |
|
861 | 'mercurial/thirdparty/xdiff/xinclude.h', | |
864 | 'mercurial/thirdparty/xdiff/xmacros.h', |
|
862 | 'mercurial/thirdparty/xdiff/xmacros.h', | |
865 | 'mercurial/thirdparty/xdiff/xprepare.h', |
|
863 | 'mercurial/thirdparty/xdiff/xprepare.h', |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now