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