Mercurial > vim
annotate src/diff.c @ 14730:193471015e1a v8.1.0377
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
commit https://github.com/vim/vim/commit/42335f50bc6fac444a8af74c81df8369d722a6fb
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 13 15:33:43 2018 +0200
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Problem: Xdiff doesn't use the Vim memory allocation functions.
Solution: Change the xdl_ defines. Check for out-of-memory. Rename
"ignored" to "vim_ignored".
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 13 Sep 2018 15:45:05 +0200 |
parents | 655f00c29c58 |
children | b43ea03bb522 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10013
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
1788 | 11 * diff.c: code for diff'ing two, three or four buffers. |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
12 * |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
13 * There are three ways to diff: |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
14 * - Shell out to an external diff program, using files. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
15 * - Use the compiled-in xdiff library. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
16 * - Let 'diffexpr' do the work, using files. |
7 | 17 */ |
18 | |
19 #include "vim.h" | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
20 #include "xdiff/xdiff.h" |
7 | 21 |
22 #if defined(FEAT_DIFF) || defined(PROTO) | |
23 | |
24 static int diff_busy = FALSE; /* ex_diffgetput() is busy */ | |
25 | |
26 /* flags obtained from the 'diffopt' option */ | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
27 #define DIFF_FILLER 1 // display filler lines |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
28 #define DIFF_ICASE 2 // ignore case |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
29 #define DIFF_IWHITE 4 // ignore change in white space |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
30 #define DIFF_HORIZONTAL 8 // horizontal splits |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
31 #define DIFF_VERTICAL 16 // vertical splits |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
32 #define DIFF_HIDDEN_OFF 32 // diffoff when hidden |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
33 #define DIFF_INTERNAL 64 // use internal xdiff algorithm |
14716
973d3f4d8017
patch 8.1.0370: not using internal diff if 'diffopt' is not changed
Christian Brabandt <cb@256bit.org>
parents:
14696
diff
changeset
|
34 static int diff_flags = DIFF_INTERNAL | DIFF_FILLER; |
7 | 35 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
36 static long diff_algorithm = 0; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
37 |
7 | 38 #define LBUFLEN 50 /* length of line in diff file */ |
39 | |
40 static int diff_a_works = MAYBE; /* TRUE when "diff -a" works, FALSE when it | |
41 doesn't work, MAYBE when not checked yet */ | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
42 #if defined(MSWIN) |
7 | 43 static int diff_bin_works = MAYBE; /* TRUE when "diff --binary" works, FALSE |
44 when it doesn't work, MAYBE when not | |
45 checked yet */ | |
46 #endif | |
47 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
48 // used for diff input |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
49 typedef struct { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
50 char_u *din_fname; // used for external diff |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
51 mmfile_t din_mmfile; // used for internal diff |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
52 } diffin_T; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
53 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
54 // used for diff result |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
55 typedef struct { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
56 char_u *dout_fname; // used for external diff |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
57 garray_T dout_ga; // used for internal diff |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
58 } diffout_T; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
59 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
60 // two diff inputs and one result |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
61 typedef struct { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
62 diffin_T dio_orig; // original file input |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
63 diffin_T dio_new; // new file input |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
64 diffout_T dio_diff; // diff result |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
65 int dio_internal; // using internal diff |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
66 } diffio_T; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
67 |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
68 static int diff_buf_idx(buf_T *buf); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
69 static int diff_buf_idx_tp(buf_T *buf, tabpage_T *tp); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
70 static void diff_mark_adjust_tp(tabpage_T *tp, int idx, linenr_T line1, linenr_T line2, long amount, long amount_after); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
71 static void diff_check_unchanged(tabpage_T *tp, diff_T *dp); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
72 static int diff_check_sanity(tabpage_T *tp, diff_T *dp); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
73 static void diff_redraw(int dofold); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
74 static int check_external_diff(diffio_T *diffio); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
75 static int diff_file(diffio_T *diffio); |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
76 static int diff_equal_entry(diff_T *dp, int idx1, int idx2); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
77 static int diff_cmp(char_u *s1, char_u *s2); |
7 | 78 #ifdef FEAT_FOLDING |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
79 static void diff_fold_update(diff_T *dp, int skip_idx); |
7 | 80 #endif |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
81 static void diff_read(int idx_orig, int idx_new, diffout_T *fname); |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
82 static void diff_copy_entry(diff_T *dprev, diff_T *dp, int idx_orig, int idx_new); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7338
diff
changeset
|
83 static diff_T *diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
84 static int parse_diff_ed(char_u *line, linenr_T *lnum_orig, long *count_orig, linenr_T *lnum_new, long *count_new); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
85 static int parse_diff_unified(char_u *line, linenr_T *lnum_orig, long *count_orig, linenr_T *lnum_new, long *count_new); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
86 static int xdiff_out(void *priv, mmbuffer_t *mb, int nbuf); |
7 | 87 |
88 #ifndef USE_CR | |
89 # define tag_fgets vim_fgets | |
90 #endif | |
91 | |
92 /* | |
93 * Called when deleting or unloading a buffer: No longer make a diff with it. | |
94 */ | |
95 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
96 diff_buf_delete(buf_T *buf) |
7 | 97 { |
98 int i; | |
672 | 99 tabpage_T *tp; |
7 | 100 |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
101 FOR_ALL_TABPAGES(tp) |
7 | 102 { |
672 | 103 i = diff_buf_idx_tp(buf, tp); |
104 if (i != DB_COUNT) | |
105 { | |
106 tp->tp_diffbuf[i] = NULL; | |
107 tp->tp_diff_invalid = TRUE; | |
1761 | 108 if (tp == curtab) |
109 diff_redraw(TRUE); | |
672 | 110 } |
7 | 111 } |
112 } | |
113 | |
114 /* | |
16 | 115 * Check if the current buffer should be added to or removed from the list of |
116 * diff buffers. | |
117 */ | |
118 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
119 diff_buf_adjust(win_T *win) |
16 | 120 { |
121 win_T *wp; | |
672 | 122 int i; |
16 | 123 |
124 if (!win->w_p_diff) | |
125 { | |
126 /* When there is no window showing a diff for this buffer, remove | |
127 * it from the diffs. */ | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
128 FOR_ALL_WINDOWS(wp) |
16 | 129 if (wp->w_buffer == win->w_buffer && wp->w_p_diff) |
130 break; | |
131 if (wp == NULL) | |
672 | 132 { |
133 i = diff_buf_idx(win->w_buffer); | |
134 if (i != DB_COUNT) | |
135 { | |
136 curtab->tp_diffbuf[i] = NULL; | |
137 curtab->tp_diff_invalid = TRUE; | |
1761 | 138 diff_redraw(TRUE); |
672 | 139 } |
140 } | |
16 | 141 } |
142 else | |
143 diff_buf_add(win->w_buffer); | |
144 } | |
145 | |
146 /* | |
7 | 147 * Add a buffer to make diffs for. |
672 | 148 * Call this when a new buffer is being edited in the current window where |
149 * 'diff' is set. | |
1788 | 150 * Marks the current buffer as being part of the diff and requiring updating. |
672 | 151 * This must be done before any autocmd, because a command may use info |
152 * about the screen contents. | |
7 | 153 */ |
154 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
155 diff_buf_add(buf_T *buf) |
7 | 156 { |
157 int i; | |
158 | |
159 if (diff_buf_idx(buf) != DB_COUNT) | |
160 return; /* It's already there. */ | |
161 | |
162 for (i = 0; i < DB_COUNT; ++i) | |
672 | 163 if (curtab->tp_diffbuf[i] == NULL) |
7 | 164 { |
672 | 165 curtab->tp_diffbuf[i] = buf; |
166 curtab->tp_diff_invalid = TRUE; | |
1761 | 167 diff_redraw(TRUE); |
7 | 168 return; |
169 } | |
170 | |
9719
219dbe63ad2a
commit https://github.com/vim/vim/commit/89eaa4185efacab253b23a182c1c8a7bbf1096c9
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
171 EMSGN(_("E96: Cannot diff more than %ld buffers"), DB_COUNT); |
7 | 172 } |
173 | |
174 /* | |
10821
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
175 * Remove all buffers to make diffs for. |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
176 */ |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
177 static void |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
178 diff_buf_clear(void) |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
179 { |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
180 int i; |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
181 |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
182 for (i = 0; i < DB_COUNT; ++i) |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
183 if (curtab->tp_diffbuf[i] != NULL) |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
184 { |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
185 curtab->tp_diffbuf[i] = NULL; |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
186 curtab->tp_diff_invalid = TRUE; |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
187 diff_redraw(TRUE); |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
188 } |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
189 } |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
190 |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
191 /* |
672 | 192 * Find buffer "buf" in the list of diff buffers for the current tab page. |
7 | 193 * Return its index or DB_COUNT if not found. |
194 */ | |
195 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
196 diff_buf_idx(buf_T *buf) |
7 | 197 { |
198 int idx; | |
199 | |
200 for (idx = 0; idx < DB_COUNT; ++idx) | |
672 | 201 if (curtab->tp_diffbuf[idx] == buf) |
202 break; | |
203 return idx; | |
204 } | |
205 | |
206 /* | |
207 * Find buffer "buf" in the list of diff buffers for tab page "tp". | |
208 * Return its index or DB_COUNT if not found. | |
209 */ | |
210 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
211 diff_buf_idx_tp(buf_T *buf, tabpage_T *tp) |
672 | 212 { |
213 int idx; | |
214 | |
215 for (idx = 0; idx < DB_COUNT; ++idx) | |
216 if (tp->tp_diffbuf[idx] == buf) | |
7 | 217 break; |
218 return idx; | |
219 } | |
220 | |
221 /* | |
672 | 222 * Mark the diff info involving buffer "buf" as invalid, it will be updated |
223 * when info is requested. | |
7 | 224 */ |
225 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
226 diff_invalidate(buf_T *buf) |
7 | 227 { |
672 | 228 tabpage_T *tp; |
229 int i; | |
230 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
231 FOR_ALL_TABPAGES(tp) |
7 | 232 { |
672 | 233 i = diff_buf_idx_tp(buf, tp); |
234 if (i != DB_COUNT) | |
235 { | |
236 tp->tp_diff_invalid = TRUE; | |
237 if (tp == curtab) | |
238 diff_redraw(TRUE); | |
239 } | |
7 | 240 } |
241 } | |
242 | |
243 /* | |
672 | 244 * Called by mark_adjust(): update line numbers in "curbuf". |
7 | 245 */ |
246 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
247 diff_mark_adjust( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
248 linenr_T line1, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
249 linenr_T line2, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
250 long amount, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
251 long amount_after) |
7 | 252 { |
672 | 253 int idx; |
254 tabpage_T *tp; | |
255 | |
256 /* Handle all tab pages that use the current buffer in a diff. */ | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
257 FOR_ALL_TABPAGES(tp) |
672 | 258 { |
259 idx = diff_buf_idx_tp(curbuf, tp); | |
260 if (idx != DB_COUNT) | |
261 diff_mark_adjust_tp(tp, idx, line1, line2, amount, amount_after); | |
262 } | |
263 } | |
264 | |
265 /* | |
266 * Update line numbers in tab page "tp" for "curbuf" with index "idx". | |
267 * This attempts to update the changes as much as possible: | |
268 * When inserting/deleting lines outside of existing change blocks, create a | |
269 * new change block and update the line numbers in following blocks. | |
270 * When inserting/deleting lines in existing change blocks, update them. | |
271 */ | |
272 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
273 diff_mark_adjust_tp( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
274 tabpage_T *tp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
275 int idx, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
276 linenr_T line1, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
277 linenr_T line2, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
278 long amount, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
279 long amount_after) |
672 | 280 { |
7 | 281 diff_T *dp; |
282 diff_T *dprev; | |
283 diff_T *dnext; | |
284 int i; | |
285 int inserted, deleted; | |
286 int n, off; | |
287 linenr_T last; | |
288 linenr_T lnum_deleted = line1; /* lnum of remaining deletion */ | |
289 int check_unchanged; | |
290 | |
291 if (line2 == MAXLNUM) | |
292 { | |
293 /* mark_adjust(99, MAXLNUM, 9, 0): insert lines */ | |
294 inserted = amount; | |
295 deleted = 0; | |
296 } | |
297 else if (amount_after > 0) | |
298 { | |
299 /* mark_adjust(99, 98, MAXLNUM, 9): a change that inserts lines*/ | |
300 inserted = amount_after; | |
301 deleted = 0; | |
302 } | |
303 else | |
304 { | |
305 /* mark_adjust(98, 99, MAXLNUM, -2): delete lines */ | |
306 inserted = 0; | |
307 deleted = -amount_after; | |
308 } | |
309 | |
310 dprev = NULL; | |
672 | 311 dp = tp->tp_first_diff; |
7 | 312 for (;;) |
313 { | |
314 /* If the change is after the previous diff block and before the next | |
315 * diff block, thus not touching an existing change, create a new diff | |
316 * block. Don't do this when ex_diffgetput() is busy. */ | |
317 if ((dp == NULL || dp->df_lnum[idx] - 1 > line2 | |
318 || (line2 == MAXLNUM && dp->df_lnum[idx] > line1)) | |
319 && (dprev == NULL | |
320 || dprev->df_lnum[idx] + dprev->df_count[idx] < line1) | |
321 && !diff_busy) | |
322 { | |
672 | 323 dnext = diff_alloc_new(tp, dprev, dp); |
7 | 324 if (dnext == NULL) |
325 return; | |
326 | |
327 dnext->df_lnum[idx] = line1; | |
328 dnext->df_count[idx] = inserted; | |
329 for (i = 0; i < DB_COUNT; ++i) | |
672 | 330 if (tp->tp_diffbuf[i] != NULL && i != idx) |
7 | 331 { |
332 if (dprev == NULL) | |
333 dnext->df_lnum[i] = line1; | |
334 else | |
335 dnext->df_lnum[i] = line1 | |
336 + (dprev->df_lnum[i] + dprev->df_count[i]) | |
337 - (dprev->df_lnum[idx] + dprev->df_count[idx]); | |
338 dnext->df_count[i] = deleted; | |
339 } | |
340 } | |
341 | |
342 /* if at end of the list, quit */ | |
343 if (dp == NULL) | |
344 break; | |
345 | |
346 /* | |
347 * Check for these situations: | |
348 * 1 2 3 | |
349 * 1 2 3 | |
350 * line1 2 3 4 5 | |
351 * 2 3 4 5 | |
352 * 2 3 4 5 | |
353 * line2 2 3 4 5 | |
354 * 3 5 6 | |
355 * 3 5 6 | |
356 */ | |
357 /* compute last line of this change */ | |
358 last = dp->df_lnum[idx] + dp->df_count[idx] - 1; | |
359 | |
360 /* 1. change completely above line1: nothing to do */ | |
361 if (last >= line1 - 1) | |
362 { | |
363 /* 6. change below line2: only adjust for amount_after; also when | |
364 * "deleted" became zero when deleted all lines between two diffs */ | |
365 if (dp->df_lnum[idx] - (deleted + inserted != 0) > line2) | |
366 { | |
367 if (amount_after == 0) | |
368 break; /* nothing left to change */ | |
369 dp->df_lnum[idx] += amount_after; | |
370 } | |
371 else | |
372 { | |
373 check_unchanged = FALSE; | |
374 | |
375 /* 2. 3. 4. 5.: inserted/deleted lines touching this diff. */ | |
376 if (deleted > 0) | |
377 { | |
378 if (dp->df_lnum[idx] >= line1) | |
379 { | |
380 off = dp->df_lnum[idx] - lnum_deleted; | |
381 if (last <= line2) | |
382 { | |
383 /* 4. delete all lines of diff */ | |
384 if (dp->df_next != NULL | |
385 && dp->df_next->df_lnum[idx] - 1 <= line2) | |
386 { | |
387 /* delete continues in next diff, only do | |
388 * lines until that one */ | |
389 n = dp->df_next->df_lnum[idx] - lnum_deleted; | |
390 deleted -= n; | |
391 n -= dp->df_count[idx]; | |
392 lnum_deleted = dp->df_next->df_lnum[idx]; | |
393 } | |
394 else | |
395 n = deleted - dp->df_count[idx]; | |
396 dp->df_count[idx] = 0; | |
397 } | |
398 else | |
399 { | |
400 /* 5. delete lines at or just before top of diff */ | |
401 n = off; | |
402 dp->df_count[idx] -= line2 - dp->df_lnum[idx] + 1; | |
403 check_unchanged = TRUE; | |
404 } | |
405 dp->df_lnum[idx] = line1; | |
406 } | |
407 else | |
408 { | |
409 off = 0; | |
410 if (last < line2) | |
411 { | |
412 /* 2. delete at end of of diff */ | |
413 dp->df_count[idx] -= last - lnum_deleted + 1; | |
414 if (dp->df_next != NULL | |
415 && dp->df_next->df_lnum[idx] - 1 <= line2) | |
416 { | |
417 /* delete continues in next diff, only do | |
418 * lines until that one */ | |
419 n = dp->df_next->df_lnum[idx] - 1 - last; | |
420 deleted -= dp->df_next->df_lnum[idx] | |
421 - lnum_deleted; | |
422 lnum_deleted = dp->df_next->df_lnum[idx]; | |
423 } | |
424 else | |
425 n = line2 - last; | |
426 check_unchanged = TRUE; | |
427 } | |
428 else | |
429 { | |
430 /* 3. delete lines inside the diff */ | |
431 n = 0; | |
432 dp->df_count[idx] -= deleted; | |
433 } | |
434 } | |
435 | |
436 for (i = 0; i < DB_COUNT; ++i) | |
672 | 437 if (tp->tp_diffbuf[i] != NULL && i != idx) |
7 | 438 { |
439 dp->df_lnum[i] -= off; | |
440 dp->df_count[i] += n; | |
441 } | |
442 } | |
443 else | |
444 { | |
445 if (dp->df_lnum[idx] <= line1) | |
446 { | |
447 /* inserted lines somewhere in this diff */ | |
448 dp->df_count[idx] += inserted; | |
449 check_unchanged = TRUE; | |
450 } | |
451 else | |
452 /* inserted lines somewhere above this diff */ | |
453 dp->df_lnum[idx] += inserted; | |
454 } | |
455 | |
456 if (check_unchanged) | |
457 /* Check if inserted lines are equal, may reduce the | |
458 * size of the diff. TODO: also check for equal lines | |
459 * in the middle and perhaps split the block. */ | |
672 | 460 diff_check_unchanged(tp, dp); |
7 | 461 } |
462 } | |
463 | |
464 /* check if this block touches the previous one, may merge them. */ | |
465 if (dprev != NULL && dprev->df_lnum[idx] + dprev->df_count[idx] | |
466 == dp->df_lnum[idx]) | |
467 { | |
468 for (i = 0; i < DB_COUNT; ++i) | |
672 | 469 if (tp->tp_diffbuf[i] != NULL) |
7 | 470 dprev->df_count[i] += dp->df_count[i]; |
471 dprev->df_next = dp->df_next; | |
472 vim_free(dp); | |
473 dp = dprev->df_next; | |
474 } | |
475 else | |
476 { | |
477 /* Advance to next entry. */ | |
478 dprev = dp; | |
479 dp = dp->df_next; | |
480 } | |
481 } | |
482 | |
483 dprev = NULL; | |
672 | 484 dp = tp->tp_first_diff; |
7 | 485 while (dp != NULL) |
486 { | |
487 /* All counts are zero, remove this entry. */ | |
488 for (i = 0; i < DB_COUNT; ++i) | |
672 | 489 if (tp->tp_diffbuf[i] != NULL && dp->df_count[i] != 0) |
7 | 490 break; |
491 if (i == DB_COUNT) | |
492 { | |
493 dnext = dp->df_next; | |
494 vim_free(dp); | |
495 dp = dnext; | |
496 if (dprev == NULL) | |
672 | 497 tp->tp_first_diff = dnext; |
7 | 498 else |
499 dprev->df_next = dnext; | |
500 } | |
501 else | |
502 { | |
503 /* Advance to next entry. */ | |
504 dprev = dp; | |
505 dp = dp->df_next; | |
506 } | |
507 | |
508 } | |
672 | 509 |
510 if (tp == curtab) | |
511 { | |
512 diff_redraw(TRUE); | |
7 | 513 |
672 | 514 /* Need to recompute the scroll binding, may remove or add filler |
515 * lines (e.g., when adding lines above w_topline). But it's slow when | |
516 * making many changes, postpone until redrawing. */ | |
517 diff_need_scrollbind = TRUE; | |
518 } | |
7 | 519 } |
520 | |
521 /* | |
522 * Allocate a new diff block and link it between "dprev" and "dp". | |
523 */ | |
524 static diff_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
525 diff_alloc_new(tabpage_T *tp, diff_T *dprev, diff_T *dp) |
7 | 526 { |
527 diff_T *dnew; | |
528 | |
529 dnew = (diff_T *)alloc((unsigned)sizeof(diff_T)); | |
530 if (dnew != NULL) | |
531 { | |
532 dnew->df_next = dp; | |
533 if (dprev == NULL) | |
672 | 534 tp->tp_first_diff = dnew; |
7 | 535 else |
536 dprev->df_next = dnew; | |
537 } | |
538 return dnew; | |
539 } | |
540 | |
541 /* | |
542 * Check if the diff block "dp" can be made smaller for lines at the start and | |
543 * end that are equal. Called after inserting lines. | |
544 * This may result in a change where all buffers have zero lines, the caller | |
545 * must take care of removing it. | |
546 */ | |
547 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
548 diff_check_unchanged(tabpage_T *tp, diff_T *dp) |
7 | 549 { |
550 int i_org; | |
551 int i_new; | |
552 int off_org, off_new; | |
553 char_u *line_org; | |
554 int dir = FORWARD; | |
555 | |
556 /* Find the first buffers, use it as the original, compare the other | |
557 * buffer lines against this one. */ | |
558 for (i_org = 0; i_org < DB_COUNT; ++i_org) | |
672 | 559 if (tp->tp_diffbuf[i_org] != NULL) |
7 | 560 break; |
561 if (i_org == DB_COUNT) /* safety check */ | |
562 return; | |
563 | |
672 | 564 if (diff_check_sanity(tp, dp) == FAIL) |
7 | 565 return; |
566 | |
567 /* First check lines at the top, then at the bottom. */ | |
568 off_org = 0; | |
569 off_new = 0; | |
570 for (;;) | |
571 { | |
572 /* Repeat until a line is found which is different or the number of | |
573 * lines has become zero. */ | |
574 while (dp->df_count[i_org] > 0) | |
575 { | |
576 /* Copy the line, the next ml_get() will invalidate it. */ | |
577 if (dir == BACKWARD) | |
578 off_org = dp->df_count[i_org] - 1; | |
672 | 579 line_org = vim_strsave(ml_get_buf(tp->tp_diffbuf[i_org], |
7 | 580 dp->df_lnum[i_org] + off_org, FALSE)); |
581 if (line_org == NULL) | |
582 return; | |
583 for (i_new = i_org + 1; i_new < DB_COUNT; ++i_new) | |
584 { | |
672 | 585 if (tp->tp_diffbuf[i_new] == NULL) |
7 | 586 continue; |
587 if (dir == BACKWARD) | |
588 off_new = dp->df_count[i_new] - 1; | |
589 /* if other buffer doesn't have this line, it was inserted */ | |
590 if (off_new < 0 || off_new >= dp->df_count[i_new]) | |
591 break; | |
672 | 592 if (diff_cmp(line_org, ml_get_buf(tp->tp_diffbuf[i_new], |
7 | 593 dp->df_lnum[i_new] + off_new, FALSE)) != 0) |
594 break; | |
595 } | |
596 vim_free(line_org); | |
597 | |
598 /* Stop when a line isn't equal in all diff buffers. */ | |
599 if (i_new != DB_COUNT) | |
600 break; | |
601 | |
602 /* Line matched in all buffers, remove it from the diff. */ | |
603 for (i_new = i_org; i_new < DB_COUNT; ++i_new) | |
672 | 604 if (tp->tp_diffbuf[i_new] != NULL) |
7 | 605 { |
606 if (dir == FORWARD) | |
607 ++dp->df_lnum[i_new]; | |
608 --dp->df_count[i_new]; | |
609 } | |
610 } | |
611 if (dir == BACKWARD) | |
612 break; | |
613 dir = BACKWARD; | |
614 } | |
615 } | |
616 | |
617 /* | |
618 * Check if a diff block doesn't contain invalid line numbers. | |
619 * This can happen when the diff program returns invalid results. | |
620 */ | |
621 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
622 diff_check_sanity(tabpage_T *tp, diff_T *dp) |
7 | 623 { |
624 int i; | |
625 | |
626 for (i = 0; i < DB_COUNT; ++i) | |
672 | 627 if (tp->tp_diffbuf[i] != NULL) |
7 | 628 if (dp->df_lnum[i] + dp->df_count[i] - 1 |
672 | 629 > tp->tp_diffbuf[i]->b_ml.ml_line_count) |
7 | 630 return FAIL; |
631 return OK; | |
632 } | |
633 | |
634 /* | |
672 | 635 * Mark all diff buffers in the current tab page for redraw. |
7 | 636 */ |
637 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
638 diff_redraw( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
639 int dofold) /* also recompute the folds */ |
7 | 640 { |
641 win_T *wp; | |
642 int n; | |
643 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
644 FOR_ALL_WINDOWS(wp) |
7 | 645 if (wp->w_p_diff) |
646 { | |
738 | 647 redraw_win_later(wp, SOME_VALID); |
7 | 648 #ifdef FEAT_FOLDING |
649 if (dofold && foldmethodIsDiff(wp)) | |
650 foldUpdateAll(wp); | |
651 #endif | |
652 /* A change may have made filler lines invalid, need to take care | |
653 * of that for other windows. */ | |
3904 | 654 n = diff_check(wp, wp->w_topline); |
655 if ((wp != curwin && wp->w_topfill > 0) || n > 0) | |
7 | 656 { |
657 if (wp->w_topfill > n) | |
658 wp->w_topfill = (n < 0 ? 0 : n); | |
3904 | 659 else if (n > 0 && n > wp->w_topfill) |
660 wp->w_topfill = n; | |
5934 | 661 check_topfill(wp, FALSE); |
7 | 662 } |
663 } | |
664 } | |
665 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
666 static void |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
667 clear_diffin(diffin_T *din) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
668 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
669 if (din->din_fname == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
670 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
671 vim_free(din->din_mmfile.ptr); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
672 din->din_mmfile.ptr = NULL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
673 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
674 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
675 mch_remove(din->din_fname); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
676 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
677 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
678 static void |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
679 clear_diffout(diffout_T *dout) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
680 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
681 if (dout->dout_fname == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
682 ga_clear_strings(&dout->dout_ga); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
683 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
684 mch_remove(dout->dout_fname); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
685 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
686 |
7 | 687 /* |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
688 * Write buffer "buf" to a memory buffer. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
689 * Return FAIL for failure. |
7 | 690 */ |
691 static int | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
692 diff_write_buffer(buf_T *buf, diffin_T *din) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
693 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
694 linenr_T lnum; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
695 char_u *s; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
696 long len = 0; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
697 char_u *ptr; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
698 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
699 // xdiff requires one big block of memory with all the text. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
700 for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
701 len += STRLEN(ml_get_buf(buf, lnum, FALSE)) + 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
702 ptr = lalloc(len, TRUE); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
703 if (ptr == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
704 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
705 // Allocating memory failed. This can happen, because we try to read |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
706 // the whole buffer text into memory. Set the failed flag, the diff |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
707 // will be retried with external diff. The flag is never reset. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
708 buf->b_diff_failed = TRUE; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
709 if (p_verbose > 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
710 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
711 verbose_enter(); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
712 smsg((char_u *) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
713 _("Not enough memory to use internal diff for buffer \"%s\""), |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
714 buf->b_fname); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
715 verbose_leave(); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
716 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
717 return FAIL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
718 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
719 din->din_mmfile.ptr = (char *)ptr; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
720 din->din_mmfile.size = len; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
721 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
722 len = 0; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
723 for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
724 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
725 for (s = ml_get_buf(buf, lnum, FALSE); *s != NUL; ) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
726 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
727 if (diff_flags & DIFF_ICASE) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
728 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
729 int c; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
730 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
731 // xdiff doesn't support ignoring case, fold-case the text. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
732 #ifdef FEAT_MBYTE |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
733 int orig_len; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
734 char_u cbuf[MB_MAXBYTES + 1]; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
735 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
736 c = PTR2CHAR(s); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
737 c = enc_utf8 ? utf_fold(c) : MB_TOLOWER(c); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
738 orig_len = MB_PTR2LEN(s); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
739 if (mb_char2bytes(c, cbuf) != orig_len) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
740 // TODO: handle byte length difference |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
741 mch_memmove(ptr + len, s, orig_len); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
742 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
743 mch_memmove(ptr + len, cbuf, orig_len); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
744 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
745 s += orig_len; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
746 len += orig_len; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
747 #else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
748 c = *s++; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
749 ptr[len++] = TOLOWER_LOC(c); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
750 #endif |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
751 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
752 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
753 ptr[len++] = *s++; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
754 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
755 ptr[len++] = NL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
756 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
757 return OK; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
758 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
759 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
760 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
761 * Write buffer "buf" to file or memory buffer. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
762 * Return FAIL for failure. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
763 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
764 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
765 diff_write(buf_T *buf, diffin_T *din) |
7 | 766 { |
767 int r; | |
768 char_u *save_ff; | |
769 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
770 if (din->din_fname == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
771 return diff_write_buffer(buf, din); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
772 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
773 // Always use 'fileformat' set to "unix". |
7 | 774 save_ff = buf->b_p_ff; |
775 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
776 r = buf_write(buf, din->din_fname, NULL, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
777 (linenr_T)1, buf->b_ml.ml_line_count, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
778 NULL, FALSE, FALSE, FALSE, TRUE); |
7 | 779 free_string_option(buf->b_p_ff); |
780 buf->b_p_ff = save_ff; | |
781 return r; | |
782 } | |
783 | |
784 /* | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
785 * Update the diffs for all buffers involved. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
786 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
787 static void |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
788 diff_try_update( |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
789 diffio_T *dio, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
790 int idx_orig, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
791 exarg_T *eap) // "eap" can be NULL |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
792 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
793 buf_T *buf; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
794 int idx_new; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
795 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
796 if (dio->dio_internal) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
797 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
798 ga_init2(&dio->dio_diff.dout_ga, sizeof(char *), 1000); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
799 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
800 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
801 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
802 // We need three temp file names. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
803 dio->dio_orig.din_fname = vim_tempname('o', TRUE); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
804 dio->dio_new.din_fname = vim_tempname('n', TRUE); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
805 dio->dio_diff.dout_fname = vim_tempname('d', TRUE); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
806 if (dio->dio_orig.din_fname == NULL |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
807 || dio->dio_new.din_fname == NULL |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
808 || dio->dio_diff.dout_fname == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
809 goto theend; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
810 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
811 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
812 // Check external diff is actually working. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
813 if (!dio->dio_internal && check_external_diff(dio) == FAIL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
814 goto theend; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
815 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
816 // :diffupdate! |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
817 if (eap != NULL && eap->forceit) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
818 for (idx_new = idx_orig; idx_new < DB_COUNT; ++idx_new) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
819 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
820 buf = curtab->tp_diffbuf[idx_new]; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
821 if (buf_valid(buf)) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
822 buf_check_timestamp(buf, FALSE); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
823 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
824 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
825 // Write the first buffer to a tempfile or mmfile_t. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
826 buf = curtab->tp_diffbuf[idx_orig]; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
827 if (diff_write(buf, &dio->dio_orig) == FAIL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
828 goto theend; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
829 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
830 // Make a difference between the first buffer and every other. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
831 for (idx_new = idx_orig + 1; idx_new < DB_COUNT; ++idx_new) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
832 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
833 buf = curtab->tp_diffbuf[idx_new]; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
834 if (buf == NULL || buf->b_ml.ml_mfp == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
835 continue; // skip buffer that isn't loaded |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
836 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
837 // Write the other buffer and diff with the first one. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
838 if (diff_write(buf, &dio->dio_new) == FAIL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
839 continue; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
840 if (diff_file(dio) == FAIL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
841 continue; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
842 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
843 // Read the diff output and add each entry to the diff list. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
844 diff_read(idx_orig, idx_new, &dio->dio_diff); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
845 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
846 clear_diffin(&dio->dio_new); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
847 clear_diffout(&dio->dio_diff); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
848 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
849 clear_diffin(&dio->dio_orig); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
850 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
851 theend: |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
852 vim_free(dio->dio_orig.din_fname); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
853 vim_free(dio->dio_new.din_fname); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
854 vim_free(dio->dio_diff.dout_fname); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
855 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
856 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
857 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
858 * Return TRUE if the options are set to use the internal diff library. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
859 * Note that if the internal diff failed for one of the buffers, the external |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
860 * diff will be used anyway. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
861 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
862 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
863 diff_internal(void) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
864 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
865 return (diff_flags & DIFF_INTERNAL) != 0 && *p_dex == NUL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
866 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
867 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
868 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
869 * Return TRUE if the internal diff failed for one of the diff buffers. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
870 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
871 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
872 diff_internal_failed(void) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
873 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
874 int idx; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
875 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
876 // Only need to do something when there is another buffer. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
877 for (idx = 0; idx < DB_COUNT; ++idx) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
878 if (curtab->tp_diffbuf[idx] != NULL |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
879 && curtab->tp_diffbuf[idx]->b_diff_failed) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
880 return TRUE; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
881 return FALSE; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
882 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
883 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
884 /* |
7 | 885 * Completely update the diffs for the buffers involved. |
886 * This uses the ordinary "diff" command. | |
887 * The buffers are written to a file, also for unmodified buffers (the file | |
888 * could have been produced by autocommands, e.g. the netrw plugin). | |
889 */ | |
890 void | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
891 ex_diffupdate(exarg_T *eap) // "eap" can be NULL |
7 | 892 { |
893 int idx_orig; | |
894 int idx_new; | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
895 diffio_T diffio; |
7 | 896 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
897 // Delete all diffblocks. |
672 | 898 diff_clear(curtab); |
899 curtab->tp_diff_invalid = FALSE; | |
7 | 900 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
901 // Use the first buffer as the original text. |
7 | 902 for (idx_orig = 0; idx_orig < DB_COUNT; ++idx_orig) |
672 | 903 if (curtab->tp_diffbuf[idx_orig] != NULL) |
7 | 904 break; |
905 if (idx_orig == DB_COUNT) | |
906 return; | |
907 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
908 // Only need to do something when there is another buffer. |
7 | 909 for (idx_new = idx_orig + 1; idx_new < DB_COUNT; ++idx_new) |
672 | 910 if (curtab->tp_diffbuf[idx_new] != NULL) |
7 | 911 break; |
912 if (idx_new == DB_COUNT) | |
913 return; | |
914 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
915 // Only use the internal method if it did not fail for one of the buffers. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
916 vim_memset(&diffio, 0, sizeof(diffio)); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
917 diffio.dio_internal = diff_internal() && !diff_internal_failed(); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
918 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
919 diff_try_update(&diffio, idx_orig, eap); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
920 if (diffio.dio_internal && diff_internal_failed()) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
921 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
922 // Internal diff failed, use external diff instead. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
923 vim_memset(&diffio, 0, sizeof(diffio)); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
924 diff_try_update(&diffio, idx_orig, eap); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
925 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
926 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
927 // force updating cursor position on screen |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
928 curwin->w_valid_cursor.lnum = 0; |
7 | 929 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
930 diff_redraw(TRUE); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
931 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
932 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
933 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
934 * Do a quick test if "diff" really works. Otherwise it looks like there |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
935 * are no differences. Can't use the return value, it's non-zero when |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
936 * there are differences. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
937 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
938 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
939 check_external_diff(diffio_T *diffio) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
940 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
941 FILE *fd; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
942 int ok; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
943 int io_error = FALSE; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
944 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
945 // May try twice, first with "-a" and then without. |
7 | 946 for (;;) |
947 { | |
948 ok = FALSE; | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
949 fd = mch_fopen((char *)diffio->dio_orig.din_fname, "w"); |
1757 | 950 if (fd == NULL) |
951 io_error = TRUE; | |
952 else | |
7 | 953 { |
1757 | 954 if (fwrite("line1\n", (size_t)6, (size_t)1, fd) != 1) |
955 io_error = TRUE; | |
7 | 956 fclose(fd); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
957 fd = mch_fopen((char *)diffio->dio_new.din_fname, "w"); |
1757 | 958 if (fd == NULL) |
959 io_error = TRUE; | |
960 else | |
7 | 961 { |
1757 | 962 if (fwrite("line2\n", (size_t)6, (size_t)1, fd) != 1) |
963 io_error = TRUE; | |
7 | 964 fclose(fd); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
965 fd = NULL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
966 if (diff_file(diffio) == OK) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
967 fd = mch_fopen((char *)diffio->dio_diff.dout_fname, "r"); |
1757 | 968 if (fd == NULL) |
969 io_error = TRUE; | |
970 else | |
7 | 971 { |
972 char_u linebuf[LBUFLEN]; | |
973 | |
974 for (;;) | |
975 { | |
976 /* There must be a line that contains "1c1". */ | |
977 if (tag_fgets(linebuf, LBUFLEN, fd)) | |
978 break; | |
979 if (STRNCMP(linebuf, "1c1", 3) == 0) | |
980 ok = TRUE; | |
981 } | |
982 fclose(fd); | |
983 } | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
984 mch_remove(diffio->dio_diff.dout_fname); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
985 mch_remove(diffio->dio_new.din_fname); |
7 | 986 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
987 mch_remove(diffio->dio_orig.din_fname); |
7 | 988 } |
989 | |
990 #ifdef FEAT_EVAL | |
991 /* When using 'diffexpr' break here. */ | |
992 if (*p_dex != NUL) | |
993 break; | |
994 #endif | |
995 | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
996 #if defined(MSWIN) |
7 | 997 /* If the "-a" argument works, also check if "--binary" works. */ |
998 if (ok && diff_a_works == MAYBE && diff_bin_works == MAYBE) | |
999 { | |
1000 diff_a_works = TRUE; | |
1001 diff_bin_works = TRUE; | |
1002 continue; | |
1003 } | |
1004 if (!ok && diff_a_works == TRUE && diff_bin_works == TRUE) | |
1005 { | |
1006 /* Tried --binary, but it failed. "-a" works though. */ | |
1007 diff_bin_works = FALSE; | |
1008 ok = TRUE; | |
1009 } | |
1010 #endif | |
1011 | |
1012 /* If we checked if "-a" works already, break here. */ | |
1013 if (diff_a_works != MAYBE) | |
1014 break; | |
1015 diff_a_works = ok; | |
1016 | |
1017 /* If "-a" works break here, otherwise retry without "-a". */ | |
1018 if (ok) | |
1019 break; | |
1020 } | |
1021 if (!ok) | |
1022 { | |
1757 | 1023 if (io_error) |
1024 EMSG(_("E810: Cannot read or write temp files")); | |
7 | 1025 EMSG(_("E97: Cannot create diffs")); |
1026 diff_a_works = MAYBE; | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1027 #if defined(MSWIN) |
7 | 1028 diff_bin_works = MAYBE; |
1029 #endif | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1030 return FAIL; |
7 | 1031 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1032 return OK; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1033 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1034 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1035 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1036 * Invoke the xdiff function. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1037 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1038 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1039 diff_file_internal(diffio_T *diffio) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1040 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1041 xpparam_t param; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1042 xdemitconf_t emit_cfg; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1043 xdemitcb_t emit_cb; |
7 | 1044 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1045 vim_memset(¶m, 0, sizeof(param)); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1046 vim_memset(&emit_cfg, 0, sizeof(emit_cfg)); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1047 vim_memset(&emit_cb, 0, sizeof(emit_cb)); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1048 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1049 param.flags = diff_algorithm; |
3524 | 1050 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1051 if (diff_flags & DIFF_IWHITE) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1052 param.flags |= XDF_IGNORE_WHITESPACE_CHANGE; |
7 | 1053 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1054 emit_cfg.ctxlen = 0; // don't need any diff_context here |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1055 emit_cb.priv = &diffio->dio_diff; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1056 emit_cb.outf = xdiff_out; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1057 if (xdl_diff(&diffio->dio_orig.din_mmfile, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1058 &diffio->dio_new.din_mmfile, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1059 ¶m, &emit_cfg, &emit_cb) < 0) |
7 | 1060 { |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1061 EMSG(_("E960: Problem creating the internal diff")); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1062 return FAIL; |
7 | 1063 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1064 return OK; |
7 | 1065 } |
1066 | |
1067 /* | |
1068 * Make a diff between files "tmp_orig" and "tmp_new", results in "tmp_diff". | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1069 * return OK or FAIL; |
7 | 1070 */ |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1071 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1072 diff_file(diffio_T *dio) |
7 | 1073 { |
1074 char_u *cmd; | |
1872 | 1075 size_t len; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1076 char_u *tmp_orig = dio->dio_orig.din_fname; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1077 char_u *tmp_new = dio->dio_new.din_fname; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1078 char_u *tmp_diff = dio->dio_diff.dout_fname; |
7 | 1079 |
1080 #ifdef FEAT_EVAL | |
1081 if (*p_dex != NUL) | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1082 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1083 // Use 'diffexpr' to generate the diff file. |
7 | 1084 eval_diff(tmp_orig, tmp_new, tmp_diff); |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1085 return OK; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1086 } |
7 | 1087 else |
1088 #endif | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1089 // Use xdiff for generating the diff. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1090 if (dio->dio_internal) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1091 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1092 return diff_file_internal(dio); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1093 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1094 else |
7 | 1095 { |
1872 | 1096 len = STRLEN(tmp_orig) + STRLEN(tmp_new) |
1097 + STRLEN(tmp_diff) + STRLEN(p_srr) + 27; | |
1098 cmd = alloc((unsigned)len); | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1099 if (cmd == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1100 return FAIL; |
193 | 1101 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1102 // We don't want $DIFF_OPTIONS to get in the way. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1103 if (getenv("DIFF_OPTIONS")) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1104 vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)""); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1105 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1106 // Build the diff command and execute it. Always use -a, binary |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1107 // differences are of no use. Ignore errors, diff returns |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1108 // non-zero when differences have been found. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1109 vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s %s", |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1110 diff_a_works == FALSE ? "" : "-a ", |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1111 #if defined(MSWIN) |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1112 diff_bin_works == TRUE ? "--binary " : "", |
7 | 1113 #else |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1114 "", |
7 | 1115 #endif |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1116 (diff_flags & DIFF_IWHITE) ? "-b " : "", |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1117 (diff_flags & DIFF_ICASE) ? "-i " : "", |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1118 tmp_orig, tmp_new); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1119 append_redir(cmd, (int)len, p_srr, tmp_diff); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1120 block_autocmds(); // avoid ShellCmdPost stuff |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1121 (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1122 unblock_autocmds(); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1123 vim_free(cmd); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1124 return OK; |
7 | 1125 } |
1126 } | |
1127 | |
1128 /* | |
1129 * Create a new version of a file from the current buffer and a diff file. | |
1130 * The buffer is written to a file, also for unmodified buffers (the file | |
1131 * could have been produced by autocommands, e.g. the netrw plugin). | |
1132 */ | |
1133 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1134 ex_diffpatch(exarg_T *eap) |
7 | 1135 { |
1136 char_u *tmp_orig; /* name of original temp file */ | |
1137 char_u *tmp_new; /* name of patched temp file */ | |
1138 char_u *buf = NULL; | |
1872 | 1139 size_t buflen; |
7 | 1140 win_T *old_curwin = curwin; |
1141 char_u *newname = NULL; /* name of patched file buffer */ | |
1142 #ifdef UNIX | |
1143 char_u dirbuf[MAXPATHL]; | |
1144 char_u *fullname = NULL; | |
1145 #endif | |
1146 #ifdef FEAT_BROWSE | |
1147 char_u *browseFile = NULL; | |
1148 int browse_flag = cmdmod.browse; | |
1149 #endif | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
1150 stat_T st; |
11113
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1151 char_u *esc_name = NULL; |
7 | 1152 |
1153 #ifdef FEAT_BROWSE | |
1154 if (cmdmod.browse) | |
1155 { | |
28 | 1156 browseFile = do_browse(0, (char_u *)_("Patch file"), |
13802
378f9f8e6d8f
patch 8.0.1773: dialog messages are not translated
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1157 eap->arg, NULL, NULL, |
378f9f8e6d8f
patch 8.0.1773: dialog messages are not translated
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1158 (char_u *)_(BROWSE_FILTER_ALL_FILES), NULL); |
7 | 1159 if (browseFile == NULL) |
1160 return; /* operation cancelled */ | |
1161 eap->arg = browseFile; | |
1162 cmdmod.browse = FALSE; /* don't let do_ecmd() browse again */ | |
1163 } | |
1164 #endif | |
1165 | |
1166 /* We need two temp file names. */ | |
6721 | 1167 tmp_orig = vim_tempname('o', FALSE); |
1168 tmp_new = vim_tempname('n', FALSE); | |
7 | 1169 if (tmp_orig == NULL || tmp_new == NULL) |
1170 goto theend; | |
1171 | |
1172 /* Write the current buffer to "tmp_orig". */ | |
1173 if (buf_write(curbuf, tmp_orig, NULL, | |
1174 (linenr_T)1, curbuf->b_ml.ml_line_count, | |
1175 NULL, FALSE, FALSE, FALSE, TRUE) == FAIL) | |
1176 goto theend; | |
1177 | |
1178 #ifdef UNIX | |
1179 /* Get the absolute path of the patchfile, changing directory below. */ | |
1180 fullname = FullName_save(eap->arg, FALSE); | |
1181 #endif | |
11113
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1182 esc_name = vim_strsave_shellescape( |
7 | 1183 # ifdef UNIX |
11113
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1184 fullname != NULL ? fullname : |
7 | 1185 # endif |
11113
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1186 eap->arg, TRUE, TRUE); |
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1187 if (esc_name == NULL) |
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1188 goto theend; |
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1189 buflen = STRLEN(tmp_orig) + STRLEN(esc_name) + STRLEN(tmp_new) + 16; |
1872 | 1190 buf = alloc((unsigned)buflen); |
7 | 1191 if (buf == NULL) |
1192 goto theend; | |
1193 | |
1194 #ifdef UNIX | |
1788 | 1195 /* Temporarily chdir to /tmp, to avoid patching files in the current |
7 | 1196 * directory when the patch file contains more than one patch. When we |
1197 * have our own temp dir use that instead, it will be cleaned up when we | |
1198 * exit (any .rej files created). Don't change directory if we can't | |
1199 * return to the current. */ | |
1200 if (mch_dirname(dirbuf, MAXPATHL) != OK || mch_chdir((char *)dirbuf) != 0) | |
1201 dirbuf[0] = NUL; | |
1202 else | |
1203 { | |
1204 # ifdef TEMPDIRNAMES | |
1205 if (vim_tempdir != NULL) | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14726
diff
changeset
|
1206 vim_ignored = mch_chdir((char *)vim_tempdir); |
7 | 1207 else |
1208 # endif | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14726
diff
changeset
|
1209 vim_ignored = mch_chdir("/tmp"); |
7 | 1210 shorten_fnames(TRUE); |
1211 } | |
1212 #endif | |
1213 | |
1214 #ifdef FEAT_EVAL | |
1215 if (*p_pex != NUL) | |
1216 /* Use 'patchexpr' to generate the new file. */ | |
1217 eval_patch(tmp_orig, | |
1218 # ifdef UNIX | |
1219 fullname != NULL ? fullname : | |
1220 # endif | |
1221 eap->arg, tmp_new); | |
1222 else | |
1223 #endif | |
1224 { | |
1225 /* Build the patch command and execute it. Ignore errors. Switch to | |
1226 * cooked mode to allow the user to respond to prompts. */ | |
11113
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1227 vim_snprintf((char *)buf, buflen, "patch -o %s %s < %s", |
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1228 tmp_new, tmp_orig, esc_name); |
1410 | 1229 block_autocmds(); /* Avoid ShellCmdPost stuff */ |
7 | 1230 (void)call_shell(buf, SHELL_FILTER | SHELL_COOKED); |
1410 | 1231 unblock_autocmds(); |
7 | 1232 } |
1233 | |
1234 #ifdef UNIX | |
1235 if (dirbuf[0] != NUL) | |
1236 { | |
1237 if (mch_chdir((char *)dirbuf) != 0) | |
1238 EMSG(_(e_prev_dir)); | |
1239 shorten_fnames(TRUE); | |
1240 } | |
1241 #endif | |
1242 | |
1243 /* patch probably has written over the screen */ | |
1244 redraw_later(CLEAR); | |
1245 | |
1246 /* Delete any .orig or .rej file created. */ | |
1247 STRCPY(buf, tmp_new); | |
1248 STRCAT(buf, ".orig"); | |
1249 mch_remove(buf); | |
1250 STRCPY(buf, tmp_new); | |
1251 STRCAT(buf, ".rej"); | |
1252 mch_remove(buf); | |
1253 | |
1942 | 1254 /* Only continue if the output file was created. */ |
1255 if (mch_stat((char *)tmp_new, &st) < 0 || st.st_size == 0) | |
1256 EMSG(_("E816: Cannot read patch output")); | |
1257 else | |
7 | 1258 { |
1942 | 1259 if (curbuf->b_fname != NULL) |
1260 { | |
1261 newname = vim_strnsave(curbuf->b_fname, | |
7 | 1262 (int)(STRLEN(curbuf->b_fname) + 4)); |
1942 | 1263 if (newname != NULL) |
1264 STRCAT(newname, ".new"); | |
1265 } | |
7 | 1266 |
1267 #ifdef FEAT_GUI | |
1942 | 1268 need_mouse_correct = TRUE; |
7 | 1269 #endif |
1942 | 1270 /* don't use a new tab page, each tab page has its own diffs */ |
1271 cmdmod.tab = 0; | |
682 | 1272 |
1942 | 1273 if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) |
1274 { | |
1275 /* Pretend it was a ":split fname" command */ | |
1276 eap->cmdidx = CMD_split; | |
1277 eap->arg = tmp_new; | |
1278 do_exedit(eap, old_curwin); | |
7 | 1279 |
1942 | 1280 /* check that split worked and editing tmp_new */ |
1281 if (curwin != old_curwin && win_valid(old_curwin)) | |
1282 { | |
1283 /* Set 'diff', 'scrollbind' on and 'wrap' off. */ | |
1284 diff_win_options(curwin, TRUE); | |
1285 diff_win_options(old_curwin, TRUE); | |
7 | 1286 |
1942 | 1287 if (newname != NULL) |
1288 { | |
1289 /* do a ":file filename.new" on the patched buffer */ | |
1290 eap->arg = newname; | |
1291 ex_file(eap); | |
7 | 1292 |
1942 | 1293 /* Do filetype detection with the new name. */ |
1294 if (au_has_group((char_u *)"filetypedetect")) | |
1295 do_cmdline_cmd((char_u *)":doau filetypedetect BufRead"); | |
1296 } | |
7 | 1297 } |
1298 } | |
1299 } | |
1300 | |
1301 theend: | |
1302 if (tmp_orig != NULL) | |
1303 mch_remove(tmp_orig); | |
1304 vim_free(tmp_orig); | |
1305 if (tmp_new != NULL) | |
1306 mch_remove(tmp_new); | |
1307 vim_free(tmp_new); | |
1308 vim_free(newname); | |
1309 vim_free(buf); | |
1310 #ifdef UNIX | |
1311 vim_free(fullname); | |
1312 #endif | |
11113
081ed9efb5c0
patch 8.0.0444: diffpatch fails when the file name has a quote
Christian Brabandt <cb@256bit.org>
parents:
11109
diff
changeset
|
1313 vim_free(esc_name); |
7 | 1314 #ifdef FEAT_BROWSE |
1315 vim_free(browseFile); | |
1316 cmdmod.browse = browse_flag; | |
1317 #endif | |
1318 } | |
1319 | |
1320 /* | |
1321 * Split the window and edit another file, setting options to show the diffs. | |
1322 */ | |
1323 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1324 ex_diffsplit(exarg_T *eap) |
7 | 1325 { |
1326 win_T *old_curwin = curwin; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1327 bufref_T old_curbuf; |
7 | 1328 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1329 set_bufref(&old_curbuf, curbuf); |
7 | 1330 #ifdef FEAT_GUI |
1331 need_mouse_correct = TRUE; | |
1332 #endif | |
10013
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1333 /* Need to compute w_fraction when no redraw happened yet. */ |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1334 validate_cursor(); |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1335 set_fraction(curwin); |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1336 |
682 | 1337 /* don't use a new tab page, each tab page has its own diffs */ |
1338 cmdmod.tab = 0; | |
1339 | |
764 | 1340 if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) |
7 | 1341 { |
1342 /* Pretend it was a ":split fname" command */ | |
1343 eap->cmdidx = CMD_split; | |
449 | 1344 curwin->w_p_diff = TRUE; |
7 | 1345 do_exedit(eap, old_curwin); |
1346 | |
1347 if (curwin != old_curwin) /* split must have worked */ | |
1348 { | |
1349 /* Set 'diff', 'scrollbind' on and 'wrap' off. */ | |
1350 diff_win_options(curwin, TRUE); | |
7338
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1351 if (win_valid(old_curwin)) |
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1352 { |
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1353 diff_win_options(old_curwin, TRUE); |
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1354 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1355 if (bufref_valid(&old_curbuf)) |
7338
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1356 /* Move the cursor position to that of the old window. */ |
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1357 curwin->w_cursor.lnum = diff_get_corresponding_line( |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1358 old_curbuf.br_buf, old_curwin->w_cursor.lnum); |
7338
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1359 } |
10013
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1360 /* Now that lines are folded scroll to show the cursor at the same |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1361 * relative position. */ |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1362 scroll_to_fraction(curwin, curwin->w_height); |
7 | 1363 } |
1364 } | |
1365 } | |
1366 | |
1367 /* | |
4352 | 1368 * Set options to show diffs for the current window. |
7 | 1369 */ |
1370 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1371 ex_diffthis(exarg_T *eap UNUSED) |
7 | 1372 { |
1373 /* Set 'diff', 'scrollbind' on and 'wrap' off. */ | |
1374 diff_win_options(curwin, TRUE); | |
1375 } | |
1376 | |
11707
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1377 static void |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1378 set_diff_option(win_T *wp, int value) |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1379 { |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1380 win_T *old_curwin = curwin; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1381 |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1382 curwin = wp; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1383 curbuf = curwin->w_buffer; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1384 ++curbuf_lock; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1385 set_option_value((char_u *)"diff", (long)value, NULL, OPT_LOCAL); |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1386 --curbuf_lock; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1387 curwin = old_curwin; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1388 curbuf = curwin->w_buffer; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1389 } |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1390 |
7 | 1391 /* |
1392 * Set options in window "wp" for diff mode. | |
1393 */ | |
1394 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1395 diff_win_options( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1396 win_T *wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1397 int addbuf) /* Add buffer to diff. */ |
7 | 1398 { |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1399 # ifdef FEAT_FOLDING |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1400 win_T *old_curwin = curwin; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1401 |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1402 /* close the manually opened folds */ |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1403 curwin = wp; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1404 newFoldLevel(); |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1405 curwin = old_curwin; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1406 # endif |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1407 |
2583 | 1408 /* Use 'scrollbind' and 'cursorbind' when available */ |
6897 | 1409 if (!wp->w_p_diff) |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1410 wp->w_p_scb_save = wp->w_p_scb; |
2583 | 1411 wp->w_p_scb = TRUE; |
6897 | 1412 if (!wp->w_p_diff) |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1413 wp->w_p_crb_save = wp->w_p_crb; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
1414 wp->w_p_crb = TRUE; |
6897 | 1415 if (!wp->w_p_diff) |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1416 wp->w_p_wrap_save = wp->w_p_wrap; |
7 | 1417 wp->w_p_wrap = FALSE; |
1418 # ifdef FEAT_FOLDING | |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1419 curwin = wp; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1420 curbuf = curwin->w_buffer; |
6897 | 1421 if (!wp->w_p_diff) |
1422 { | |
1423 if (wp->w_p_diff_saved) | |
1424 free_string_option(wp->w_p_fdm_save); | |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1425 wp->w_p_fdm_save = vim_strsave(wp->w_p_fdm); |
6897 | 1426 } |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1427 set_string_option_direct((char_u *)"fdm", -1, (char_u *)"diff", |
694 | 1428 OPT_LOCAL|OPT_FREE, 0); |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1429 curwin = old_curwin; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1430 curbuf = curwin->w_buffer; |
6897 | 1431 if (!wp->w_p_diff) |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1432 { |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1433 wp->w_p_fdc_save = wp->w_p_fdc; |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1434 wp->w_p_fen_save = wp->w_p_fen; |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1435 wp->w_p_fdl_save = wp->w_p_fdl; |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1436 } |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1437 wp->w_p_fdc = diff_foldcolumn; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1438 wp->w_p_fen = TRUE; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1439 wp->w_p_fdl = 0; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1440 foldUpdateAll(wp); |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1441 /* make sure topline is not halfway a fold */ |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1442 changed_window_setting_win(wp); |
7 | 1443 # endif |
1444 if (vim_strchr(p_sbo, 'h') == NULL) | |
1445 do_cmdline_cmd((char_u *)"set sbo+=hor"); | |
11707
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1446 /* Save the current values, to be restored in ex_diffoff(). */ |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1447 wp->w_p_diff_saved = TRUE; |
7 | 1448 |
11707
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1449 set_diff_option(wp, TRUE); |
6897 | 1450 |
7 | 1451 if (addbuf) |
1452 diff_buf_add(wp->w_buffer); | |
1453 redraw_win_later(wp, NOT_VALID); | |
1454 } | |
1455 | |
1456 /* | |
16 | 1457 * Set options not to show diffs. For the current window or all windows. |
671 | 1458 * Only in the current tab page. |
16 | 1459 */ |
1460 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1461 ex_diffoff(exarg_T *eap) |
16 | 1462 { |
1463 win_T *wp; | |
1464 int diffwin = FALSE; | |
1465 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1466 FOR_ALL_WINDOWS(wp) |
16 | 1467 { |
5358 | 1468 if (eap->forceit ? wp->w_p_diff : wp == curwin) |
16 | 1469 { |
6897 | 1470 /* Set 'diff' off. If option values were saved in |
1471 * diff_win_options(), restore the ones whose settings seem to have | |
1472 * been left over from diff mode. */ | |
11707
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1473 set_diff_option(wp, FALSE); |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1474 |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1475 if (wp->w_p_diff_saved) |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1476 { |
6897 | 1477 |
1478 if (wp->w_p_scb) | |
1479 wp->w_p_scb = wp->w_p_scb_save; | |
1480 if (wp->w_p_crb) | |
1481 wp->w_p_crb = wp->w_p_crb_save; | |
1482 if (!wp->w_p_wrap) | |
1483 wp->w_p_wrap = wp->w_p_wrap_save; | |
1484 #ifdef FEAT_FOLDING | |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1485 free_string_option(wp->w_p_fdm); |
11430
eba1a8c6e21d
patch 8.0.0599: diff mode is insufficiently tested
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1486 wp->w_p_fdm = vim_strsave( |
eba1a8c6e21d
patch 8.0.0599: diff mode is insufficiently tested
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1487 *wp->w_p_fdm_save ? wp->w_p_fdm_save : (char_u*)"manual"); |
5200
b3ff17862b4c
updated for version 7.4a.026
Bram Moolenaar <bram@vim.org>
parents:
5102
diff
changeset
|
1488 |
6897 | 1489 if (wp->w_p_fdc == diff_foldcolumn) |
1490 wp->w_p_fdc = wp->w_p_fdc_save; | |
1491 if (wp->w_p_fdl == 0) | |
1492 wp->w_p_fdl = wp->w_p_fdl_save; | |
1493 | |
5200
b3ff17862b4c
updated for version 7.4a.026
Bram Moolenaar <bram@vim.org>
parents:
5102
diff
changeset
|
1494 /* Only restore 'foldenable' when 'foldmethod' is not |
b3ff17862b4c
updated for version 7.4a.026
Bram Moolenaar <bram@vim.org>
parents:
5102
diff
changeset
|
1495 * "manual", otherwise we continue to show the diff folds. */ |
6897 | 1496 if (wp->w_p_fen) |
1497 wp->w_p_fen = foldmethodIsManual(wp) ? FALSE | |
1498 : wp->w_p_fen_save; | |
1499 | |
1500 foldUpdateAll(wp); | |
1501 #endif | |
5200
b3ff17862b4c
updated for version 7.4a.026
Bram Moolenaar <bram@vim.org>
parents:
5102
diff
changeset
|
1502 } |
10005
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1503 /* remove filler lines */ |
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1504 wp->w_topfill = 0; |
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1505 |
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1506 /* make sure topline is not halfway a fold and cursor is |
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1507 * invalidated */ |
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1508 changed_window_setting_win(wp); |
5200
b3ff17862b4c
updated for version 7.4a.026
Bram Moolenaar <bram@vim.org>
parents:
5102
diff
changeset
|
1509 |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1510 /* Note: 'sbo' is not restored, it's a global option. */ |
16 | 1511 diff_buf_adjust(wp); |
1512 } | |
1513 diffwin |= wp->w_p_diff; | |
1514 } | |
1515 | |
10821
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
1516 /* Also remove hidden buffers from the list. */ |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
1517 if (eap->forceit) |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
1518 diff_buf_clear(); |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
1519 |
16 | 1520 /* Remove "hor" from from 'scrollopt' if there are no diff windows left. */ |
1521 if (!diffwin && vim_strchr(p_sbo, 'h') != NULL) | |
1522 do_cmdline_cmd((char_u *)"set sbo-=hor"); | |
1523 } | |
1524 | |
1525 /* | |
7 | 1526 * Read the diff output and add each entry to the diff list. |
1527 */ | |
1528 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1529 diff_read( |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1530 int idx_orig, // idx of original file |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1531 int idx_new, // idx of new file |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1532 diffout_T *dout) // diff output |
7 | 1533 { |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1534 FILE *fd = NULL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1535 int line_idx = 0; |
7 | 1536 diff_T *dprev = NULL; |
672 | 1537 diff_T *dp = curtab->tp_first_diff; |
7 | 1538 diff_T *dn, *dpl; |
1539 char_u linebuf[LBUFLEN]; /* only need to hold the diff line */ | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1540 char_u *line; |
7 | 1541 long off; |
1542 int i; | |
1543 linenr_T lnum_orig, lnum_new; | |
1544 long count_orig, count_new; | |
1545 int notset = TRUE; /* block "*dp" not set yet */ | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1546 enum { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1547 DIFF_ED, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1548 DIFF_UNIFIED, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1549 DIFF_NONE |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1550 } diffstyle = DIFF_NONE; |
7 | 1551 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1552 if (dout->dout_fname == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1553 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1554 diffstyle = DIFF_UNIFIED; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1555 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1556 else |
7 | 1557 { |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1558 fd = mch_fopen((char *)dout->dout_fname, "r"); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1559 if (fd == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1560 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1561 EMSG(_("E98: Cannot read diff output")); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1562 return; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1563 } |
7 | 1564 } |
1565 | |
1566 for (;;) | |
1567 { | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1568 if (fd == NULL) |
7 | 1569 { |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1570 if (line_idx >= dout->dout_ga.ga_len) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1571 break; // did last line |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1572 line = ((char_u **)dout->dout_ga.ga_data)[line_idx++]; |
7 | 1573 } |
1574 else | |
1575 { | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1576 if (tag_fgets(linebuf, LBUFLEN, fd)) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1577 break; // end of file |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1578 line = linebuf; |
7 | 1579 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1580 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1581 if (diffstyle == DIFF_NONE) |
7 | 1582 { |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1583 // Determine diff style. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1584 // ed like diff looks like this: |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1585 // {first}[,{last}]c{first}[,{last}] |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1586 // {first}a{first}[,{last}] |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1587 // {first}[,{last}]d{first} |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1588 // |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1589 // unified diff looks like this: |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1590 // --- file1 2018-03-20 13:23:35.783153140 +0100 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1591 // +++ file2 2018-03-20 13:23:41.183156066 +0100 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1592 // @@ -1,3 +1,5 @@ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1593 if (isdigit(*line)) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1594 diffstyle = DIFF_ED; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1595 else if ((STRNCMP(line, "@@ ", 3) == 0)) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1596 diffstyle = DIFF_UNIFIED; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1597 else if ((STRNCMP(line, "--- ", 4) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1598 && (tag_fgets(linebuf, LBUFLEN, fd) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1599 && (STRNCMP(line, "+++ ", 4) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1600 && (tag_fgets(linebuf, LBUFLEN, fd) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1601 && (STRNCMP(line, "@@ ", 3) == 0)) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1602 diffstyle = DIFF_UNIFIED; |
14726
655f00c29c58
patch 8.1.0375: cannot use diff mode with Cygwin diff.exe
Christian Brabandt <cb@256bit.org>
parents:
14716
diff
changeset
|
1603 else |
655f00c29c58
patch 8.1.0375: cannot use diff mode with Cygwin diff.exe
Christian Brabandt <cb@256bit.org>
parents:
14716
diff
changeset
|
1604 // Format not recognized yet, skip over this line. Cygwin diff |
655f00c29c58
patch 8.1.0375: cannot use diff mode with Cygwin diff.exe
Christian Brabandt <cb@256bit.org>
parents:
14716
diff
changeset
|
1605 // may put a warning at the start of the file. |
655f00c29c58
patch 8.1.0375: cannot use diff mode with Cygwin diff.exe
Christian Brabandt <cb@256bit.org>
parents:
14716
diff
changeset
|
1606 continue; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1607 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1608 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1609 if (diffstyle == DIFF_ED) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1610 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1611 if (!isdigit(*line)) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1612 continue; // not the start of a diff block |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1613 if (parse_diff_ed(line, &lnum_orig, &count_orig, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1614 &lnum_new, &count_new) == FAIL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1615 continue; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1616 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1617 else if (diffstyle == DIFF_UNIFIED) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1618 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1619 if (STRNCMP(line, "@@ ", 3) != 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1620 continue; // not the start of a diff block |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1621 if (parse_diff_unified(line, &lnum_orig, &count_orig, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1622 &lnum_new, &count_new) == FAIL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1623 continue; |
7 | 1624 } |
1625 else | |
1626 { | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1627 EMSG(_("E959: Invalid diff format.")); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1628 break; |
7 | 1629 } |
1630 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1631 // Go over blocks before the change, for which orig and new are equal. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1632 // Copy blocks from orig to new. |
7 | 1633 while (dp != NULL |
1634 && lnum_orig > dp->df_lnum[idx_orig] + dp->df_count[idx_orig]) | |
1635 { | |
1636 if (notset) | |
1637 diff_copy_entry(dprev, dp, idx_orig, idx_new); | |
1638 dprev = dp; | |
1639 dp = dp->df_next; | |
1640 notset = TRUE; | |
1641 } | |
1642 | |
1643 if (dp != NULL | |
1644 && lnum_orig <= dp->df_lnum[idx_orig] + dp->df_count[idx_orig] | |
1645 && lnum_orig + count_orig >= dp->df_lnum[idx_orig]) | |
1646 { | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1647 // New block overlaps with existing block(s). |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1648 // First find last block that overlaps. |
7 | 1649 for (dpl = dp; dpl->df_next != NULL; dpl = dpl->df_next) |
1650 if (lnum_orig + count_orig < dpl->df_next->df_lnum[idx_orig]) | |
1651 break; | |
1652 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1653 // If the newly found block starts before the old one, set the |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1654 // start back a number of lines. |
7 | 1655 off = dp->df_lnum[idx_orig] - lnum_orig; |
1656 if (off > 0) | |
1657 { | |
1658 for (i = idx_orig; i < idx_new; ++i) | |
672 | 1659 if (curtab->tp_diffbuf[i] != NULL) |
7 | 1660 dp->df_lnum[i] -= off; |
1661 dp->df_lnum[idx_new] = lnum_new; | |
1662 dp->df_count[idx_new] = count_new; | |
1663 } | |
1664 else if (notset) | |
1665 { | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1666 // new block inside existing one, adjust new block |
7 | 1667 dp->df_lnum[idx_new] = lnum_new + off; |
1668 dp->df_count[idx_new] = count_new - off; | |
1669 } | |
1670 else | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1671 // second overlap of new block with existing block |
1519 | 1672 dp->df_count[idx_new] += count_new - count_orig |
1673 + dpl->df_lnum[idx_orig] + dpl->df_count[idx_orig] | |
1674 - (dp->df_lnum[idx_orig] + dp->df_count[idx_orig]); | |
7 | 1675 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1676 // Adjust the size of the block to include all the lines to the |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1677 // end of the existing block or the new diff, whatever ends last. |
7 | 1678 off = (lnum_orig + count_orig) |
1679 - (dpl->df_lnum[idx_orig] + dpl->df_count[idx_orig]); | |
1680 if (off < 0) | |
1681 { | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1682 // new change ends in existing block, adjust the end if not |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1683 // done already |
7 | 1684 if (notset) |
1685 dp->df_count[idx_new] += -off; | |
1686 off = 0; | |
1687 } | |
1428 | 1688 for (i = idx_orig; i < idx_new; ++i) |
672 | 1689 if (curtab->tp_diffbuf[i] != NULL) |
7 | 1690 dp->df_count[i] = dpl->df_lnum[i] + dpl->df_count[i] |
1691 - dp->df_lnum[i] + off; | |
1692 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1693 // Delete the diff blocks that have been merged into one. |
7 | 1694 dn = dp->df_next; |
1695 dp->df_next = dpl->df_next; | |
1696 while (dn != dp->df_next) | |
1697 { | |
1698 dpl = dn->df_next; | |
1699 vim_free(dn); | |
1700 dn = dpl; | |
1701 } | |
1702 } | |
1703 else | |
1704 { | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1705 // Allocate a new diffblock. |
672 | 1706 dp = diff_alloc_new(curtab, dprev, dp); |
7 | 1707 if (dp == NULL) |
840 | 1708 goto done; |
7 | 1709 |
1710 dp->df_lnum[idx_orig] = lnum_orig; | |
1711 dp->df_count[idx_orig] = count_orig; | |
1712 dp->df_lnum[idx_new] = lnum_new; | |
1713 dp->df_count[idx_new] = count_new; | |
1714 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1715 // Set values for other buffers, these must be equal to the |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1716 // original buffer, otherwise there would have been a change |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1717 // already. |
7 | 1718 for (i = idx_orig + 1; i < idx_new; ++i) |
672 | 1719 if (curtab->tp_diffbuf[i] != NULL) |
7 | 1720 diff_copy_entry(dprev, dp, idx_orig, i); |
1721 } | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1722 notset = FALSE; // "*dp" has been set |
7 | 1723 } |
1724 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1725 // for remaining diff blocks orig and new are equal |
7 | 1726 while (dp != NULL) |
1727 { | |
1728 if (notset) | |
1729 diff_copy_entry(dprev, dp, idx_orig, idx_new); | |
1730 dprev = dp; | |
1731 dp = dp->df_next; | |
1732 notset = TRUE; | |
1733 } | |
1734 | |
840 | 1735 done: |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1736 if (fd != NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1737 fclose(fd); |
7 | 1738 } |
1739 | |
1740 /* | |
1741 * Copy an entry at "dp" from "idx_orig" to "idx_new". | |
1742 */ | |
1743 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1744 diff_copy_entry( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1745 diff_T *dprev, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1746 diff_T *dp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1747 int idx_orig, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1748 int idx_new) |
7 | 1749 { |
1750 long off; | |
1751 | |
1752 if (dprev == NULL) | |
1753 off = 0; | |
1754 else | |
1755 off = (dprev->df_lnum[idx_orig] + dprev->df_count[idx_orig]) | |
1756 - (dprev->df_lnum[idx_new] + dprev->df_count[idx_new]); | |
1757 dp->df_lnum[idx_new] = dp->df_lnum[idx_orig] - off; | |
1758 dp->df_count[idx_new] = dp->df_count[idx_orig]; | |
1759 } | |
1760 | |
1761 /* | |
672 | 1762 * Clear the list of diffblocks for tab page "tp". |
7 | 1763 */ |
358 | 1764 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1765 diff_clear(tabpage_T *tp) |
7 | 1766 { |
1767 diff_T *p, *next_p; | |
1768 | |
672 | 1769 for (p = tp->tp_first_diff; p != NULL; p = next_p) |
7 | 1770 { |
1771 next_p = p->df_next; | |
1772 vim_free(p); | |
1773 } | |
672 | 1774 tp->tp_first_diff = NULL; |
7 | 1775 } |
1776 | |
1777 /* | |
1778 * Check diff status for line "lnum" in buffer "buf": | |
1779 * Returns 0 for nothing special | |
1780 * Returns -1 for a line that should be highlighted as changed. | |
1781 * Returns -2 for a line that should be highlighted as added/deleted. | |
1782 * Returns > 0 for inserting that many filler lines above it (never happens | |
1783 * when 'diffopt' doesn't contain "filler"). | |
1784 * This should only be used for windows where 'diff' is set. | |
1785 */ | |
1786 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1787 diff_check(win_T *wp, linenr_T lnum) |
7 | 1788 { |
672 | 1789 int idx; /* index in tp_diffbuf[] for this buffer */ |
7 | 1790 diff_T *dp; |
1791 int maxcount; | |
1792 int i; | |
1793 buf_T *buf = wp->w_buffer; | |
1794 int cmp; | |
1795 | |
672 | 1796 if (curtab->tp_diff_invalid) |
7 | 1797 ex_diffupdate(NULL); /* update after a big change */ |
1798 | |
672 | 1799 if (curtab->tp_first_diff == NULL || !wp->w_p_diff) /* no diffs at all */ |
7 | 1800 return 0; |
1801 | |
1802 /* safety check: "lnum" must be a buffer line */ | |
1803 if (lnum < 1 || lnum > buf->b_ml.ml_line_count + 1) | |
1804 return 0; | |
1805 | |
1806 idx = diff_buf_idx(buf); | |
1807 if (idx == DB_COUNT) | |
1808 return 0; /* no diffs for buffer "buf" */ | |
1809 | |
1810 #ifdef FEAT_FOLDING | |
1811 /* A closed fold never has filler lines. */ | |
1812 if (hasFoldingWin(wp, lnum, NULL, NULL, TRUE, NULL)) | |
1813 return 0; | |
1814 #endif | |
1815 | |
1816 /* search for a change that includes "lnum" in the list of diffblocks. */ | |
672 | 1817 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
7 | 1818 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
1819 break; | |
1820 if (dp == NULL || lnum < dp->df_lnum[idx]) | |
1821 return 0; | |
1822 | |
1823 if (lnum < dp->df_lnum[idx] + dp->df_count[idx]) | |
1824 { | |
1825 int zero = FALSE; | |
1826 | |
1827 /* Changed or inserted line. If the other buffers have a count of | |
1828 * zero, the lines were inserted. If the other buffers have the same | |
1829 * count, check if the lines are identical. */ | |
1830 cmp = FALSE; | |
1831 for (i = 0; i < DB_COUNT; ++i) | |
672 | 1832 if (i != idx && curtab->tp_diffbuf[i] != NULL) |
7 | 1833 { |
1834 if (dp->df_count[i] == 0) | |
1835 zero = TRUE; | |
1836 else | |
1837 { | |
1838 if (dp->df_count[i] != dp->df_count[idx]) | |
1839 return -1; /* nr of lines changed. */ | |
1840 cmp = TRUE; | |
1841 } | |
1842 } | |
1843 if (cmp) | |
1844 { | |
1845 /* Compare all lines. If they are equal the lines were inserted | |
1846 * in some buffers, deleted in others, but not changed. */ | |
1847 for (i = 0; i < DB_COUNT; ++i) | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1848 if (i != idx && curtab->tp_diffbuf[i] != NULL |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1849 && dp->df_count[i] != 0) |
7 | 1850 if (!diff_equal_entry(dp, idx, i)) |
1851 return -1; | |
1852 } | |
1853 /* If there is no buffer with zero lines then there is no difference | |
1854 * any longer. Happens when making a change (or undo) that removes | |
1855 * the difference. Can't remove the entry here, we might be halfway | |
1856 * updating the window. Just report the text as unchanged. Other | |
1857 * windows might still show the change though. */ | |
1858 if (zero == FALSE) | |
1859 return 0; | |
1860 return -2; | |
1861 } | |
1862 | |
1863 /* If 'diffopt' doesn't contain "filler", return 0. */ | |
1864 if (!(diff_flags & DIFF_FILLER)) | |
1865 return 0; | |
1866 | |
1867 /* Insert filler lines above the line just below the change. Will return | |
1868 * 0 when this buf had the max count. */ | |
1869 maxcount = 0; | |
1870 for (i = 0; i < DB_COUNT; ++i) | |
672 | 1871 if (curtab->tp_diffbuf[i] != NULL && dp->df_count[i] > maxcount) |
7 | 1872 maxcount = dp->df_count[i]; |
1873 return maxcount - dp->df_count[idx]; | |
1874 } | |
1875 | |
1876 /* | |
1877 * Compare two entries in diff "*dp" and return TRUE if they are equal. | |
1878 */ | |
1879 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1880 diff_equal_entry(diff_T *dp, int idx1, int idx2) |
7 | 1881 { |
1882 int i; | |
1883 char_u *line; | |
1884 int cmp; | |
1885 | |
1886 if (dp->df_count[idx1] != dp->df_count[idx2]) | |
1887 return FALSE; | |
672 | 1888 if (diff_check_sanity(curtab, dp) == FAIL) |
7 | 1889 return FALSE; |
1890 for (i = 0; i < dp->df_count[idx1]; ++i) | |
1891 { | |
672 | 1892 line = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1], |
7 | 1893 dp->df_lnum[idx1] + i, FALSE)); |
1894 if (line == NULL) | |
1895 return FALSE; | |
672 | 1896 cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2], |
7 | 1897 dp->df_lnum[idx2] + i, FALSE)); |
1898 vim_free(line); | |
1899 if (cmp != 0) | |
1900 return FALSE; | |
1901 } | |
1902 return TRUE; | |
1903 } | |
1904 | |
1905 /* | |
12333
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1906 * Compare the characters at "p1" and "p2". If they are equal (possibly |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1907 * ignoring case) return TRUE and set "len" to the number of bytes. |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1908 */ |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1909 static int |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1910 diff_equal_char(char_u *p1, char_u *p2, int *len) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1911 { |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1912 #ifdef FEAT_MBYTE |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1913 int l = (*mb_ptr2len)(p1); |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1914 |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1915 if (l != (*mb_ptr2len)(p2)) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1916 return FALSE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1917 if (l > 1) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1918 { |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1919 if (STRNCMP(p1, p2, l) != 0 |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1920 && (!enc_utf8 |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1921 || !(diff_flags & DIFF_ICASE) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1922 || utf_fold(utf_ptr2char(p1)) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1923 != utf_fold(utf_ptr2char(p2)))) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1924 return FALSE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1925 *len = l; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1926 } |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1927 else |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1928 #endif |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1929 { |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1930 if ((*p1 != *p2) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1931 && (!(diff_flags & DIFF_ICASE) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1932 || TOLOWER_LOC(*p1) != TOLOWER_LOC(*p2))) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1933 return FALSE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1934 *len = 1; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1935 } |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1936 return TRUE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1937 } |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1938 |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1939 /* |
7 | 1940 * Compare strings "s1" and "s2" according to 'diffopt'. |
1941 * Return non-zero when they are different. | |
1942 */ | |
1943 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1944 diff_cmp(char_u *s1, char_u *s2) |
7 | 1945 { |
1946 char_u *p1, *p2; | |
1947 int l; | |
1948 | |
1949 if ((diff_flags & (DIFF_ICASE | DIFF_IWHITE)) == 0) | |
1950 return STRCMP(s1, s2); | |
1951 if ((diff_flags & DIFF_ICASE) && !(diff_flags & DIFF_IWHITE)) | |
1952 return MB_STRICMP(s1, s2); | |
1953 | |
1954 /* Ignore white space changes and possibly ignore case. */ | |
1955 p1 = s1; | |
1956 p2 = s2; | |
1957 while (*p1 != NUL && *p2 != NUL) | |
1958 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
1959 if (VIM_ISWHITE(*p1) && VIM_ISWHITE(*p2)) |
7 | 1960 { |
1961 p1 = skipwhite(p1); | |
1962 p2 = skipwhite(p2); | |
1963 } | |
1964 else | |
1965 { | |
12333
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1966 if (!diff_equal_char(p1, p2, &l)) |
7 | 1967 break; |
12333
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1968 p1 += l; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1969 p2 += l; |
7 | 1970 } |
1971 } | |
1972 | |
1973 /* Ignore trailing white space. */ | |
1974 p1 = skipwhite(p1); | |
1975 p2 = skipwhite(p2); | |
1976 if (*p1 != NUL || *p2 != NUL) | |
1977 return 1; | |
1978 return 0; | |
1979 } | |
1980 | |
1981 /* | |
1982 * Return the number of filler lines above "lnum". | |
1983 */ | |
1984 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1985 diff_check_fill(win_T *wp, linenr_T lnum) |
7 | 1986 { |
1987 int n; | |
1988 | |
1989 /* be quick when there are no filler lines */ | |
1990 if (!(diff_flags & DIFF_FILLER)) | |
1991 return 0; | |
1992 n = diff_check(wp, lnum); | |
1993 if (n <= 0) | |
1994 return 0; | |
1995 return n; | |
1996 } | |
1997 | |
1998 /* | |
1999 * Set the topline of "towin" to match the position in "fromwin", so that they | |
2000 * show the same diff'ed lines. | |
2001 */ | |
2002 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2003 diff_set_topline(win_T *fromwin, win_T *towin) |
7 | 2004 { |
1519 | 2005 buf_T *frombuf = fromwin->w_buffer; |
7 | 2006 linenr_T lnum = fromwin->w_topline; |
1519 | 2007 int fromidx; |
2008 int toidx; | |
7 | 2009 diff_T *dp; |
1519 | 2010 int max_count; |
7 | 2011 int i; |
2012 | |
1519 | 2013 fromidx = diff_buf_idx(frombuf); |
2014 if (fromidx == DB_COUNT) | |
7 | 2015 return; /* safety check */ |
2016 | |
672 | 2017 if (curtab->tp_diff_invalid) |
7 | 2018 ex_diffupdate(NULL); /* update after a big change */ |
2019 | |
2020 towin->w_topfill = 0; | |
2021 | |
2022 /* search for a change that includes "lnum" in the list of diffblocks. */ | |
672 | 2023 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
1519 | 2024 if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx]) |
7 | 2025 break; |
2026 if (dp == NULL) | |
2027 { | |
2028 /* After last change, compute topline relative to end of file; no | |
2029 * filler lines. */ | |
2030 towin->w_topline = towin->w_buffer->b_ml.ml_line_count | |
1519 | 2031 - (frombuf->b_ml.ml_line_count - lnum); |
7 | 2032 } |
2033 else | |
2034 { | |
2035 /* Find index for "towin". */ | |
1519 | 2036 toidx = diff_buf_idx(towin->w_buffer); |
2037 if (toidx == DB_COUNT) | |
7 | 2038 return; /* safety check */ |
2039 | |
1519 | 2040 towin->w_topline = lnum + (dp->df_lnum[toidx] - dp->df_lnum[fromidx]); |
2041 if (lnum >= dp->df_lnum[fromidx]) | |
7 | 2042 { |
1519 | 2043 /* Inside a change: compute filler lines. With three or more |
2044 * buffers we need to know the largest count. */ | |
2045 max_count = 0; | |
2046 for (i = 0; i < DB_COUNT; ++i) | |
2047 if (curtab->tp_diffbuf[i] != NULL | |
2048 && max_count < dp->df_count[i]) | |
2049 max_count = dp->df_count[i]; | |
2050 | |
2051 if (dp->df_count[toidx] == dp->df_count[fromidx]) | |
2052 { | |
2053 /* same number of lines: use same filler count */ | |
7 | 2054 towin->w_topfill = fromwin->w_topfill; |
1519 | 2055 } |
2056 else if (dp->df_count[toidx] > dp->df_count[fromidx]) | |
7 | 2057 { |
1519 | 2058 if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) |
2059 { | |
2060 /* more lines in towin and fromwin doesn't show diff | |
2061 * lines, only filler lines */ | |
2062 if (max_count - fromwin->w_topfill >= dp->df_count[toidx]) | |
2063 { | |
2064 /* towin also only shows filler lines */ | |
2065 towin->w_topline = dp->df_lnum[toidx] | |
2066 + dp->df_count[toidx]; | |
2067 towin->w_topfill = fromwin->w_topfill; | |
2068 } | |
2069 else | |
2070 /* towin still has some diff lines to show */ | |
2071 towin->w_topline = dp->df_lnum[toidx] | |
2072 + max_count - fromwin->w_topfill; | |
2073 } | |
7 | 2074 } |
1519 | 2075 else if (towin->w_topline >= dp->df_lnum[toidx] |
2076 + dp->df_count[toidx]) | |
7 | 2077 { |
1519 | 2078 /* less lines in towin and no diff lines to show: compute |
2079 * filler lines */ | |
2080 towin->w_topline = dp->df_lnum[toidx] + dp->df_count[toidx]; | |
2081 if (diff_flags & DIFF_FILLER) | |
7 | 2082 { |
1519 | 2083 if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) |
2084 /* fromwin is also out of diff lines */ | |
2085 towin->w_topfill = fromwin->w_topfill; | |
2086 else | |
2087 /* fromwin has some diff lines */ | |
2088 towin->w_topfill = dp->df_lnum[fromidx] | |
2089 + max_count - lnum; | |
7 | 2090 } |
2091 } | |
2092 } | |
2093 } | |
2094 | |
2095 /* safety check (if diff info gets outdated strange things may happen) */ | |
2096 towin->w_botfill = FALSE; | |
2097 if (towin->w_topline > towin->w_buffer->b_ml.ml_line_count) | |
2098 { | |
2099 towin->w_topline = towin->w_buffer->b_ml.ml_line_count; | |
2100 towin->w_botfill = TRUE; | |
2101 } | |
2102 if (towin->w_topline < 1) | |
2103 { | |
2104 towin->w_topline = 1; | |
2105 towin->w_topfill = 0; | |
2106 } | |
2107 | |
2108 /* When w_topline changes need to recompute w_botline and cursor position */ | |
2109 invalidate_botline_win(towin); | |
2110 changed_line_abv_curs_win(towin); | |
2111 | |
2112 check_topfill(towin, FALSE); | |
2113 #ifdef FEAT_FOLDING | |
2114 (void)hasFoldingWin(towin, towin->w_topline, &towin->w_topline, | |
2115 NULL, TRUE, NULL); | |
2116 #endif | |
2117 } | |
2118 | |
2119 /* | |
2120 * This is called when 'diffopt' is changed. | |
2121 */ | |
2122 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2123 diffopt_changed(void) |
7 | 2124 { |
2125 char_u *p; | |
2126 int diff_context_new = 6; | |
2127 int diff_flags_new = 0; | |
764 | 2128 int diff_foldcolumn_new = 2; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2129 long diff_algorithm_new = 0; |
672 | 2130 tabpage_T *tp; |
7 | 2131 |
2132 p = p_dip; | |
2133 while (*p != NUL) | |
2134 { | |
2135 if (STRNCMP(p, "filler", 6) == 0) | |
2136 { | |
2137 p += 6; | |
2138 diff_flags_new |= DIFF_FILLER; | |
2139 } | |
2140 else if (STRNCMP(p, "context:", 8) == 0 && VIM_ISDIGIT(p[8])) | |
2141 { | |
2142 p += 8; | |
2143 diff_context_new = getdigits(&p); | |
2144 } | |
2145 else if (STRNCMP(p, "icase", 5) == 0) | |
2146 { | |
2147 p += 5; | |
2148 diff_flags_new |= DIFF_ICASE; | |
2149 } | |
2150 else if (STRNCMP(p, "iwhite", 6) == 0) | |
2151 { | |
2152 p += 6; | |
2153 diff_flags_new |= DIFF_IWHITE; | |
2154 } | |
764 | 2155 else if (STRNCMP(p, "horizontal", 10) == 0) |
2156 { | |
2157 p += 10; | |
2158 diff_flags_new |= DIFF_HORIZONTAL; | |
2159 } | |
2160 else if (STRNCMP(p, "vertical", 8) == 0) | |
2161 { | |
2162 p += 8; | |
2163 diff_flags_new |= DIFF_VERTICAL; | |
2164 } | |
2165 else if (STRNCMP(p, "foldcolumn:", 11) == 0 && VIM_ISDIGIT(p[11])) | |
2166 { | |
2167 p += 11; | |
2168 diff_foldcolumn_new = getdigits(&p); | |
2169 } | |
12971
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2170 else if (STRNCMP(p, "hiddenoff", 9) == 0) |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2171 { |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2172 p += 9; |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2173 diff_flags_new |= DIFF_HIDDEN_OFF; |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2174 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2175 else if (STRNCMP(p, "indent-heuristic", 16) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2176 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2177 p += 16; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2178 diff_algorithm_new |= XDF_INDENT_HEURISTIC; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2179 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2180 else if (STRNCMP(p, "internal", 8) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2181 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2182 p += 8; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2183 diff_flags_new |= DIFF_INTERNAL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2184 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2185 else if (STRNCMP(p, "algorithm:", 10) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2186 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2187 p += 10; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2188 if (STRNCMP(p, "myers", 5) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2189 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2190 p += 5; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2191 diff_algorithm_new = 0; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2192 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2193 else if (STRNCMP(p, "minimal", 7) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2194 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2195 p += 7; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2196 diff_algorithm_new = XDF_NEED_MINIMAL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2197 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2198 else if (STRNCMP(p, "patience", 8) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2199 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2200 p += 8; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2201 diff_algorithm_new = XDF_PATIENCE_DIFF; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2202 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2203 else if (STRNCMP(p, "histogram", 9) == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2204 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2205 p += 9; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2206 diff_algorithm_new = XDF_HISTOGRAM_DIFF; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2207 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2208 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2209 |
7 | 2210 if (*p != ',' && *p != NUL) |
2211 return FAIL; | |
2212 if (*p == ',') | |
2213 ++p; | |
2214 } | |
2215 | |
764 | 2216 /* Can't have both "horizontal" and "vertical". */ |
2217 if ((diff_flags_new & DIFF_HORIZONTAL) && (diff_flags_new & DIFF_VERTICAL)) | |
2218 return FAIL; | |
2219 | |
7 | 2220 /* If "icase" or "iwhite" was added or removed, need to update the diff. */ |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2221 if (diff_flags != diff_flags_new || diff_algorithm != diff_algorithm_new) |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2222 FOR_ALL_TABPAGES(tp) |
672 | 2223 tp->tp_diff_invalid = TRUE; |
7 | 2224 |
2225 diff_flags = diff_flags_new; | |
2226 diff_context = diff_context_new; | |
764 | 2227 diff_foldcolumn = diff_foldcolumn_new; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2228 diff_algorithm = diff_algorithm_new; |
7 | 2229 |
2230 diff_redraw(TRUE); | |
2231 | |
2232 /* recompute the scroll binding with the new option value, may | |
2233 * remove or add filler lines */ | |
2234 check_scrollbind((linenr_T)0, 0L); | |
2235 | |
2236 return OK; | |
2237 } | |
2238 | |
2239 /* | |
764 | 2240 * Return TRUE if 'diffopt' contains "horizontal". |
2241 */ | |
2242 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2243 diffopt_horizontal(void) |
764 | 2244 { |
2245 return (diff_flags & DIFF_HORIZONTAL) != 0; | |
2246 } | |
2247 | |
2248 /* | |
12971
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2249 * Return TRUE if 'diffopt' contains "hiddenoff". |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2250 */ |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2251 int |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2252 diffopt_hiddenoff(void) |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2253 { |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2254 return (diff_flags & DIFF_HIDDEN_OFF) != 0; |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2255 } |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2256 |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2257 /* |
7 | 2258 * Find the difference within a changed line. |
2259 * Returns TRUE if the line was added, no other buffer has it. | |
2260 */ | |
2261 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2262 diff_find_change( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2263 win_T *wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2264 linenr_T lnum, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2265 int *startp, /* first char of the change */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2266 int *endp) /* last char of the change */ |
7 | 2267 { |
2268 char_u *line_org; | |
2269 char_u *line_new; | |
2270 int i; | |
829 | 2271 int si_org, si_new; |
2272 int ei_org, ei_new; | |
7 | 2273 diff_T *dp; |
2274 int idx; | |
2275 int off; | |
2276 int added = TRUE; | |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2277 char_u *p1, *p2; |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2278 int l; |
7 | 2279 |
2280 /* Make a copy of the line, the next ml_get() will invalidate it. */ | |
2281 line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE)); | |
2282 if (line_org == NULL) | |
2283 return FALSE; | |
2284 | |
2285 idx = diff_buf_idx(wp->w_buffer); | |
2286 if (idx == DB_COUNT) /* cannot happen */ | |
1074 | 2287 { |
2288 vim_free(line_org); | |
7 | 2289 return FALSE; |
1074 | 2290 } |
7 | 2291 |
2292 /* search for a change that includes "lnum" in the list of diffblocks. */ | |
672 | 2293 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
7 | 2294 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
2295 break; | |
672 | 2296 if (dp == NULL || diff_check_sanity(curtab, dp) == FAIL) |
1074 | 2297 { |
2298 vim_free(line_org); | |
7 | 2299 return FALSE; |
1074 | 2300 } |
7 | 2301 |
2302 off = lnum - dp->df_lnum[idx]; | |
2303 | |
2304 for (i = 0; i < DB_COUNT; ++i) | |
672 | 2305 if (curtab->tp_diffbuf[i] != NULL && i != idx) |
7 | 2306 { |
2307 /* Skip lines that are not in the other change (filler lines). */ | |
2308 if (off >= dp->df_count[i]) | |
2309 continue; | |
2310 added = FALSE; | |
829 | 2311 line_new = ml_get_buf(curtab->tp_diffbuf[i], |
2312 dp->df_lnum[i] + off, FALSE); | |
7 | 2313 |
2314 /* Search for start of difference */ | |
829 | 2315 si_org = si_new = 0; |
2316 while (line_org[si_org] != NUL) | |
2317 { | |
2318 if ((diff_flags & DIFF_IWHITE) | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2319 && VIM_ISWHITE(line_org[si_org]) |
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2320 && VIM_ISWHITE(line_new[si_new])) |
829 | 2321 { |
835 | 2322 si_org = (int)(skipwhite(line_org + si_org) - line_org); |
2323 si_new = (int)(skipwhite(line_new + si_new) - line_new); | |
829 | 2324 } |
2325 else | |
2326 { | |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2327 if (!diff_equal_char(line_org + si_org, line_new + si_new, |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2328 &l)) |
829 | 2329 break; |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2330 si_org += l; |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2331 si_new += l; |
829 | 2332 } |
2333 } | |
7 | 2334 #ifdef FEAT_MBYTE |
2335 if (has_mbyte) | |
2336 { | |
2337 /* Move back to first byte of character in both lines (may | |
2338 * have "nn^" in line_org and "n^ in line_new). */ | |
829 | 2339 si_org -= (*mb_head_off)(line_org, line_org + si_org); |
2340 si_new -= (*mb_head_off)(line_new, line_new + si_new); | |
7 | 2341 } |
2342 #endif | |
829 | 2343 if (*startp > si_org) |
2344 *startp = si_org; | |
7 | 2345 |
2346 /* Search for end of difference, if any. */ | |
829 | 2347 if (line_org[si_org] != NUL || line_new[si_new] != NUL) |
7 | 2348 { |
2349 ei_org = (int)STRLEN(line_org); | |
2350 ei_new = (int)STRLEN(line_new); | |
829 | 2351 while (ei_org >= *startp && ei_new >= si_new |
2352 && ei_org >= 0 && ei_new >= 0) | |
7 | 2353 { |
829 | 2354 if ((diff_flags & DIFF_IWHITE) |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2355 && VIM_ISWHITE(line_org[ei_org]) |
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2356 && VIM_ISWHITE(line_new[ei_new])) |
829 | 2357 { |
2358 while (ei_org >= *startp | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2359 && VIM_ISWHITE(line_org[ei_org])) |
829 | 2360 --ei_org; |
2361 while (ei_new >= si_new | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2362 && VIM_ISWHITE(line_new[ei_new])) |
829 | 2363 --ei_new; |
2364 } | |
2365 else | |
2366 { | |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2367 p1 = line_org + ei_org; |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2368 p2 = line_new + ei_new; |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2369 #ifdef FEAT_MBYTE |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2370 p1 -= (*mb_head_off)(line_org, p1); |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2371 p2 -= (*mb_head_off)(line_new, p2); |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2372 #endif |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2373 if (!diff_equal_char(p1, p2, &l)) |
829 | 2374 break; |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2375 ei_org -= l; |
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2376 ei_new -= l; |
829 | 2377 } |
7 | 2378 } |
2379 if (*endp < ei_org) | |
2380 *endp = ei_org; | |
2381 } | |
2382 } | |
2383 | |
2384 vim_free(line_org); | |
2385 return added; | |
2386 } | |
2387 | |
2388 #if defined(FEAT_FOLDING) || defined(PROTO) | |
2389 /* | |
2390 * Return TRUE if line "lnum" is not close to a diff block, this line should | |
2391 * be in a fold. | |
2392 * Return FALSE if there are no diff blocks at all in this window. | |
2393 */ | |
2394 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2395 diff_infold(win_T *wp, linenr_T lnum) |
7 | 2396 { |
2397 int i; | |
2398 int idx = -1; | |
2399 int other = FALSE; | |
2400 diff_T *dp; | |
2401 | |
2402 /* Return if 'diff' isn't set. */ | |
2403 if (!wp->w_p_diff) | |
2404 return FALSE; | |
2405 | |
2406 for (i = 0; i < DB_COUNT; ++i) | |
2407 { | |
672 | 2408 if (curtab->tp_diffbuf[i] == wp->w_buffer) |
7 | 2409 idx = i; |
672 | 2410 else if (curtab->tp_diffbuf[i] != NULL) |
7 | 2411 other = TRUE; |
2412 } | |
2413 | |
2414 /* return here if there are no diffs in the window */ | |
2415 if (idx == -1 || !other) | |
2416 return FALSE; | |
2417 | |
672 | 2418 if (curtab->tp_diff_invalid) |
7 | 2419 ex_diffupdate(NULL); /* update after a big change */ |
2420 | |
2421 /* Return if there are no diff blocks. All lines will be folded. */ | |
672 | 2422 if (curtab->tp_first_diff == NULL) |
7 | 2423 return TRUE; |
2424 | |
672 | 2425 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
7 | 2426 { |
2427 /* If this change is below the line there can't be any further match. */ | |
2428 if (dp->df_lnum[idx] - diff_context > lnum) | |
2429 break; | |
2430 /* If this change ends before the line we have a match. */ | |
2431 if (dp->df_lnum[idx] + dp->df_count[idx] + diff_context > lnum) | |
2432 return FALSE; | |
2433 } | |
2434 return TRUE; | |
2435 } | |
2436 #endif | |
2437 | |
2438 /* | |
2439 * "dp" and "do" commands. | |
2440 */ | |
2441 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2442 nv_diffgetput(int put, long count) |
7 | 2443 { |
2444 exarg_T ea; | |
6314 | 2445 char_u buf[30]; |
7 | 2446 |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
2447 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
2448 if (bt_prompt(curbuf)) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
2449 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
2450 vim_beep(BO_OPER); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
2451 return; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
2452 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
2453 #endif |
6314 | 2454 if (count == 0) |
2455 ea.arg = (char_u *)""; | |
2456 else | |
2457 { | |
2458 vim_snprintf((char *)buf, 30, "%ld", count); | |
2459 ea.arg = buf; | |
2460 } | |
7 | 2461 if (put) |
2462 ea.cmdidx = CMD_diffput; | |
2463 else | |
2464 ea.cmdidx = CMD_diffget; | |
2465 ea.addr_count = 0; | |
2466 ea.line1 = curwin->w_cursor.lnum; | |
2467 ea.line2 = curwin->w_cursor.lnum; | |
2468 ex_diffgetput(&ea); | |
2469 } | |
2470 | |
2471 /* | |
2472 * ":diffget" | |
2473 * ":diffput" | |
2474 */ | |
2475 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2476 ex_diffgetput(exarg_T *eap) |
7 | 2477 { |
2478 linenr_T lnum; | |
2479 int count; | |
2480 linenr_T off = 0; | |
2481 diff_T *dp; | |
2482 diff_T *dprev; | |
2483 diff_T *dfree; | |
2484 int idx_cur; | |
2485 int idx_other; | |
2486 int idx_from; | |
2487 int idx_to; | |
2488 int i; | |
2489 int added; | |
2490 char_u *p; | |
2491 aco_save_T aco; | |
2492 buf_T *buf; | |
2493 int start_skip, end_skip; | |
2494 int new_count; | |
648 | 2495 int buf_empty; |
1075 | 2496 int found_not_ma = FALSE; |
7 | 2497 |
2498 /* Find the current buffer in the list of diff buffers. */ | |
2499 idx_cur = diff_buf_idx(curbuf); | |
2500 if (idx_cur == DB_COUNT) | |
2501 { | |
2502 EMSG(_("E99: Current buffer is not in diff mode")); | |
2503 return; | |
2504 } | |
2505 | |
2506 if (*eap->arg == NUL) | |
2507 { | |
2508 /* No argument: Find the other buffer in the list of diff buffers. */ | |
2509 for (idx_other = 0; idx_other < DB_COUNT; ++idx_other) | |
672 | 2510 if (curtab->tp_diffbuf[idx_other] != curbuf |
1075 | 2511 && curtab->tp_diffbuf[idx_other] != NULL) |
2512 { | |
2513 if (eap->cmdidx != CMD_diffput | |
2514 || curtab->tp_diffbuf[idx_other]->b_p_ma) | |
2515 break; | |
2516 found_not_ma = TRUE; | |
2517 } | |
7 | 2518 if (idx_other == DB_COUNT) |
2519 { | |
1075 | 2520 if (found_not_ma) |
2521 EMSG(_("E793: No other buffer in diff mode is modifiable")); | |
2522 else | |
2523 EMSG(_("E100: No other buffer in diff mode")); | |
7 | 2524 return; |
2525 } | |
2526 | |
2527 /* Check that there isn't a third buffer in the list */ | |
2528 for (i = idx_other + 1; i < DB_COUNT; ++i) | |
672 | 2529 if (curtab->tp_diffbuf[i] != curbuf |
2530 && curtab->tp_diffbuf[i] != NULL | |
2531 && (eap->cmdidx != CMD_diffput || curtab->tp_diffbuf[i]->b_p_ma)) | |
7 | 2532 { |
2533 EMSG(_("E101: More than two buffers in diff mode, don't know which one to use")); | |
2534 return; | |
2535 } | |
2536 } | |
2537 else | |
2538 { | |
2539 /* Buffer number or pattern given. Ignore trailing white space. */ | |
2540 p = eap->arg + STRLEN(eap->arg); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2541 while (p > eap->arg && VIM_ISWHITE(p[-1])) |
7 | 2542 --p; |
2543 for (i = 0; vim_isdigit(eap->arg[i]) && eap->arg + i < p; ++i) | |
2544 ; | |
2545 if (eap->arg + i == p) /* digits only */ | |
2546 i = atol((char *)eap->arg); | |
2547 else | |
2548 { | |
4236 | 2549 i = buflist_findpat(eap->arg, p, FALSE, TRUE, FALSE); |
7 | 2550 if (i < 0) |
2551 return; /* error message already given */ | |
2552 } | |
2553 buf = buflist_findnr(i); | |
2554 if (buf == NULL) | |
2555 { | |
2556 EMSG2(_("E102: Can't find buffer \"%s\""), eap->arg); | |
2557 return; | |
2558 } | |
1788 | 2559 if (buf == curbuf) |
2560 return; /* nothing to do */ | |
7 | 2561 idx_other = diff_buf_idx(buf); |
2562 if (idx_other == DB_COUNT) | |
2563 { | |
2564 EMSG2(_("E103: Buffer \"%s\" is not in diff mode"), eap->arg); | |
2565 return; | |
2566 } | |
2567 } | |
2568 | |
2569 diff_busy = TRUE; | |
2570 | |
2571 /* When no range given include the line above or below the cursor. */ | |
2572 if (eap->addr_count == 0) | |
2573 { | |
2574 /* Make it possible that ":diffget" on the last line gets line below | |
2575 * the cursor line when there is no difference above the cursor. */ | |
2576 if (eap->cmdidx == CMD_diffget | |
2577 && eap->line1 == curbuf->b_ml.ml_line_count | |
2578 && diff_check(curwin, eap->line1) == 0 | |
2579 && (eap->line1 == 1 || diff_check(curwin, eap->line1 - 1) == 0)) | |
2580 ++eap->line2; | |
2581 else if (eap->line1 > 0) | |
2582 --eap->line1; | |
2583 } | |
2584 | |
2585 if (eap->cmdidx == CMD_diffget) | |
2586 { | |
2587 idx_from = idx_other; | |
2588 idx_to = idx_cur; | |
2589 } | |
2590 else | |
2591 { | |
2592 idx_from = idx_cur; | |
2593 idx_to = idx_other; | |
2594 /* Need to make the other buffer the current buffer to be able to make | |
2595 * changes in it. */ | |
2596 /* set curwin/curbuf to buf and save a few things */ | |
672 | 2597 aucmd_prepbuf(&aco, curtab->tp_diffbuf[idx_other]); |
7 | 2598 } |
2599 | |
819 | 2600 /* May give the warning for a changed buffer here, which can trigger the |
2601 * FileChangedRO autocommand, which may do nasty things and mess | |
2602 * everything up. */ | |
2603 if (!curbuf->b_changed) | |
2604 { | |
2605 change_warning(0); | |
2606 if (diff_buf_idx(curbuf) != idx_to) | |
2607 { | |
2608 EMSG(_("E787: Buffer changed unexpectedly")); | |
2609 return; | |
2610 } | |
2611 } | |
2612 | |
7 | 2613 dprev = NULL; |
672 | 2614 for (dp = curtab->tp_first_diff; dp != NULL; ) |
7 | 2615 { |
2616 if (dp->df_lnum[idx_cur] > eap->line2 + off) | |
2617 break; /* past the range that was specified */ | |
2618 | |
2619 dfree = NULL; | |
2620 lnum = dp->df_lnum[idx_to]; | |
2621 count = dp->df_count[idx_to]; | |
2622 if (dp->df_lnum[idx_cur] + dp->df_count[idx_cur] > eap->line1 + off | |
2623 && u_save(lnum - 1, lnum + count) != FAIL) | |
2624 { | |
2625 /* Inside the specified range and saving for undo worked. */ | |
2626 start_skip = 0; | |
2627 end_skip = 0; | |
2628 if (eap->addr_count > 0) | |
2629 { | |
2630 /* A range was specified: check if lines need to be skipped. */ | |
2631 start_skip = eap->line1 + off - dp->df_lnum[idx_cur]; | |
2632 if (start_skip > 0) | |
2633 { | |
2634 /* range starts below start of current diff block */ | |
2635 if (start_skip > count) | |
2636 { | |
2637 lnum += count; | |
2638 count = 0; | |
2639 } | |
2640 else | |
2641 { | |
2642 count -= start_skip; | |
2643 lnum += start_skip; | |
2644 } | |
2645 } | |
2646 else | |
2647 start_skip = 0; | |
2648 | |
2649 end_skip = dp->df_lnum[idx_cur] + dp->df_count[idx_cur] - 1 | |
2650 - (eap->line2 + off); | |
2651 if (end_skip > 0) | |
2652 { | |
2653 /* range ends above end of current/from diff block */ | |
2654 if (idx_cur == idx_from) /* :diffput */ | |
2655 { | |
2656 i = dp->df_count[idx_cur] - start_skip - end_skip; | |
2657 if (count > i) | |
2658 count = i; | |
2659 } | |
2660 else /* :diffget */ | |
2661 { | |
2662 count -= end_skip; | |
2663 end_skip = dp->df_count[idx_from] - start_skip - count; | |
2664 if (end_skip < 0) | |
2665 end_skip = 0; | |
2666 } | |
2667 } | |
2668 else | |
2669 end_skip = 0; | |
2670 } | |
2671 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11113
diff
changeset
|
2672 buf_empty = BUFEMPTY(); |
7 | 2673 added = 0; |
2674 for (i = 0; i < count; ++i) | |
2675 { | |
648 | 2676 /* remember deleting the last line of the buffer */ |
2677 buf_empty = curbuf->b_ml.ml_line_count == 1; | |
7 | 2678 ml_delete(lnum, FALSE); |
2679 --added; | |
2680 } | |
2681 for (i = 0; i < dp->df_count[idx_from] - start_skip - end_skip; ++i) | |
2682 { | |
2683 linenr_T nr; | |
2684 | |
2685 nr = dp->df_lnum[idx_from] + start_skip + i; | |
672 | 2686 if (nr > curtab->tp_diffbuf[idx_from]->b_ml.ml_line_count) |
7 | 2687 break; |
819 | 2688 p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], |
2689 nr, FALSE)); | |
7 | 2690 if (p != NULL) |
2691 { | |
2692 ml_append(lnum + i - 1, p, 0, FALSE); | |
2693 vim_free(p); | |
2694 ++added; | |
648 | 2695 if (buf_empty && curbuf->b_ml.ml_line_count == 2) |
2696 { | |
2697 /* Added the first line into an empty buffer, need to | |
2698 * delete the dummy empty line. */ | |
2699 buf_empty = FALSE; | |
2700 ml_delete((linenr_T)2, FALSE); | |
2701 } | |
7 | 2702 } |
2703 } | |
2704 new_count = dp->df_count[idx_to] + added; | |
2705 dp->df_count[idx_to] = new_count; | |
2706 | |
2707 if (start_skip == 0 && end_skip == 0) | |
2708 { | |
2709 /* Check if there are any other buffers and if the diff is | |
2710 * equal in them. */ | |
2711 for (i = 0; i < DB_COUNT; ++i) | |
819 | 2712 if (curtab->tp_diffbuf[i] != NULL && i != idx_from |
2713 && i != idx_to | |
7 | 2714 && !diff_equal_entry(dp, idx_from, i)) |
2715 break; | |
2716 if (i == DB_COUNT) | |
2717 { | |
2718 /* delete the diff entry, the buffers are now equal here */ | |
2719 dfree = dp; | |
2720 dp = dp->df_next; | |
2721 if (dprev == NULL) | |
672 | 2722 curtab->tp_first_diff = dp; |
7 | 2723 else |
2724 dprev->df_next = dp; | |
2725 } | |
2726 } | |
2727 | |
2728 /* Adjust marks. This will change the following entries! */ | |
2729 if (added != 0) | |
2730 { | |
2731 mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added); | |
2732 if (curwin->w_cursor.lnum >= lnum) | |
2733 { | |
2734 /* Adjust the cursor position if it's in/after the changed | |
2735 * lines. */ | |
2736 if (curwin->w_cursor.lnum >= lnum + count) | |
2737 curwin->w_cursor.lnum += added; | |
2738 else if (added < 0) | |
2739 curwin->w_cursor.lnum = lnum; | |
2740 } | |
2741 } | |
2742 changed_lines(lnum, 0, lnum + count, (long)added); | |
2743 | |
2744 if (dfree != NULL) | |
2745 { | |
2746 /* Diff is deleted, update folds in other windows. */ | |
2747 #ifdef FEAT_FOLDING | |
2748 diff_fold_update(dfree, idx_to); | |
2749 #endif | |
2750 vim_free(dfree); | |
2751 } | |
2752 else | |
2753 /* mark_adjust() may have changed the count in a wrong way */ | |
2754 dp->df_count[idx_to] = new_count; | |
2755 | |
2756 /* When changing the current buffer, keep track of line numbers */ | |
2757 if (idx_cur == idx_to) | |
2758 off += added; | |
2759 } | |
2760 | |
2761 /* If before the range or not deleted, go to next diff. */ | |
2762 if (dfree == NULL) | |
2763 { | |
2764 dprev = dp; | |
2765 dp = dp->df_next; | |
2766 } | |
2767 } | |
2768 | |
2769 /* restore curwin/curbuf and a few other things */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2770 if (eap->cmdidx != CMD_diffget) |
7 | 2771 { |
2772 /* Syncing undo only works for the current buffer, but we change | |
2773 * another buffer. Sync undo if the command was typed. This isn't | |
2774 * 100% right when ":diffput" is used in a function or mapping. */ | |
2775 if (KeyTyped) | |
825 | 2776 u_sync(FALSE); |
7 | 2777 aucmd_restbuf(&aco); |
2778 } | |
2779 | |
2780 diff_busy = FALSE; | |
2781 | |
2782 /* Check that the cursor is on a valid character and update it's position. | |
2783 * When there were filler lines the topline has become invalid. */ | |
2784 check_cursor(); | |
2785 changed_line_abv_curs(); | |
2786 | |
2787 /* Also need to redraw the other buffers. */ | |
2788 diff_redraw(FALSE); | |
2789 } | |
2790 | |
2791 #ifdef FEAT_FOLDING | |
2792 /* | |
2793 * Update folds for all diff buffers for entry "dp". | |
2794 * Skip buffer with index "skip_idx". | |
2795 * When there are no diffs, all folds are removed. | |
2796 */ | |
2797 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2798 diff_fold_update(diff_T *dp, int skip_idx) |
7 | 2799 { |
2800 int i; | |
2801 win_T *wp; | |
2802 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2803 FOR_ALL_WINDOWS(wp) |
7 | 2804 for (i = 0; i < DB_COUNT; ++i) |
672 | 2805 if (curtab->tp_diffbuf[i] == wp->w_buffer && i != skip_idx) |
7 | 2806 foldUpdate(wp, dp->df_lnum[i], |
2807 dp->df_lnum[i] + dp->df_count[i]); | |
2808 } | |
2809 #endif | |
2810 | |
2811 /* | |
2812 * Return TRUE if buffer "buf" is in diff-mode. | |
2813 */ | |
2814 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2815 diff_mode_buf(buf_T *buf) |
7 | 2816 { |
672 | 2817 tabpage_T *tp; |
2818 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2819 FOR_ALL_TABPAGES(tp) |
672 | 2820 if (diff_buf_idx_tp(buf, tp) != DB_COUNT) |
2821 return TRUE; | |
2822 return FALSE; | |
7 | 2823 } |
2824 | |
2825 /* | |
2826 * Move "count" times in direction "dir" to the next diff block. | |
2827 * Return FAIL if there isn't such a diff block. | |
2828 */ | |
2829 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2830 diff_move_to(int dir, long count) |
7 | 2831 { |
2832 int idx; | |
2833 linenr_T lnum = curwin->w_cursor.lnum; | |
2834 diff_T *dp; | |
2835 | |
2836 idx = diff_buf_idx(curbuf); | |
672 | 2837 if (idx == DB_COUNT || curtab->tp_first_diff == NULL) |
7 | 2838 return FAIL; |
2839 | |
672 | 2840 if (curtab->tp_diff_invalid) |
7 | 2841 ex_diffupdate(NULL); /* update after a big change */ |
2842 | |
672 | 2843 if (curtab->tp_first_diff == NULL) /* no diffs today */ |
7 | 2844 return FAIL; |
2845 | |
2846 while (--count >= 0) | |
2847 { | |
2848 /* Check if already before first diff. */ | |
672 | 2849 if (dir == BACKWARD && lnum <= curtab->tp_first_diff->df_lnum[idx]) |
7 | 2850 break; |
2851 | |
672 | 2852 for (dp = curtab->tp_first_diff; ; dp = dp->df_next) |
7 | 2853 { |
2854 if (dp == NULL) | |
2855 break; | |
2856 if ((dir == FORWARD && lnum < dp->df_lnum[idx]) | |
2857 || (dir == BACKWARD | |
2858 && (dp->df_next == NULL | |
2859 || lnum <= dp->df_next->df_lnum[idx]))) | |
2860 { | |
2861 lnum = dp->df_lnum[idx]; | |
2862 break; | |
2863 } | |
2864 } | |
2865 } | |
2866 | |
2867 /* don't end up past the end of the file */ | |
2868 if (lnum > curbuf->b_ml.ml_line_count) | |
2869 lnum = curbuf->b_ml.ml_line_count; | |
2870 | |
2871 /* When the cursor didn't move at all we fail. */ | |
2872 if (lnum == curwin->w_cursor.lnum) | |
2873 return FAIL; | |
2874 | |
2875 setpcmark(); | |
2876 curwin->w_cursor.lnum = lnum; | |
2877 curwin->w_cursor.col = 0; | |
2878 | |
2879 return OK; | |
2880 } | |
2881 | |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2882 /* |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2883 * Return the line number in the current window that is closest to "lnum1" in |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2884 * "buf1" in diff mode. |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2885 */ |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2886 static linenr_T |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2887 diff_get_corresponding_line_int( |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2888 buf_T *buf1, |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2889 linenr_T lnum1) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2890 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2891 int idx1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2892 int idx2; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2893 diff_T *dp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2894 int baseline = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2895 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2896 idx1 = diff_buf_idx(buf1); |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2897 idx2 = diff_buf_idx(curbuf); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2898 if (idx1 == DB_COUNT || idx2 == DB_COUNT || curtab->tp_first_diff == NULL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2899 return lnum1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2900 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2901 if (curtab->tp_diff_invalid) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2902 ex_diffupdate(NULL); /* update after a big change */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2903 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2904 if (curtab->tp_first_diff == NULL) /* no diffs today */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2905 return lnum1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2906 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2907 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2908 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2909 if (dp->df_lnum[idx1] > lnum1) |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2910 return lnum1 - baseline; |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2911 if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2912 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2913 /* Inside the diffblock */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2914 baseline = lnum1 - dp->df_lnum[idx1]; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2915 if (baseline > dp->df_count[idx2]) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2916 baseline = dp->df_count[idx2]; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2917 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2918 return dp->df_lnum[idx2] + baseline; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2919 } |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2920 if ( (dp->df_lnum[idx1] == lnum1) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2921 && (dp->df_count[idx1] == 0) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2922 && (dp->df_lnum[idx2] <= curwin->w_cursor.lnum) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2923 && ((dp->df_lnum[idx2] + dp->df_count[idx2]) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2924 > curwin->w_cursor.lnum)) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2925 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2926 * Special case: if the cursor is just after a zero-count |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2927 * block (i.e. all filler) and the target cursor is already |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2928 * inside the corresponding block, leave the target cursor |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2929 * unmoved. This makes repeated CTRL-W W operations work |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2930 * as expected. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2931 */ |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2932 return curwin->w_cursor.lnum; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2933 baseline = (dp->df_lnum[idx1] + dp->df_count[idx1]) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2934 - (dp->df_lnum[idx2] + dp->df_count[idx2]); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2935 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2936 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2937 /* If we get here then the cursor is after the last diff */ |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2938 return lnum1 - baseline; |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2939 } |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2940 |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2941 /* |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2942 * Return the line number in the current window that is closest to "lnum1" in |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2943 * "buf1" in diff mode. Checks the line number to be valid. |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2944 */ |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2945 linenr_T |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2946 diff_get_corresponding_line(buf_T *buf1, linenr_T lnum1) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2947 { |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2948 linenr_T lnum = diff_get_corresponding_line_int(buf1, lnum1); |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2949 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2950 /* don't end up past the end of the file */ |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2951 if (lnum > curbuf->b_ml.ml_line_count) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2952 return curbuf->b_ml.ml_line_count; |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2953 return lnum; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2954 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
2955 |
7 | 2956 /* |
2957 * For line "lnum" in the current window find the equivalent lnum in window | |
2958 * "wp", compensating for inserted/deleted lines. | |
2959 */ | |
2960 linenr_T | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2961 diff_lnum_win(linenr_T lnum, win_T *wp) |
7 | 2962 { |
2963 diff_T *dp; | |
2964 int idx; | |
2965 int i; | |
2966 linenr_T n; | |
2967 | |
2968 idx = diff_buf_idx(curbuf); | |
2969 if (idx == DB_COUNT) /* safety check */ | |
2970 return (linenr_T)0; | |
2971 | |
672 | 2972 if (curtab->tp_diff_invalid) |
7 | 2973 ex_diffupdate(NULL); /* update after a big change */ |
2974 | |
2975 /* search for a change that includes "lnum" in the list of diffblocks. */ | |
672 | 2976 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
7 | 2977 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
2978 break; | |
2979 | |
2980 /* When after the last change, compute relative to the last line number. */ | |
2981 if (dp == NULL) | |
2982 return wp->w_buffer->b_ml.ml_line_count | |
2983 - (curbuf->b_ml.ml_line_count - lnum); | |
2984 | |
2985 /* Find index for "wp". */ | |
2986 i = diff_buf_idx(wp->w_buffer); | |
2987 if (i == DB_COUNT) /* safety check */ | |
2988 return (linenr_T)0; | |
2989 | |
2990 n = lnum + (dp->df_lnum[i] - dp->df_lnum[idx]); | |
2991 if (n > dp->df_lnum[i] + dp->df_count[i]) | |
2992 n = dp->df_lnum[i] + dp->df_count[i]; | |
2993 return n; | |
2994 } | |
2995 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2996 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2997 * Handle an ED style diff line. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2998 * Return FAIL if the line does not contain diff info. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2999 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3000 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3001 parse_diff_ed( |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3002 char_u *line, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3003 linenr_T *lnum_orig, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3004 long *count_orig, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3005 linenr_T *lnum_new, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3006 long *count_new) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3007 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3008 char_u *p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3009 long f1, l1, f2, l2; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3010 int difftype; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3011 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3012 // The line must be one of three formats: |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3013 // change: {first}[,{last}]c{first}[,{last}] |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3014 // append: {first}a{first}[,{last}] |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3015 // delete: {first}[,{last}]d{first} |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3016 p = line; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3017 f1 = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3018 if (*p == ',') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3019 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3020 ++p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3021 l1 = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3022 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3023 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3024 l1 = f1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3025 if (*p != 'a' && *p != 'c' && *p != 'd') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3026 return FAIL; // invalid diff format |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3027 difftype = *p++; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3028 f2 = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3029 if (*p == ',') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3030 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3031 ++p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3032 l2 = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3033 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3034 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3035 l2 = f2; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3036 if (l1 < f1 || l2 < f2) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3037 return FAIL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3038 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3039 if (difftype == 'a') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3040 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3041 *lnum_orig = f1 + 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3042 *count_orig = 0; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3043 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3044 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3045 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3046 *lnum_orig = f1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3047 *count_orig = l1 - f1 + 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3048 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3049 if (difftype == 'd') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3050 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3051 *lnum_new = f2 + 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3052 *count_new = 0; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3053 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3054 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3055 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3056 *lnum_new = f2; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3057 *count_new = l2 - f2 + 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3058 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3059 return OK; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3060 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3061 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3062 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3063 * Parses unified diff with zero(!) context lines. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3064 * Return FAIL if there is no diff information in "line". |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3065 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3066 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3067 parse_diff_unified( |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3068 char_u *line, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3069 linenr_T *lnum_orig, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3070 long *count_orig, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3071 linenr_T *lnum_new, |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3072 long *count_new) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3073 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3074 char_u *p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3075 long oldline, oldcount, newline, newcount; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3076 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3077 // Parse unified diff hunk header: |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3078 // @@ -oldline,oldcount +newline,newcount @@ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3079 p = line; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3080 if (*p++ == '@' && *p++ == '@' && *p++ == ' ' && *p++ == '-') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3081 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3082 oldline = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3083 if (*p == ',') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3084 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3085 ++p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3086 oldcount = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3087 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3088 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3089 oldcount = 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3090 if (*p++ == ' ' && *p++ == '+') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3091 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3092 newline = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3093 if (*p == ',') |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3094 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3095 ++p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3096 newcount = getdigits(&p); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3097 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3098 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3099 newcount = 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3100 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3101 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3102 return FAIL; // invalid diff format |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3103 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3104 if (oldcount == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3105 oldline += 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3106 if (newcount == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3107 newline += 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3108 if (newline == 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3109 newline = 1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3110 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3111 *lnum_orig = oldline; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3112 *count_orig = oldcount; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3113 *lnum_new = newline; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3114 *count_new = newcount; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3115 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3116 return OK; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3117 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3118 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3119 return FAIL; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3120 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3121 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3122 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3123 * Callback function for the xdl_diff() function. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3124 * Stores the diff output in a grow array. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3125 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3126 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3127 xdiff_out(void *priv, mmbuffer_t *mb, int nbuf) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3128 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3129 diffout_T *dout = (diffout_T *)priv; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3130 int i; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3131 char_u *p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3132 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3133 for (i = 0; i < nbuf; i++) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3134 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3135 // We are only interested in the header lines, skip text lines. |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3136 if (STRNCMP(mb[i].ptr, "@@ ", 3) != 0) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3137 continue; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3138 if (ga_grow(&dout->dout_ga, 1) == FAIL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3139 return -1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3140 p = vim_strnsave((char_u *)mb[i].ptr, mb[i].size); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3141 if (p == NULL) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3142 return -1; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3143 ((char_u **)dout->dout_ga.ga_data)[dout->dout_ga.ga_len++] = p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3144 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3145 return 0; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3146 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3147 |
7 | 3148 #endif /* FEAT_DIFF */ |