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