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