Mercurial > vim
annotate src/diff.c @ 25267:c69ebc71bd85 v8.2.3170
patch 8.2.3170: Illegal memory access in test
Commit: https://github.com/vim/vim/commit/d8cee76b498507c48706f651aeb78b93b5376d00
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jul 15 23:15:59 2021 +0200
patch 8.2.3170: Illegal memory access in test
Problem: Illegal memory access in test.
Solution: Check pointer is not before the start of the line.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 15 Jul 2021 23:30:04 +0200 |
parents | 05c199ea8295 |
children | 712e867f9721 |
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; | |
658 int n; | |
659 | |
17851
ba63a184e6b6
patch 8.1.1922: in diff mode global operations can be very slow
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
660 need_diff_redraw = FALSE; |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
661 FOR_ALL_WINDOWS(wp) |
7 | 662 if (wp->w_p_diff) |
663 { | |
738 | 664 redraw_win_later(wp, SOME_VALID); |
7 | 665 #ifdef FEAT_FOLDING |
666 if (dofold && foldmethodIsDiff(wp)) | |
667 foldUpdateAll(wp); | |
668 #endif | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
669 // 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
|
670 // of that for other windows. |
3904 | 671 n = diff_check(wp, wp->w_topline); |
672 if ((wp != curwin && wp->w_topfill > 0) || n > 0) | |
7 | 673 { |
674 if (wp->w_topfill > n) | |
675 wp->w_topfill = (n < 0 ? 0 : n); | |
3904 | 676 else if (n > 0 && n > wp->w_topfill) |
677 wp->w_topfill = n; | |
5934 | 678 check_topfill(wp, FALSE); |
7 | 679 } |
680 } | |
681 } | |
682 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
683 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
|
684 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
|
685 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
686 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
|
687 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
688 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
|
689 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
|
690 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
691 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
692 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
|
693 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
694 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
695 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
|
696 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
|
697 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
698 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
|
699 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
|
700 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
701 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
|
702 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
703 |
7 | 704 /* |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
705 * 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
|
706 * Return FAIL for failure. |
7 | 707 */ |
708 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
|
709 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
|
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 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
|
712 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
|
713 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
|
714 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
|
715 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
716 // 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
|
717 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
|
718 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
|
719 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
|
720 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
|
721 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
722 // 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
|
723 // 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
|
724 // 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
|
725 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
|
726 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
|
727 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
728 verbose_enter(); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15103
diff
changeset
|
729 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
|
730 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
|
731 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
|
732 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
733 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
|
734 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
735 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
|
736 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
|
737 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
738 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
|
739 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
|
740 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
741 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
|
742 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
743 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
|
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 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
|
746 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
|
747 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
|
748 |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
749 // 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
|
750 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
|
751 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
|
752 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
|
753 if (mb_char2bytes(c, cbuf) != orig_len) |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
754 // TODO: handle byte length difference |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
755 mch_memmove(ptr + len, s, orig_len); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
756 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
757 mch_memmove(ptr + len, cbuf, orig_len); |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
758 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
759 s += orig_len; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
760 len += orig_len; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
761 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
762 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
763 ptr[len++] = *s++; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
764 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
765 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
|
766 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
767 return OK; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
768 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
769 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
770 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
771 * 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
|
772 * 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
|
773 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
774 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
|
775 diff_write(buf_T *buf, diffin_T *din) |
7 | 776 { |
777 int r; | |
778 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
|
779 int save_cmod_flags; |
7 | 780 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
781 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
|
782 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
|
783 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
784 // Always use 'fileformat' set to "unix". |
7 | 785 save_ff = buf->b_p_ff; |
786 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
|
787 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
|
788 // 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
|
789 // 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
|
790 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
|
791 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
|
792 (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
|
793 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
|
794 cmdmod.cmod_flags = save_cmod_flags; |
7 | 795 free_string_option(buf->b_p_ff); |
796 buf->b_p_ff = save_ff; | |
797 return r; | |
798 } | |
799 | |
800 /* | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
801 * 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
|
802 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
803 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
|
804 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
|
805 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
|
806 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
|
807 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
|
808 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
809 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
|
810 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
|
811 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
812 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
|
813 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
814 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
|
815 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
816 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
817 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
818 // 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
|
819 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
|
820 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
|
821 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
|
822 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
|
823 || 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
|
824 || 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
|
825 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
|
826 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
827 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
828 // 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
|
829 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
|
830 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
|
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 // :diffupdate! |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
833 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
|
834 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
|
835 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
836 buf = 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
|
837 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
|
838 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
|
839 } |
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 // 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
|
842 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
|
843 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
|
844 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
|
845 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
846 // 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
|
847 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
|
848 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
849 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
|
850 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
|
851 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
|
852 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
853 // 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
|
854 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
|
855 continue; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
856 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
|
857 continue; |
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 // 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
|
860 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
|
861 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
862 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
|
863 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
|
864 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
865 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
|
866 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
867 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 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
|
869 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
|
870 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
|
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 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
873 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
874 * 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
|
875 * 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
|
876 * 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
|
877 */ |
14764
f562b9fbd0d3
patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents:
14762
diff
changeset
|
878 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
|
879 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
|
880 { |
15971
ced614446eaa
patch 8.1.0991: cannot build with a mix of features
Bram Moolenaar <Bram@vim.org>
parents:
15900
diff
changeset
|
881 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
|
882 #ifdef FEAT_EVAL |
ced614446eaa
patch 8.1.0991: cannot build with a mix of features
Bram Moolenaar <Bram@vim.org>
parents:
15900
diff
changeset
|
883 && *p_dex == NUL |
ced614446eaa
patch 8.1.0991: cannot build with a mix of features
Bram Moolenaar <Bram@vim.org>
parents:
15900
diff
changeset
|
884 #endif |
ced614446eaa
patch 8.1.0991: cannot build with a mix of features
Bram Moolenaar <Bram@vim.org>
parents:
15900
diff
changeset
|
885 ; |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
886 } |
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 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
889 * Return TRUE 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
|
890 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
891 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
|
892 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
|
893 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
894 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
|
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 // 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
|
897 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
|
898 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
|
899 && 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
|
900 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
|
901 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
|
902 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
903 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
904 /* |
7 | 905 * 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
|
906 * 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
|
907 * 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
|
908 * autocommands, e.g. the netrw plugin). |
7 | 909 */ |
910 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
|
911 ex_diffupdate(exarg_T *eap) // "eap" can be NULL |
7 | 912 { |
913 int idx_orig; | |
914 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
|
915 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
|
916 int had_diffs = curtab->tp_first_diff != NULL; |
7 | 917 |
14776
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
918 if (diff_busy) |
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
919 { |
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
920 diff_need_update = TRUE; |
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
921 return; |
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
922 } |
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
923 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
924 // Delete all diffblocks. |
672 | 925 diff_clear(curtab); |
926 curtab->tp_diff_invalid = FALSE; | |
7 | 927 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
928 // Use the first buffer as the original text. |
7 | 929 for (idx_orig = 0; idx_orig < DB_COUNT; ++idx_orig) |
672 | 930 if (curtab->tp_diffbuf[idx_orig] != NULL) |
7 | 931 break; |
932 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
|
933 goto theend; |
7 | 934 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
935 // Only need to do something when there is another buffer. |
7 | 936 for (idx_new = idx_orig + 1; idx_new < DB_COUNT; ++idx_new) |
672 | 937 if (curtab->tp_diffbuf[idx_new] != NULL) |
7 | 938 break; |
939 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
|
940 goto theend; |
7 | 941 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
942 // 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
|
943 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
|
944 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
|
945 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
946 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
|
947 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
|
948 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
949 // 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
|
950 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
|
951 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
|
952 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
953 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
954 // 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
|
955 curwin->w_valid_cursor.lnum = 0; |
7 | 956 |
14780
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
957 theend: |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
958 // 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
|
959 // 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
|
960 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
|
961 { |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
962 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
|
963 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
|
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 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
966 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
967 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
968 * 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
|
969 * 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
|
970 * 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
|
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 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
|
973 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
|
974 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
975 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
|
976 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
|
977 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
|
978 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
979 // May try twice, first with "-a" and then without. |
7 | 980 for (;;) |
981 { | |
982 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
|
983 fd = mch_fopen((char *)diffio->dio_orig.din_fname, "w"); |
1757 | 984 if (fd == NULL) |
985 io_error = TRUE; | |
986 else | |
7 | 987 { |
1757 | 988 if (fwrite("line1\n", (size_t)6, (size_t)1, fd) != 1) |
989 io_error = TRUE; | |
7 | 990 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
|
991 fd = mch_fopen((char *)diffio->dio_new.din_fname, "w"); |
1757 | 992 if (fd == NULL) |
993 io_error = TRUE; | |
994 else | |
7 | 995 { |
1757 | 996 if (fwrite("line2\n", (size_t)6, (size_t)1, fd) != 1) |
997 io_error = TRUE; | |
7 | 998 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
|
999 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
|
1000 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
|
1001 fd = mch_fopen((char *)diffio->dio_diff.dout_fname, "r"); |
1757 | 1002 if (fd == NULL) |
1003 io_error = TRUE; | |
1004 else | |
7 | 1005 { |
1006 char_u linebuf[LBUFLEN]; | |
1007 | |
1008 for (;;) | |
1009 { | |
24683
05c199ea8295
patch 8.2.2880: unified diff fails if actually used
Bram Moolenaar <Bram@vim.org>
parents:
23895
diff
changeset
|
1010 // 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
|
1011 // "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
|
1012 if (vim_fgets(linebuf, LBUFLEN, fd)) |
7 | 1013 break; |
24683
05c199ea8295
patch 8.2.2880: unified diff fails if actually used
Bram Moolenaar <Bram@vim.org>
parents:
23895
diff
changeset
|
1014 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
|
1015 || STRNCMP(linebuf, "@@ -1 +1 @@", 11) == 0) |
7 | 1016 ok = TRUE; |
1017 } | |
1018 fclose(fd); | |
1019 } | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1020 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
|
1021 mch_remove(diffio->dio_new.din_fname); |
7 | 1022 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1023 mch_remove(diffio->dio_orig.din_fname); |
7 | 1024 } |
1025 | |
1026 #ifdef FEAT_EVAL | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1027 // When using 'diffexpr' break here. |
7 | 1028 if (*p_dex != NUL) |
1029 break; | |
1030 #endif | |
1031 | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1032 #if defined(MSWIN) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1033 // If the "-a" argument works, also check if "--binary" works. |
7 | 1034 if (ok && diff_a_works == MAYBE && diff_bin_works == MAYBE) |
1035 { | |
1036 diff_a_works = TRUE; | |
1037 diff_bin_works = TRUE; | |
1038 continue; | |
1039 } | |
1040 if (!ok && diff_a_works == TRUE && diff_bin_works == TRUE) | |
1041 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1042 // Tried --binary, but it failed. "-a" works though. |
7 | 1043 diff_bin_works = FALSE; |
1044 ok = TRUE; | |
1045 } | |
1046 #endif | |
1047 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1048 // If we checked if "-a" works already, break here. |
7 | 1049 if (diff_a_works != MAYBE) |
1050 break; | |
1051 diff_a_works = ok; | |
1052 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1053 // If "-a" works break here, otherwise retry without "-a". |
7 | 1054 if (ok) |
1055 break; | |
1056 } | |
1057 if (!ok) | |
1058 { | |
1757 | 1059 if (io_error) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15103
diff
changeset
|
1060 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
|
1061 emsg(_("E97: Cannot create diffs")); |
7 | 1062 diff_a_works = MAYBE; |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1063 #if defined(MSWIN) |
7 | 1064 diff_bin_works = MAYBE; |
1065 #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
|
1066 return FAIL; |
7 | 1067 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1068 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
|
1069 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1070 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1071 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1072 * 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
|
1073 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1074 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
|
1075 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
|
1076 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1077 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
|
1078 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
|
1079 xdemitcb_t emit_cb; |
7 | 1080 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1081 CLEAR_FIELD(param); |
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1082 CLEAR_FIELD(emit_cfg); |
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1083 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
|
1084 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1085 param.flags = diff_algorithm; |
3524 | 1086 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1087 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
|
1088 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
|
1089 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
|
1090 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
|
1091 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
|
1092 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
|
1093 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
|
1094 param.flags |= XDF_IGNORE_BLANK_LINES; |
7 | 1095 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1096 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
|
1097 emit_cb.priv = &diffio->dio_diff; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1098 emit_cb.outf = xdiff_out; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1099 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
|
1100 &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
|
1101 ¶m, &emit_cfg, &emit_cb) < 0) |
7 | 1102 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15103
diff
changeset
|
1103 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
|
1104 return FAIL; |
7 | 1105 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1106 return OK; |
7 | 1107 } |
1108 | |
1109 /* | |
1110 * 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
|
1111 * return OK or FAIL; |
7 | 1112 */ |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1113 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
|
1114 diff_file(diffio_T *dio) |
7 | 1115 { |
1116 char_u *cmd; | |
1872 | 1117 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
|
1118 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
|
1119 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
|
1120 char_u *tmp_diff = dio->dio_diff.dout_fname; |
7 | 1121 |
1122 #ifdef FEAT_EVAL | |
1123 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
|
1124 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1125 // Use 'diffexpr' to generate the diff file. |
7 | 1126 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
|
1127 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
|
1128 } |
7 | 1129 else |
1130 #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
|
1131 // 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
|
1132 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
|
1133 { |
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 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
|
1135 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1136 else |
7 | 1137 { |
1872 | 1138 len = STRLEN(tmp_orig) + STRLEN(tmp_new) |
1139 + 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
|
1140 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
|
1141 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
|
1142 return FAIL; |
193 | 1143 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1144 // 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
|
1145 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
|
1146 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
|
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 // 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
|
1149 // 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
|
1150 // 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
|
1151 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
|
1152 diff_a_works == FALSE ? "" : "-a ", |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1153 #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
|
1154 diff_bin_works == TRUE ? "--binary " : "", |
7 | 1155 #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
|
1156 "", |
7 | 1157 #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
|
1158 (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
|
1159 (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
|
1160 (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
|
1161 (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
|
1162 (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
|
1163 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
|
1164 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
|
1165 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
|
1166 (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
|
1167 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
|
1168 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
|
1169 return OK; |
7 | 1170 } |
1171 } | |
1172 | |
1173 /* | |
1174 * Create a new version of a file from the current buffer and a diff file. | |
1175 * The buffer is written to a file, also for unmodified buffers (the file | |
1176 * could have been produced by autocommands, e.g. the netrw plugin). | |
1177 */ | |
1178 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1179 ex_diffpatch(exarg_T *eap) |
7 | 1180 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1181 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
|
1182 char_u *tmp_new; // name of patched temp file |
7 | 1183 char_u *buf = NULL; |
1872 | 1184 size_t buflen; |
7 | 1185 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
|
1186 char_u *newname = NULL; // name of patched file buffer |
7 | 1187 #ifdef UNIX |
1188 char_u dirbuf[MAXPATHL]; | |
1189 char_u *fullname = NULL; | |
1190 #endif | |
1191 #ifdef FEAT_BROWSE | |
1192 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
|
1193 int save_cmod_flags = cmdmod.cmod_flags; |
7 | 1194 #endif |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
8368
diff
changeset
|
1195 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
|
1196 char_u *esc_name = NULL; |
7 | 1197 |
1198 #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
|
1199 if (cmdmod.cmod_flags & CMOD_BROWSE) |
7 | 1200 { |
28 | 1201 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
|
1202 eap->arg, NULL, NULL, |
378f9f8e6d8f
patch 8.0.1773: dialog messages are not translated
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1203 (char_u *)_(BROWSE_FILTER_ALL_FILES), NULL); |
7 | 1204 if (browseFile == NULL) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1205 return; // operation cancelled |
7 | 1206 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
|
1207 cmdmod.cmod_flags &= ~CMOD_BROWSE; // don't let do_ecmd() browse again |
7 | 1208 } |
1209 #endif | |
1210 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1211 // We need two temp file names. |
6721 | 1212 tmp_orig = vim_tempname('o', FALSE); |
1213 tmp_new = vim_tempname('n', FALSE); | |
7 | 1214 if (tmp_orig == NULL || tmp_new == NULL) |
1215 goto theend; | |
1216 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1217 // Write the current buffer to "tmp_orig". |
7 | 1218 if (buf_write(curbuf, tmp_orig, NULL, |
1219 (linenr_T)1, curbuf->b_ml.ml_line_count, | |
1220 NULL, FALSE, FALSE, FALSE, TRUE) == FAIL) | |
1221 goto theend; | |
1222 | |
1223 #ifdef UNIX | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1224 // Get the absolute path of the patchfile, changing directory below. |
7 | 1225 fullname = FullName_save(eap->arg, FALSE); |
1226 #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
|
1227 esc_name = vim_strsave_shellescape( |
7 | 1228 # 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
|
1229 fullname != NULL ? fullname : |
7 | 1230 # 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
|
1231 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
|
1232 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
|
1233 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
|
1234 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
|
1235 buf = alloc(buflen); |
7 | 1236 if (buf == NULL) |
1237 goto theend; | |
1238 | |
1239 #ifdef UNIX | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1240 // 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
|
1241 // 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
|
1242 // 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
|
1243 // 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
|
1244 // return to the current. |
7 | 1245 if (mch_dirname(dirbuf, MAXPATHL) != OK || mch_chdir((char *)dirbuf) != 0) |
1246 dirbuf[0] = NUL; | |
1247 else | |
1248 { | |
1249 # ifdef TEMPDIRNAMES | |
1250 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
|
1251 vim_ignored = mch_chdir((char *)vim_tempdir); |
7 | 1252 else |
1253 # 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
|
1254 vim_ignored = mch_chdir("/tmp"); |
7 | 1255 shorten_fnames(TRUE); |
1256 } | |
1257 #endif | |
1258 | |
1259 #ifdef FEAT_EVAL | |
1260 if (*p_pex != NUL) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1261 // Use 'patchexpr' to generate the new file. |
7 | 1262 eval_patch(tmp_orig, |
1263 # ifdef UNIX | |
1264 fullname != NULL ? fullname : | |
1265 # endif | |
1266 eap->arg, tmp_new); | |
1267 else | |
1268 #endif | |
1269 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1270 // 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
|
1271 // 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
|
1272 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
|
1273 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
|
1274 block_autocmds(); // Avoid ShellCmdPost stuff |
7 | 1275 (void)call_shell(buf, SHELL_FILTER | SHELL_COOKED); |
1410 | 1276 unblock_autocmds(); |
7 | 1277 } |
1278 | |
1279 #ifdef UNIX | |
1280 if (dirbuf[0] != NUL) | |
1281 { | |
1282 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
|
1283 emsg(_(e_prev_dir)); |
7 | 1284 shorten_fnames(TRUE); |
1285 } | |
1286 #endif | |
1287 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1288 // patch probably has written over the screen |
7 | 1289 redraw_later(CLEAR); |
1290 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1291 // Delete any .orig or .rej file created. |
7 | 1292 STRCPY(buf, tmp_new); |
1293 STRCAT(buf, ".orig"); | |
1294 mch_remove(buf); | |
1295 STRCPY(buf, tmp_new); | |
1296 STRCAT(buf, ".rej"); | |
1297 mch_remove(buf); | |
1298 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1299 // Only continue if the output file was created. |
1942 | 1300 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
|
1301 emsg(_("E816: Cannot read patch output")); |
1942 | 1302 else |
7 | 1303 { |
1942 | 1304 if (curbuf->b_fname != NULL) |
1305 { | |
1306 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
|
1307 STRLEN(curbuf->b_fname) + 4); |
1942 | 1308 if (newname != NULL) |
1309 STRCAT(newname, ".new"); | |
1310 } | |
7 | 1311 |
1312 #ifdef FEAT_GUI | |
1942 | 1313 need_mouse_correct = TRUE; |
7 | 1314 #endif |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1315 // 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
|
1316 cmdmod.cmod_tab = 0; |
682 | 1317 |
1942 | 1318 if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) |
1319 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1320 // Pretend it was a ":split fname" command |
1942 | 1321 eap->cmdidx = CMD_split; |
1322 eap->arg = tmp_new; | |
1323 do_exedit(eap, old_curwin); | |
7 | 1324 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1325 // check that split worked and editing tmp_new |
1942 | 1326 if (curwin != old_curwin && win_valid(old_curwin)) |
1327 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1328 // Set 'diff', 'scrollbind' on and 'wrap' off. |
1942 | 1329 diff_win_options(curwin, TRUE); |
1330 diff_win_options(old_curwin, TRUE); | |
7 | 1331 |
1942 | 1332 if (newname != NULL) |
1333 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1334 // do a ":file filename.new" on the patched buffer |
1942 | 1335 eap->arg = newname; |
1336 ex_file(eap); | |
7 | 1337 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1338 // Do filetype detection with the new name. |
1942 | 1339 if (au_has_group((char_u *)"filetypedetect")) |
1340 do_cmdline_cmd((char_u *)":doau filetypedetect BufRead"); | |
1341 } | |
7 | 1342 } |
1343 } | |
1344 } | |
1345 | |
1346 theend: | |
1347 if (tmp_orig != NULL) | |
1348 mch_remove(tmp_orig); | |
1349 vim_free(tmp_orig); | |
1350 if (tmp_new != NULL) | |
1351 mch_remove(tmp_new); | |
1352 vim_free(tmp_new); | |
1353 vim_free(newname); | |
1354 vim_free(buf); | |
1355 #ifdef UNIX | |
1356 vim_free(fullname); | |
1357 #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
|
1358 vim_free(esc_name); |
7 | 1359 #ifdef FEAT_BROWSE |
1360 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
|
1361 cmdmod.cmod_flags = save_cmod_flags; |
7 | 1362 #endif |
1363 } | |
1364 | |
1365 /* | |
1366 * Split the window and edit another file, setting options to show the diffs. | |
1367 */ | |
1368 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1369 ex_diffsplit(exarg_T *eap) |
7 | 1370 { |
1371 win_T *old_curwin = curwin; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1372 bufref_T old_curbuf; |
7 | 1373 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1374 set_bufref(&old_curbuf, curbuf); |
7 | 1375 #ifdef FEAT_GUI |
1376 need_mouse_correct = TRUE; | |
1377 #endif | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1378 // 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
|
1379 validate_cursor(); |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1380 set_fraction(curwin); |
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1381 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1382 // 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
|
1383 cmdmod.cmod_tab = 0; |
682 | 1384 |
764 | 1385 if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) |
7 | 1386 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1387 // Pretend it was a ":split fname" command |
7 | 1388 eap->cmdidx = CMD_split; |
449 | 1389 curwin->w_p_diff = TRUE; |
7 | 1390 do_exedit(eap, old_curwin); |
1391 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1392 if (curwin != old_curwin) // split must have worked |
7 | 1393 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1394 // Set 'diff', 'scrollbind' on and 'wrap' off. |
7 | 1395 diff_win_options(curwin, TRUE); |
7338
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1396 if (win_valid(old_curwin)) |
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1397 { |
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1398 diff_win_options(old_curwin, TRUE); |
96d5dd9e7bc9
commit https://github.com/vim/vim/commit/f29a82dcd0914c76f595d475ddac4517371fab2b
Christian Brabandt <cb@256bit.org>
parents:
6985
diff
changeset
|
1399 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1400 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
|
1401 // 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
|
1402 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
|
1403 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
|
1404 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1405 // 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
|
1406 // relative position. |
10013
942d40a92be6
commit https://github.com/vim/vim/commit/46328f9a1cc8047d1e05095bc9f531038c5a4028
Christian Brabandt <cb@256bit.org>
parents:
10005
diff
changeset
|
1407 scroll_to_fraction(curwin, curwin->w_height); |
7 | 1408 } |
1409 } | |
1410 } | |
1411 | |
1412 /* | |
4352 | 1413 * Set options to show diffs for the current window. |
7 | 1414 */ |
1415 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1416 ex_diffthis(exarg_T *eap UNUSED) |
7 | 1417 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1418 // Set 'diff', 'scrollbind' on and 'wrap' off. |
7 | 1419 diff_win_options(curwin, TRUE); |
1420 } | |
1421 | |
11707
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1422 static void |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1423 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
|
1424 { |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1425 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
|
1426 |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1427 curwin = wp; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1428 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
|
1429 ++curbuf_lock; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1430 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
|
1431 --curbuf_lock; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1432 curwin = old_curwin; |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1433 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
|
1434 } |
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1435 |
7 | 1436 /* |
1437 * Set options in window "wp" for diff mode. | |
1438 */ | |
1439 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1440 diff_win_options( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1441 win_T *wp, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1442 int addbuf) // Add buffer to diff. |
7 | 1443 { |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1444 # ifdef FEAT_FOLDING |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1445 win_T *old_curwin = curwin; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1446 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1447 // close the manually opened folds |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1448 curwin = wp; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1449 newFoldLevel(); |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1450 curwin = old_curwin; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1451 # endif |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1452 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1453 // Use 'scrollbind' and 'cursorbind' when available |
6897 | 1454 if (!wp->w_p_diff) |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1455 wp->w_p_scb_save = wp->w_p_scb; |
2583 | 1456 wp->w_p_scb = TRUE; |
6897 | 1457 if (!wp->w_p_diff) |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1458 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
|
1459 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
|
1460 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
|
1461 { |
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1462 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
|
1463 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
|
1464 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
|
1465 } |
7 | 1466 # ifdef FEAT_FOLDING |
6897 | 1467 if (!wp->w_p_diff) |
1468 { | |
1469 if (wp->w_p_diff_saved) | |
1470 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
|
1471 wp->w_p_fdm_save = vim_strsave(wp->w_p_fdm); |
6897 | 1472 } |
16806
306766ed0f70
patch 8.1.1405: "highlight" option of popup windows not supported
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1473 set_string_option_direct_in_win(wp, (char_u *)"fdm", -1, (char_u *)"diff", |
694 | 1474 OPT_LOCAL|OPT_FREE, 0); |
6897 | 1475 if (!wp->w_p_diff) |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1476 { |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1477 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
|
1478 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
|
1479 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
|
1480 } |
2086
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1481 wp->w_p_fdc = diff_foldcolumn; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1482 wp->w_p_fen = TRUE; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1483 wp->w_p_fdl = 0; |
c11845a465ae
updated for version 7.2.370
Bram Moolenaar <bram@zimbu.org>
parents:
1942
diff
changeset
|
1484 foldUpdateAll(wp); |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1485 // 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
|
1486 changed_window_setting_win(wp); |
7 | 1487 # endif |
1488 if (vim_strchr(p_sbo, 'h') == NULL) | |
1489 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
|
1490 // 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
|
1491 wp->w_p_diff_saved = TRUE; |
7 | 1492 |
11707
1395a3b6978d
patch 8.0.0736: OptionSet not triggered when entering diff mode
Christian Brabandt <cb@256bit.org>
parents:
11430
diff
changeset
|
1493 set_diff_option(wp, TRUE); |
6897 | 1494 |
7 | 1495 if (addbuf) |
1496 diff_buf_add(wp->w_buffer); | |
1497 redraw_win_later(wp, NOT_VALID); | |
1498 } | |
1499 | |
1500 /* | |
16 | 1501 * Set options not to show diffs. For the current window or all windows. |
671 | 1502 * Only in the current tab page. |
16 | 1503 */ |
1504 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1505 ex_diffoff(exarg_T *eap) |
16 | 1506 { |
1507 win_T *wp; | |
1508 int diffwin = FALSE; | |
1509 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1510 FOR_ALL_WINDOWS(wp) |
16 | 1511 { |
5358 | 1512 if (eap->forceit ? wp->w_p_diff : wp == curwin) |
16 | 1513 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1514 // 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
|
1515 // 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
|
1516 // 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
|
1517 set_diff_option(wp, FALSE); |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1518 |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1519 if (wp->w_p_diff_saved) |
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1520 { |
6897 | 1521 |
1522 if (wp->w_p_scb) | |
1523 wp->w_p_scb = wp->w_p_scb_save; | |
1524 if (wp->w_p_crb) | |
1525 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
|
1526 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
|
1527 { |
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1528 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
|
1529 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
|
1530 } |
6897 | 1531 #ifdef FEAT_FOLDING |
5102
11d0c6df1d7b
updated for version 7.3.1294
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1532 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
|
1533 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
|
1534 *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
|
1535 |
6897 | 1536 if (wp->w_p_fdc == diff_foldcolumn) |
1537 wp->w_p_fdc = wp->w_p_fdc_save; | |
1538 if (wp->w_p_fdl == 0) | |
1539 wp->w_p_fdl = wp->w_p_fdl_save; | |
1540 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1541 // 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
|
1542 // "manual", otherwise we continue to show the diff folds. |
6897 | 1543 if (wp->w_p_fen) |
1544 wp->w_p_fen = foldmethodIsManual(wp) ? FALSE | |
1545 : wp->w_p_fen_save; | |
1546 | |
1547 foldUpdateAll(wp); | |
1548 #endif | |
5200
b3ff17862b4c
updated for version 7.4a.026
Bram Moolenaar <bram@vim.org>
parents:
5102
diff
changeset
|
1549 } |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1550 // remove filler lines |
10005
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1551 wp->w_topfill = 0; |
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1552 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1553 // 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
|
1554 // invalidated |
10005
4b4ba6589a98
commit https://github.com/vim/vim/commit/e67d546f3c691139e6d3d33f36724d98aec04c14
Christian Brabandt <cb@256bit.org>
parents:
9719
diff
changeset
|
1555 changed_window_setting_win(wp); |
5200
b3ff17862b4c
updated for version 7.4a.026
Bram Moolenaar <bram@vim.org>
parents:
5102
diff
changeset
|
1556 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1557 // Note: 'sbo' is not restored, it's a global option. |
16 | 1558 diff_buf_adjust(wp); |
1559 } | |
1560 diffwin |= wp->w_p_diff; | |
1561 } | |
1562 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1563 // 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
|
1564 if (eap->forceit) |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
1565 diff_buf_clear(); |
d9e48fb5142f
patch 8.0.0300: cannot stop diffing hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
1566 |
18590
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1567 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
|
1568 { |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1569 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
|
1570 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
|
1571 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
|
1572 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
|
1573 } |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1574 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1575 // Remove "hor" from from 'scrollopt' if there are no diff windows left. |
16 | 1576 if (!diffwin && vim_strchr(p_sbo, 'h') != NULL) |
1577 do_cmdline_cmd((char_u *)"set sbo-=hor"); | |
1578 } | |
1579 | |
1580 /* | |
7 | 1581 * Read the diff output and add each entry to the diff list. |
1582 */ | |
1583 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1584 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
|
1585 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
|
1586 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
|
1587 diffout_T *dout) // diff output |
7 | 1588 { |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1589 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
|
1590 int line_idx = 0; |
7 | 1591 diff_T *dprev = NULL; |
672 | 1592 diff_T *dp = curtab->tp_first_diff; |
7 | 1593 diff_T *dn, *dpl; |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1594 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
|
1595 char_u *line; |
7 | 1596 long off; |
1597 int i; | |
1598 linenr_T lnum_orig, lnum_new; | |
1599 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
|
1600 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
|
1601 enum { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1602 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
|
1603 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
|
1604 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
|
1605 } diffstyle = DIFF_NONE; |
7 | 1606 |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1607 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
|
1608 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1609 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
|
1610 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1611 else |
7 | 1612 { |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1613 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
|
1614 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
|
1615 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15103
diff
changeset
|
1616 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
|
1617 return; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1618 } |
7 | 1619 } |
1620 | |
1621 for (;;) | |
1622 { | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1623 if (fd == NULL) |
7 | 1624 { |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1625 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
|
1626 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
|
1627 line = ((char_u **)dout->dout_ga.ga_data)[line_idx++]; |
7 | 1628 } |
1629 else | |
1630 { | |
15840
734b1928a5aa
patch 8.1.0927: USE_CR is never defined
Bram Moolenaar <Bram@vim.org>
parents:
15595
diff
changeset
|
1631 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
|
1632 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
|
1633 line = linebuf; |
7 | 1634 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1635 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1636 if (diffstyle == DIFF_NONE) |
7 | 1637 { |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1638 // 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
|
1639 // 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
|
1640 // {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
|
1641 // {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
|
1642 // {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
|
1643 // |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1644 // 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
|
1645 // --- 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
|
1646 // +++ 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
|
1647 // @@ -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
|
1648 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
|
1649 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
|
1650 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
|
1651 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
|
1652 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
|
1653 && (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
|
1654 && (STRNCMP(line, "+++ ", 4) == 0) |
15840
734b1928a5aa
patch 8.1.0927: USE_CR is never defined
Bram Moolenaar <Bram@vim.org>
parents:
15595
diff
changeset
|
1655 && (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
|
1656 && (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
|
1657 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
|
1658 else |
655f00c29c58
patch 8.1.0375: cannot use diff mode with Cygwin diff.exe
Christian Brabandt <cb@256bit.org>
parents:
14716
diff
changeset
|
1659 // 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
|
1660 // 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
|
1661 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
|
1662 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1663 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1664 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
|
1665 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1666 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
|
1667 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
|
1668 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
|
1669 &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
|
1670 continue; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1671 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1672 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
|
1673 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1674 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
|
1675 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
|
1676 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
|
1677 &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
|
1678 continue; |
7 | 1679 } |
1680 else | |
1681 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15103
diff
changeset
|
1682 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
|
1683 break; |
7 | 1684 } |
1685 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1686 // 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
|
1687 // Copy blocks from orig to new. |
7 | 1688 while (dp != NULL |
1689 && lnum_orig > dp->df_lnum[idx_orig] + dp->df_count[idx_orig]) | |
1690 { | |
1691 if (notset) | |
1692 diff_copy_entry(dprev, dp, idx_orig, idx_new); | |
1693 dprev = dp; | |
1694 dp = dp->df_next; | |
1695 notset = TRUE; | |
1696 } | |
1697 | |
1698 if (dp != NULL | |
1699 && lnum_orig <= dp->df_lnum[idx_orig] + dp->df_count[idx_orig] | |
1700 && lnum_orig + count_orig >= dp->df_lnum[idx_orig]) | |
1701 { | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1702 // 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
|
1703 // First find last block that overlaps. |
7 | 1704 for (dpl = dp; dpl->df_next != NULL; dpl = dpl->df_next) |
1705 if (lnum_orig + count_orig < dpl->df_next->df_lnum[idx_orig]) | |
1706 break; | |
1707 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1708 // 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
|
1709 // start back a number of lines. |
7 | 1710 off = dp->df_lnum[idx_orig] - lnum_orig; |
1711 if (off > 0) | |
1712 { | |
1713 for (i = idx_orig; i < idx_new; ++i) | |
672 | 1714 if (curtab->tp_diffbuf[i] != NULL) |
7 | 1715 dp->df_lnum[i] -= off; |
1716 dp->df_lnum[idx_new] = lnum_new; | |
1717 dp->df_count[idx_new] = count_new; | |
1718 } | |
1719 else if (notset) | |
1720 { | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1721 // new block inside existing one, adjust new block |
7 | 1722 dp->df_lnum[idx_new] = lnum_new + off; |
1723 dp->df_count[idx_new] = count_new - off; | |
1724 } | |
1725 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
|
1726 // second overlap of new block with existing block |
1519 | 1727 dp->df_count[idx_new] += count_new - count_orig |
1728 + dpl->df_lnum[idx_orig] + dpl->df_count[idx_orig] | |
1729 - (dp->df_lnum[idx_orig] + dp->df_count[idx_orig]); | |
7 | 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 // 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
|
1732 // end of the existing block or the new diff, whatever ends last. |
7 | 1733 off = (lnum_orig + count_orig) |
1734 - (dpl->df_lnum[idx_orig] + dpl->df_count[idx_orig]); | |
1735 if (off < 0) | |
1736 { | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1737 // 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
|
1738 // done already |
7 | 1739 if (notset) |
1740 dp->df_count[idx_new] += -off; | |
1741 off = 0; | |
1742 } | |
1428 | 1743 for (i = idx_orig; i < idx_new; ++i) |
672 | 1744 if (curtab->tp_diffbuf[i] != NULL) |
7 | 1745 dp->df_count[i] = dpl->df_lnum[i] + dpl->df_count[i] |
1746 - dp->df_lnum[i] + off; | |
1747 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1748 // Delete the diff blocks that have been merged into one. |
7 | 1749 dn = dp->df_next; |
1750 dp->df_next = dpl->df_next; | |
1751 while (dn != dp->df_next) | |
1752 { | |
1753 dpl = dn->df_next; | |
1754 vim_free(dn); | |
1755 dn = dpl; | |
1756 } | |
1757 } | |
1758 else | |
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 // Allocate a new diffblock. |
672 | 1761 dp = diff_alloc_new(curtab, dprev, dp); |
7 | 1762 if (dp == NULL) |
840 | 1763 goto done; |
7 | 1764 |
1765 dp->df_lnum[idx_orig] = lnum_orig; | |
1766 dp->df_count[idx_orig] = count_orig; | |
1767 dp->df_lnum[idx_new] = lnum_new; | |
1768 dp->df_count[idx_new] = count_new; | |
1769 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1770 // 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
|
1771 // 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
|
1772 // already. |
7 | 1773 for (i = idx_orig + 1; i < idx_new; ++i) |
672 | 1774 if (curtab->tp_diffbuf[i] != NULL) |
7 | 1775 diff_copy_entry(dprev, dp, idx_orig, i); |
1776 } | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1777 notset = FALSE; // "*dp" has been set |
7 | 1778 } |
1779 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1780 // for remaining diff blocks orig and new are equal |
7 | 1781 while (dp != NULL) |
1782 { | |
1783 if (notset) | |
1784 diff_copy_entry(dprev, dp, idx_orig, idx_new); | |
1785 dprev = dp; | |
1786 dp = dp->df_next; | |
1787 notset = TRUE; | |
1788 } | |
1789 | |
840 | 1790 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
|
1791 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
|
1792 fclose(fd); |
7 | 1793 } |
1794 | |
1795 /* | |
1796 * Copy an entry at "dp" from "idx_orig" to "idx_new". | |
1797 */ | |
1798 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1799 diff_copy_entry( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1800 diff_T *dprev, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1801 diff_T *dp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1802 int idx_orig, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1803 int idx_new) |
7 | 1804 { |
1805 long off; | |
1806 | |
1807 if (dprev == NULL) | |
1808 off = 0; | |
1809 else | |
1810 off = (dprev->df_lnum[idx_orig] + dprev->df_count[idx_orig]) | |
1811 - (dprev->df_lnum[idx_new] + dprev->df_count[idx_new]); | |
1812 dp->df_lnum[idx_new] = dp->df_lnum[idx_orig] - off; | |
1813 dp->df_count[idx_new] = dp->df_count[idx_orig]; | |
1814 } | |
1815 | |
1816 /* | |
672 | 1817 * Clear the list of diffblocks for tab page "tp". |
7 | 1818 */ |
358 | 1819 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1820 diff_clear(tabpage_T *tp) |
7 | 1821 { |
1822 diff_T *p, *next_p; | |
1823 | |
672 | 1824 for (p = tp->tp_first_diff; p != NULL; p = next_p) |
7 | 1825 { |
1826 next_p = p->df_next; | |
1827 vim_free(p); | |
1828 } | |
672 | 1829 tp->tp_first_diff = NULL; |
7 | 1830 } |
1831 | |
1832 /* | |
1833 * Check diff status for line "lnum" in buffer "buf": | |
1834 * Returns 0 for nothing special | |
1835 * Returns -1 for a line that should be highlighted as changed. | |
1836 * Returns -2 for a line that should be highlighted as added/deleted. | |
1837 * Returns > 0 for inserting that many filler lines above it (never happens | |
1838 * when 'diffopt' doesn't contain "filler"). | |
1839 * This should only be used for windows where 'diff' is set. | |
1840 */ | |
1841 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1842 diff_check(win_T *wp, linenr_T lnum) |
7 | 1843 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1844 int idx; // index in tp_diffbuf[] for this buffer |
7 | 1845 diff_T *dp; |
1846 int maxcount; | |
1847 int i; | |
1848 buf_T *buf = wp->w_buffer; | |
1849 int cmp; | |
1850 | |
672 | 1851 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
|
1852 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
|
1853 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1854 if (curtab->tp_first_diff == NULL || !wp->w_p_diff) // no diffs at all |
7 | 1855 return 0; |
1856 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1857 // safety check: "lnum" must be a buffer line |
7 | 1858 if (lnum < 1 || lnum > buf->b_ml.ml_line_count + 1) |
1859 return 0; | |
1860 | |
1861 idx = diff_buf_idx(buf); | |
1862 if (idx == DB_COUNT) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1863 return 0; // no diffs for buffer "buf" |
7 | 1864 |
1865 #ifdef FEAT_FOLDING | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1866 // A closed fold never has filler lines. |
7 | 1867 if (hasFoldingWin(wp, lnum, NULL, NULL, TRUE, NULL)) |
1868 return 0; | |
1869 #endif | |
1870 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1871 // 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
|
1872 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) |
7 | 1873 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
1874 break; | |
1875 if (dp == NULL || lnum < dp->df_lnum[idx]) | |
1876 return 0; | |
1877 | |
1878 if (lnum < dp->df_lnum[idx] + dp->df_count[idx]) | |
1879 { | |
1880 int zero = FALSE; | |
1881 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1882 // 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
|
1883 // 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
|
1884 // count, check if the lines are identical. |
7 | 1885 cmp = FALSE; |
1886 for (i = 0; i < DB_COUNT; ++i) | |
672 | 1887 if (i != idx && curtab->tp_diffbuf[i] != NULL) |
7 | 1888 { |
1889 if (dp->df_count[i] == 0) | |
1890 zero = TRUE; | |
1891 else | |
1892 { | |
1893 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
|
1894 return -1; // nr of lines changed. |
7 | 1895 cmp = TRUE; |
1896 } | |
1897 } | |
1898 if (cmp) | |
1899 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1900 // 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
|
1901 // in some buffers, deleted in others, but not changed. |
7 | 1902 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
|
1903 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
|
1904 && dp->df_count[i] != 0) |
7 | 1905 if (!diff_equal_entry(dp, idx, i)) |
1906 return -1; | |
1907 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1908 // 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
|
1909 // 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
|
1910 // 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
|
1911 // 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
|
1912 // windows might still show the change though. |
7 | 1913 if (zero == FALSE) |
1914 return 0; | |
1915 return -2; | |
1916 } | |
1917 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1918 // If 'diffopt' doesn't contain "filler", return 0. |
7 | 1919 if (!(diff_flags & DIFF_FILLER)) |
1920 return 0; | |
1921 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1922 // 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
|
1923 // 0 when this buf had the max count. |
7 | 1924 maxcount = 0; |
1925 for (i = 0; i < DB_COUNT; ++i) | |
672 | 1926 if (curtab->tp_diffbuf[i] != NULL && dp->df_count[i] > maxcount) |
7 | 1927 maxcount = dp->df_count[i]; |
1928 return maxcount - dp->df_count[idx]; | |
1929 } | |
1930 | |
1931 /* | |
1932 * Compare two entries in diff "*dp" and return TRUE if they are equal. | |
1933 */ | |
1934 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1935 diff_equal_entry(diff_T *dp, int idx1, int idx2) |
7 | 1936 { |
1937 int i; | |
1938 char_u *line; | |
1939 int cmp; | |
1940 | |
1941 if (dp->df_count[idx1] != dp->df_count[idx2]) | |
1942 return FALSE; | |
672 | 1943 if (diff_check_sanity(curtab, dp) == FAIL) |
7 | 1944 return FALSE; |
1945 for (i = 0; i < dp->df_count[idx1]; ++i) | |
1946 { | |
672 | 1947 line = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx1], |
7 | 1948 dp->df_lnum[idx1] + i, FALSE)); |
1949 if (line == NULL) | |
1950 return FALSE; | |
672 | 1951 cmp = diff_cmp(line, ml_get_buf(curtab->tp_diffbuf[idx2], |
7 | 1952 dp->df_lnum[idx2] + i, FALSE)); |
1953 vim_free(line); | |
1954 if (cmp != 0) | |
1955 return FALSE; | |
1956 } | |
1957 return TRUE; | |
1958 } | |
1959 | |
1960 /* | |
12333
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1961 * 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
|
1962 * 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
|
1963 */ |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1964 static int |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1965 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
|
1966 { |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1967 int l = (*mb_ptr2len)(p1); |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1968 |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1969 if (l != (*mb_ptr2len)(p2)) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1970 return FALSE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1971 if (l > 1) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1972 { |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1973 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
|
1974 && (!enc_utf8 |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1975 || !(diff_flags & DIFF_ICASE) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1976 || utf_fold(utf_ptr2char(p1)) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1977 != utf_fold(utf_ptr2char(p2)))) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1978 return FALSE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1979 *len = l; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1980 } |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1981 else |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1982 { |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1983 if ((*p1 != *p2) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1984 && (!(diff_flags & DIFF_ICASE) |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1985 || 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
|
1986 return FALSE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1987 *len = 1; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1988 } |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1989 return TRUE; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
1990 } |
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 /* |
7 | 1993 * Compare strings "s1" and "s2" according to 'diffopt'. |
1994 * Return non-zero when they are different. | |
1995 */ | |
1996 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1997 diff_cmp(char_u *s1, char_u *s2) |
7 | 1998 { |
1999 char_u *p1, *p2; | |
2000 int l; | |
2001 | |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2002 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
|
2003 && (*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
|
2004 return 0; |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2005 |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2006 if ((diff_flags & (DIFF_ICASE | ALL_WHITE_DIFF)) == 0) |
7 | 2007 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
|
2008 if ((diff_flags & DIFF_ICASE) && !(diff_flags & ALL_WHITE_DIFF)) |
7 | 2009 return MB_STRICMP(s1, s2); |
2010 | |
2011 p1 = s1; | |
2012 p2 = s2; | |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2013 |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2014 // Ignore white space changes and possibly ignore case. |
7 | 2015 while (*p1 != NUL && *p2 != NUL) |
2016 { | |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2017 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
|
2018 && 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
|
2019 || ((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
|
2020 && (VIM_ISWHITE(*p1) || VIM_ISWHITE(*p2)))) |
7 | 2021 { |
2022 p1 = skipwhite(p1); | |
2023 p2 = skipwhite(p2); | |
2024 } | |
2025 else | |
2026 { | |
12333
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2027 if (!diff_equal_char(p1, p2, &l)) |
7 | 2028 break; |
12333
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2029 p1 += l; |
dea5dda9ef30
patch 8.0.1046: code duplication in diff mode
Christian Brabandt <cb@256bit.org>
parents:
12315
diff
changeset
|
2030 p2 += l; |
7 | 2031 } |
2032 } | |
2033 | |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2034 // Ignore trailing white space. |
7 | 2035 p1 = skipwhite(p1); |
2036 p2 = skipwhite(p2); | |
2037 if (*p1 != NUL || *p2 != NUL) | |
2038 return 1; | |
2039 return 0; | |
2040 } | |
2041 | |
2042 /* | |
2043 * Return the number of filler lines above "lnum". | |
2044 */ | |
2045 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2046 diff_check_fill(win_T *wp, linenr_T lnum) |
7 | 2047 { |
2048 int n; | |
2049 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2050 // be quick when there are no filler lines |
7 | 2051 if (!(diff_flags & DIFF_FILLER)) |
2052 return 0; | |
2053 n = diff_check(wp, lnum); | |
2054 if (n <= 0) | |
2055 return 0; | |
2056 return n; | |
2057 } | |
2058 | |
2059 /* | |
2060 * Set the topline of "towin" to match the position in "fromwin", so that they | |
2061 * show the same diff'ed lines. | |
2062 */ | |
2063 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2064 diff_set_topline(win_T *fromwin, win_T *towin) |
7 | 2065 { |
1519 | 2066 buf_T *frombuf = fromwin->w_buffer; |
7 | 2067 linenr_T lnum = fromwin->w_topline; |
1519 | 2068 int fromidx; |
2069 int toidx; | |
7 | 2070 diff_T *dp; |
1519 | 2071 int max_count; |
7 | 2072 int i; |
2073 | |
1519 | 2074 fromidx = diff_buf_idx(frombuf); |
2075 if (fromidx == DB_COUNT) | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2076 return; // safety check |
7 | 2077 |
672 | 2078 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
|
2079 ex_diffupdate(NULL); // update after a big change |
7 | 2080 |
2081 towin->w_topfill = 0; | |
2082 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2083 // 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
|
2084 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) |
1519 | 2085 if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx]) |
7 | 2086 break; |
2087 if (dp == NULL) | |
2088 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2089 // 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
|
2090 // filler lines. |
7 | 2091 towin->w_topline = towin->w_buffer->b_ml.ml_line_count |
1519 | 2092 - (frombuf->b_ml.ml_line_count - lnum); |
7 | 2093 } |
2094 else | |
2095 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2096 // Find index for "towin". |
1519 | 2097 toidx = diff_buf_idx(towin->w_buffer); |
2098 if (toidx == 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 |
1519 | 2101 towin->w_topline = lnum + (dp->df_lnum[toidx] - dp->df_lnum[fromidx]); |
2102 if (lnum >= dp->df_lnum[fromidx]) | |
7 | 2103 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2104 // 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
|
2105 // buffers we need to know the largest count. |
1519 | 2106 max_count = 0; |
2107 for (i = 0; i < DB_COUNT; ++i) | |
2108 if (curtab->tp_diffbuf[i] != NULL | |
2109 && max_count < dp->df_count[i]) | |
2110 max_count = dp->df_count[i]; | |
2111 | |
2112 if (dp->df_count[toidx] == dp->df_count[fromidx]) | |
2113 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2114 // same number of lines: use same filler count |
7 | 2115 towin->w_topfill = fromwin->w_topfill; |
1519 | 2116 } |
2117 else if (dp->df_count[toidx] > dp->df_count[fromidx]) | |
7 | 2118 { |
1519 | 2119 if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) |
2120 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2121 // 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
|
2122 // lines, only filler lines |
1519 | 2123 if (max_count - fromwin->w_topfill >= dp->df_count[toidx]) |
2124 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2125 // towin also only shows filler lines |
1519 | 2126 towin->w_topline = dp->df_lnum[toidx] |
2127 + dp->df_count[toidx]; | |
2128 towin->w_topfill = fromwin->w_topfill; | |
2129 } | |
2130 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2131 // towin still has some diff lines to show |
1519 | 2132 towin->w_topline = dp->df_lnum[toidx] |
2133 + max_count - fromwin->w_topfill; | |
2134 } | |
7 | 2135 } |
1519 | 2136 else if (towin->w_topline >= dp->df_lnum[toidx] |
2137 + dp->df_count[toidx]) | |
7 | 2138 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2139 // 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
|
2140 // filler lines |
1519 | 2141 towin->w_topline = dp->df_lnum[toidx] + dp->df_count[toidx]; |
2142 if (diff_flags & DIFF_FILLER) | |
7 | 2143 { |
1519 | 2144 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
|
2145 // fromwin is also out of diff lines |
1519 | 2146 towin->w_topfill = fromwin->w_topfill; |
2147 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2148 // fromwin has some diff lines |
1519 | 2149 towin->w_topfill = dp->df_lnum[fromidx] |
2150 + max_count - lnum; | |
7 | 2151 } |
2152 } | |
2153 } | |
2154 } | |
2155 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2156 // safety check (if diff info gets outdated strange things may happen) |
7 | 2157 towin->w_botfill = FALSE; |
2158 if (towin->w_topline > towin->w_buffer->b_ml.ml_line_count) | |
2159 { | |
2160 towin->w_topline = towin->w_buffer->b_ml.ml_line_count; | |
2161 towin->w_botfill = TRUE; | |
2162 } | |
2163 if (towin->w_topline < 1) | |
2164 { | |
2165 towin->w_topline = 1; | |
2166 towin->w_topfill = 0; | |
2167 } | |
2168 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2169 // When w_topline changes need to recompute w_botline and cursor position |
7 | 2170 invalidate_botline_win(towin); |
2171 changed_line_abv_curs_win(towin); | |
2172 | |
2173 check_topfill(towin, FALSE); | |
2174 #ifdef FEAT_FOLDING | |
2175 (void)hasFoldingWin(towin, towin->w_topline, &towin->w_topline, | |
2176 NULL, TRUE, NULL); | |
2177 #endif | |
2178 } | |
2179 | |
2180 /* | |
2181 * This is called when 'diffopt' is changed. | |
2182 */ | |
2183 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2184 diffopt_changed(void) |
7 | 2185 { |
2186 char_u *p; | |
2187 int diff_context_new = 6; | |
2188 int diff_flags_new = 0; | |
764 | 2189 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
|
2190 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
|
2191 long diff_indent_heuristic = 0; |
672 | 2192 tabpage_T *tp; |
7 | 2193 |
2194 p = p_dip; | |
2195 while (*p != NUL) | |
2196 { | |
2197 if (STRNCMP(p, "filler", 6) == 0) | |
2198 { | |
2199 p += 6; | |
2200 diff_flags_new |= DIFF_FILLER; | |
2201 } | |
2202 else if (STRNCMP(p, "context:", 8) == 0 && VIM_ISDIGIT(p[8])) | |
2203 { | |
2204 p += 8; | |
2205 diff_context_new = getdigits(&p); | |
2206 } | |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2207 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
|
2208 { |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2209 p += 6; |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2210 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
|
2211 } |
7 | 2212 else if (STRNCMP(p, "icase", 5) == 0) |
2213 { | |
2214 p += 5; | |
2215 diff_flags_new |= DIFF_ICASE; | |
2216 } | |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2217 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
|
2218 { |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2219 p += 9; |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2220 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
|
2221 } |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2222 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
|
2223 { |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2224 p += 9; |
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2225 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
|
2226 } |
7 | 2227 else if (STRNCMP(p, "iwhite", 6) == 0) |
2228 { | |
2229 p += 6; | |
2230 diff_flags_new |= DIFF_IWHITE; | |
2231 } | |
764 | 2232 else if (STRNCMP(p, "horizontal", 10) == 0) |
2233 { | |
2234 p += 10; | |
2235 diff_flags_new |= DIFF_HORIZONTAL; | |
2236 } | |
2237 else if (STRNCMP(p, "vertical", 8) == 0) | |
2238 { | |
2239 p += 8; | |
2240 diff_flags_new |= DIFF_VERTICAL; | |
2241 } | |
2242 else if (STRNCMP(p, "foldcolumn:", 11) == 0 && VIM_ISDIGIT(p[11])) | |
2243 { | |
2244 p += 11; | |
2245 diff_foldcolumn_new = getdigits(&p); | |
2246 } | |
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
|
2247 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
|
2248 { |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2249 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
|
2250 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
|
2251 } |
18590
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2252 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
|
2253 { |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2254 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
|
2255 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
|
2256 } |
23895
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
2257 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
|
2258 { |
e313b6ee2d9c
patch 8.2.2490: 'wrap' option is always reset when starting diff mode
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
2259 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
|
2260 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
|
2261 } |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2262 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
|
2263 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2264 p += 16; |
15103
9339601e7a31
patch 8.1.0562: parsing of 'diffopt' is slightly wrong
Bram Moolenaar <Bram@vim.org>
parents:
15004
diff
changeset
|
2265 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
|
2266 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2267 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
|
2268 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2269 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
|
2270 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
|
2271 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2272 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
|
2273 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2274 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
|
2275 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
|
2276 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2277 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
|
2278 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
|
2279 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2280 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
|
2281 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2282 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
|
2283 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
|
2284 } |
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, "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
|
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 += 8; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2288 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
|
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, "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
|
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 += 9; |
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_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
|
2294 } |
15004
9c2352253376
patch 8.1.0513: no error for set diffopt+=algorithm:
Bram Moolenaar <Bram@vim.org>
parents:
14982
diff
changeset
|
2295 else |
9c2352253376
patch 8.1.0513: no error for set diffopt+=algorithm:
Bram Moolenaar <Bram@vim.org>
parents:
14982
diff
changeset
|
2296 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
|
2297 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
2298 |
7 | 2299 if (*p != ',' && *p != NUL) |
2300 return FAIL; | |
2301 if (*p == ',') | |
2302 ++p; | |
2303 } | |
2304 | |
15103
9339601e7a31
patch 8.1.0562: parsing of 'diffopt' is slightly wrong
Bram Moolenaar <Bram@vim.org>
parents:
15004
diff
changeset
|
2305 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
|
2306 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2307 // Can't have both "horizontal" and "vertical". |
764 | 2308 if ((diff_flags_new & DIFF_HORIZONTAL) && (diff_flags_new & DIFF_VERTICAL)) |
2309 return FAIL; | |
2310 | |
14780
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
2311 // 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
|
2312 // 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
|
2313 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
|
2314 FOR_ALL_TABPAGES(tp) |
672 | 2315 tp->tp_diff_invalid = TRUE; |
7 | 2316 |
2317 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
|
2318 diff_context = diff_context_new == 0 ? 1 : diff_context_new; |
764 | 2319 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
|
2320 diff_algorithm = diff_algorithm_new; |
7 | 2321 |
2322 diff_redraw(TRUE); | |
2323 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2324 // 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
|
2325 // remove or add filler lines |
7 | 2326 check_scrollbind((linenr_T)0, 0L); |
2327 | |
2328 return OK; | |
2329 } | |
2330 | |
2331 /* | |
764 | 2332 * Return TRUE if 'diffopt' contains "horizontal". |
2333 */ | |
2334 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2335 diffopt_horizontal(void) |
764 | 2336 { |
2337 return (diff_flags & DIFF_HORIZONTAL) != 0; | |
2338 } | |
2339 | |
2340 /* | |
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
|
2341 * 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
|
2342 */ |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2343 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
|
2344 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
|
2345 { |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2346 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
|
2347 } |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2348 |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12353
diff
changeset
|
2349 /* |
18590
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2350 * 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
|
2351 */ |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2352 int |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2353 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
|
2354 { |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2355 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
|
2356 } |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2357 |
41484f342f80
patch 8.1.2289: after :diffsplit closing the window does not disable diff
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2358 /* |
7 | 2359 * Find the difference within a changed line. |
2360 * Returns TRUE if the line was added, no other buffer has it. | |
2361 */ | |
2362 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2363 diff_find_change( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2364 win_T *wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2365 linenr_T lnum, |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2366 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
|
2367 int *endp) // last char of the change |
7 | 2368 { |
2369 char_u *line_org; | |
2370 char_u *line_new; | |
2371 int i; | |
829 | 2372 int si_org, si_new; |
2373 int ei_org, ei_new; | |
7 | 2374 diff_T *dp; |
2375 int idx; | |
2376 int off; | |
2377 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
|
2378 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
|
2379 int l; |
7 | 2380 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2381 // Make a copy of the line, the next ml_get() will invalidate it. |
7 | 2382 line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE)); |
2383 if (line_org == NULL) | |
2384 return FALSE; | |
2385 | |
2386 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
|
2387 if (idx == DB_COUNT) // cannot happen |
1074 | 2388 { |
2389 vim_free(line_org); | |
7 | 2390 return FALSE; |
1074 | 2391 } |
7 | 2392 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2393 // 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
|
2394 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) |
7 | 2395 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
2396 break; | |
672 | 2397 if (dp == NULL || diff_check_sanity(curtab, dp) == FAIL) |
1074 | 2398 { |
2399 vim_free(line_org); | |
7 | 2400 return FALSE; |
1074 | 2401 } |
7 | 2402 |
2403 off = lnum - dp->df_lnum[idx]; | |
2404 | |
2405 for (i = 0; i < DB_COUNT; ++i) | |
672 | 2406 if (curtab->tp_diffbuf[i] != NULL && i != idx) |
7 | 2407 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2408 // Skip lines that are not in the other change (filler lines). |
7 | 2409 if (off >= dp->df_count[i]) |
2410 continue; | |
2411 added = FALSE; | |
829 | 2412 line_new = ml_get_buf(curtab->tp_diffbuf[i], |
2413 dp->df_lnum[i] + off, FALSE); | |
7 | 2414 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2415 // Search for start of difference |
829 | 2416 si_org = si_new = 0; |
2417 while (line_org[si_org] != NUL) | |
2418 { | |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2419 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
|
2420 && 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
|
2421 && 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
|
2422 || ((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
|
2423 && (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
|
2424 || VIM_ISWHITE(line_new[si_new])))) |
829 | 2425 { |
835 | 2426 si_org = (int)(skipwhite(line_org + si_org) - line_org); |
2427 si_new = (int)(skipwhite(line_new + si_new) - line_new); | |
829 | 2428 } |
2429 else | |
2430 { | |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2431 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
|
2432 &l)) |
829 | 2433 break; |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2434 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
|
2435 si_new += l; |
829 | 2436 } |
2437 } | |
7 | 2438 if (has_mbyte) |
2439 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2440 // 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
|
2441 // have "nn^" in line_org and "n^ in line_new). |
829 | 2442 si_org -= (*mb_head_off)(line_org, line_org + si_org); |
2443 si_new -= (*mb_head_off)(line_new, line_new + si_new); | |
7 | 2444 } |
829 | 2445 if (*startp > si_org) |
2446 *startp = si_org; | |
7 | 2447 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2448 // Search for end of difference, if any. |
829 | 2449 if (line_org[si_org] != NUL || line_new[si_new] != NUL) |
7 | 2450 { |
2451 ei_org = (int)STRLEN(line_org); | |
2452 ei_new = (int)STRLEN(line_new); | |
829 | 2453 while (ei_org >= *startp && ei_new >= si_new |
2454 && ei_org >= 0 && ei_new >= 0) | |
7 | 2455 { |
14762
b43ea03bb522
patch 8.1.0393: not all white space difference options available
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
2456 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
|
2457 && 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
|
2458 && 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
|
2459 || ((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
|
2460 && (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
|
2461 || VIM_ISWHITE(line_new[ei_new])))) |
829 | 2462 { |
2463 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
|
2464 && VIM_ISWHITE(line_org[ei_org])) |
829 | 2465 --ei_org; |
2466 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
|
2467 && VIM_ISWHITE(line_new[ei_new])) |
829 | 2468 --ei_new; |
2469 } | |
2470 else | |
2471 { | |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2472 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
|
2473 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
|
2474 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
|
2475 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
|
2476 if (!diff_equal_char(p1, p2, &l)) |
829 | 2477 break; |
12315
40ee9f3d265f
patch 8.0.1037: "icase" of 'diffopt' is not used for highlighting
Christian Brabandt <cb@256bit.org>
parents:
11707
diff
changeset
|
2478 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
|
2479 ei_new -= l; |
829 | 2480 } |
7 | 2481 } |
2482 if (*endp < ei_org) | |
2483 *endp = ei_org; | |
2484 } | |
2485 } | |
2486 | |
2487 vim_free(line_org); | |
2488 return added; | |
2489 } | |
2490 | |
2491 #if defined(FEAT_FOLDING) || defined(PROTO) | |
2492 /* | |
2493 * Return TRUE if line "lnum" is not close to a diff block, this line should | |
2494 * be in a fold. | |
2495 * Return FALSE if there are no diff blocks at all in this window. | |
2496 */ | |
2497 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2498 diff_infold(win_T *wp, linenr_T lnum) |
7 | 2499 { |
2500 int i; | |
2501 int idx = -1; | |
2502 int other = FALSE; | |
2503 diff_T *dp; | |
2504 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2505 // Return if 'diff' isn't set. |
7 | 2506 if (!wp->w_p_diff) |
2507 return FALSE; | |
2508 | |
2509 for (i = 0; i < DB_COUNT; ++i) | |
2510 { | |
672 | 2511 if (curtab->tp_diffbuf[i] == wp->w_buffer) |
7 | 2512 idx = i; |
672 | 2513 else if (curtab->tp_diffbuf[i] != NULL) |
7 | 2514 other = TRUE; |
2515 } | |
2516 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2517 // return here if there are no diffs in the window |
7 | 2518 if (idx == -1 || !other) |
2519 return FALSE; | |
2520 | |
672 | 2521 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
|
2522 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
|
2523 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2524 // Return if there are no diff blocks. All lines will be folded. |
672 | 2525 if (curtab->tp_first_diff == NULL) |
7 | 2526 return TRUE; |
2527 | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
18777
diff
changeset
|
2528 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) |
7 | 2529 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2530 // If this change is below the line there can't be any further match. |
7 | 2531 if (dp->df_lnum[idx] - diff_context > lnum) |
2532 break; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2533 // If this change ends before the line we have a match. |
7 | 2534 if (dp->df_lnum[idx] + dp->df_count[idx] + diff_context > lnum) |
2535 return FALSE; | |
2536 } | |
2537 return TRUE; | |
2538 } | |
2539 #endif | |
2540 | |
2541 /* | |
2542 * "dp" and "do" commands. | |
2543 */ | |
2544 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2545 nv_diffgetput(int put, long count) |
7 | 2546 { |
2547 exarg_T ea; | |
6314 | 2548 char_u buf[30]; |
7 | 2549 |
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
|
2550 #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
|
2551 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
|
2552 { |
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
|
2553 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
|
2554 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
|
2555 } |
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
|
2556 #endif |
6314 | 2557 if (count == 0) |
2558 ea.arg = (char_u *)""; | |
2559 else | |
2560 { | |
2561 vim_snprintf((char *)buf, 30, "%ld", count); | |
2562 ea.arg = buf; | |
2563 } | |
7 | 2564 if (put) |
2565 ea.cmdidx = CMD_diffput; | |
2566 else | |
2567 ea.cmdidx = CMD_diffget; | |
2568 ea.addr_count = 0; | |
2569 ea.line1 = curwin->w_cursor.lnum; | |
2570 ea.line2 = curwin->w_cursor.lnum; | |
2571 ex_diffgetput(&ea); | |
2572 } | |
2573 | |
2574 /* | |
2575 * ":diffget" | |
2576 * ":diffput" | |
2577 */ | |
2578 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2579 ex_diffgetput(exarg_T *eap) |
7 | 2580 { |
2581 linenr_T lnum; | |
2582 int count; | |
2583 linenr_T off = 0; | |
2584 diff_T *dp; | |
2585 diff_T *dprev; | |
2586 diff_T *dfree; | |
2587 int idx_cur; | |
2588 int idx_other; | |
2589 int idx_from; | |
2590 int idx_to; | |
2591 int i; | |
2592 int added; | |
2593 char_u *p; | |
2594 aco_save_T aco; | |
2595 buf_T *buf; | |
2596 int start_skip, end_skip; | |
2597 int new_count; | |
648 | 2598 int buf_empty; |
1075 | 2599 int found_not_ma = FALSE; |
7 | 2600 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2601 // Find the current buffer in the list of diff buffers. |
7 | 2602 idx_cur = diff_buf_idx(curbuf); |
2603 if (idx_cur == DB_COUNT) | |
2604 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15103
diff
changeset
|
2605 emsg(_("E99: Current buffer is not in diff mode")); |
7 | 2606 return; |
2607 } | |
2608 | |
2609 if (*eap->arg == NUL) | |
2610 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2611 // No argument: Find the other buffer in the list of diff buffers. |
7 | 2612 for (idx_other = 0; idx_other < DB_COUNT; ++idx_other) |
672 | 2613 if (curtab->tp_diffbuf[idx_other] != curbuf |
1075 | 2614 && curtab->tp_diffbuf[idx_other] != NULL) |
2615 { | |
2616 if (eap->cmdidx != CMD_diffput | |
2617 || curtab->tp_diffbuf[idx_other]->b_p_ma) | |
2618 break; | |
2619 found_not_ma = TRUE; | |
2620 } | |
7 | 2621 if (idx_other == DB_COUNT) |
2622 { | |
1075 | 2623 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
|
2624 emsg(_("E793: No other buffer in diff mode is modifiable")); |
1075 | 2625 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15103
diff
changeset
|
2626 emsg(_("E100: No other buffer in diff mode")); |
7 | 2627 return; |
2628 } | |
2629 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2630 // Check that there isn't a third buffer in the list |
7 | 2631 for (i = idx_other + 1; i < DB_COUNT; ++i) |
672 | 2632 if (curtab->tp_diffbuf[i] != curbuf |
2633 && curtab->tp_diffbuf[i] != NULL | |
2634 && (eap->cmdidx != CMD_diffput || curtab->tp_diffbuf[i]->b_p_ma)) | |
7 | 2635 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15103
diff
changeset
|
2636 emsg(_("E101: More than two buffers in diff mode, don't know which one to use")); |
7 | 2637 return; |
2638 } | |
2639 } | |
2640 else | |
2641 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2642 // Buffer number or pattern given. Ignore trailing white space. |
7 | 2643 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
|
2644 while (p > eap->arg && VIM_ISWHITE(p[-1])) |
7 | 2645 --p; |
2646 for (i = 0; vim_isdigit(eap->arg[i]) && eap->arg + i < p; ++i) | |
2647 ; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2648 if (eap->arg + i == p) // digits only |
7 | 2649 i = atol((char *)eap->arg); |
2650 else | |
2651 { | |
4236 | 2652 i = buflist_findpat(eap->arg, p, FALSE, TRUE, FALSE); |
7 | 2653 if (i < 0) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2654 return; // error message already given |
7 | 2655 } |
2656 buf = buflist_findnr(i); | |
2657 if (buf == NULL) | |
2658 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15103
diff
changeset
|
2659 semsg(_("E102: Can't find buffer \"%s\""), eap->arg); |
7 | 2660 return; |
2661 } | |
1788 | 2662 if (buf == curbuf) |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2663 return; // nothing to do |
7 | 2664 idx_other = diff_buf_idx(buf); |
2665 if (idx_other == DB_COUNT) | |
2666 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15103
diff
changeset
|
2667 semsg(_("E103: Buffer \"%s\" is not in diff mode"), eap->arg); |
7 | 2668 return; |
2669 } | |
2670 } | |
2671 | |
2672 diff_busy = TRUE; | |
2673 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2674 // When no range given include the line above or below the cursor. |
7 | 2675 if (eap->addr_count == 0) |
2676 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2677 // 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
|
2678 // the cursor line when there is no difference above the cursor. |
7 | 2679 if (eap->cmdidx == CMD_diffget |
2680 && eap->line1 == curbuf->b_ml.ml_line_count | |
2681 && diff_check(curwin, eap->line1) == 0 | |
2682 && (eap->line1 == 1 || diff_check(curwin, eap->line1 - 1) == 0)) | |
2683 ++eap->line2; | |
2684 else if (eap->line1 > 0) | |
2685 --eap->line1; | |
2686 } | |
2687 | |
2688 if (eap->cmdidx == CMD_diffget) | |
2689 { | |
2690 idx_from = idx_other; | |
2691 idx_to = idx_cur; | |
2692 } | |
2693 else | |
2694 { | |
2695 idx_from = idx_cur; | |
2696 idx_to = idx_other; | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2697 // 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
|
2698 // changes in it. |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2699 // set curwin/curbuf to buf and save a few things |
672 | 2700 aucmd_prepbuf(&aco, curtab->tp_diffbuf[idx_other]); |
7 | 2701 } |
2702 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2703 // 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
|
2704 // 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
|
2705 // everything up. |
819 | 2706 if (!curbuf->b_changed) |
2707 { | |
2708 change_warning(0); | |
2709 if (diff_buf_idx(curbuf) != idx_to) | |
2710 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15103
diff
changeset
|
2711 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
|
2712 goto theend; |
819 | 2713 } |
2714 } | |
2715 | |
7 | 2716 dprev = NULL; |
672 | 2717 for (dp = curtab->tp_first_diff; dp != NULL; ) |
7 | 2718 { |
2719 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
|
2720 break; // past the range that was specified |
7 | 2721 |
2722 dfree = NULL; | |
2723 lnum = dp->df_lnum[idx_to]; | |
2724 count = dp->df_count[idx_to]; | |
2725 if (dp->df_lnum[idx_cur] + dp->df_count[idx_cur] > eap->line1 + off | |
2726 && u_save(lnum - 1, lnum + count) != FAIL) | |
2727 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2728 // Inside the specified range and saving for undo worked. |
7 | 2729 start_skip = 0; |
2730 end_skip = 0; | |
2731 if (eap->addr_count > 0) | |
2732 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2733 // A range was specified: check if lines need to be skipped. |
7 | 2734 start_skip = eap->line1 + off - dp->df_lnum[idx_cur]; |
2735 if (start_skip > 0) | |
2736 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2737 // range starts below start of current diff block |
7 | 2738 if (start_skip > count) |
2739 { | |
2740 lnum += count; | |
2741 count = 0; | |
2742 } | |
2743 else | |
2744 { | |
2745 count -= start_skip; | |
2746 lnum += start_skip; | |
2747 } | |
2748 } | |
2749 else | |
2750 start_skip = 0; | |
2751 | |
2752 end_skip = dp->df_lnum[idx_cur] + dp->df_count[idx_cur] - 1 | |
2753 - (eap->line2 + off); | |
2754 if (end_skip > 0) | |
2755 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2756 // 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
|
2757 if (idx_cur == idx_from) // :diffput |
7 | 2758 { |
2759 i = dp->df_count[idx_cur] - start_skip - end_skip; | |
2760 if (count > i) | |
2761 count = i; | |
2762 } | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2763 else // :diffget |
7 | 2764 { |
2765 count -= end_skip; | |
2766 end_skip = dp->df_count[idx_from] - start_skip - count; | |
2767 if (end_skip < 0) | |
2768 end_skip = 0; | |
2769 } | |
2770 } | |
2771 else | |
2772 end_skip = 0; | |
2773 } | |
2774 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11113
diff
changeset
|
2775 buf_empty = BUFEMPTY(); |
7 | 2776 added = 0; |
2777 for (i = 0; i < count; ++i) | |
2778 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2779 // remember deleting the last line of the buffer |
648 | 2780 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
|
2781 ml_delete(lnum); |
7 | 2782 --added; |
2783 } | |
2784 for (i = 0; i < dp->df_count[idx_from] - start_skip - end_skip; ++i) | |
2785 { | |
2786 linenr_T nr; | |
2787 | |
2788 nr = dp->df_lnum[idx_from] + start_skip + i; | |
672 | 2789 if (nr > curtab->tp_diffbuf[idx_from]->b_ml.ml_line_count) |
7 | 2790 break; |
819 | 2791 p = vim_strsave(ml_get_buf(curtab->tp_diffbuf[idx_from], |
2792 nr, FALSE)); | |
7 | 2793 if (p != NULL) |
2794 { | |
2795 ml_append(lnum + i - 1, p, 0, FALSE); | |
2796 vim_free(p); | |
2797 ++added; | |
648 | 2798 if (buf_empty && curbuf->b_ml.ml_line_count == 2) |
2799 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2800 // 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
|
2801 // delete the dummy empty line. |
648 | 2802 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
|
2803 ml_delete((linenr_T)2); |
648 | 2804 } |
7 | 2805 } |
2806 } | |
2807 new_count = dp->df_count[idx_to] + added; | |
2808 dp->df_count[idx_to] = new_count; | |
2809 | |
2810 if (start_skip == 0 && end_skip == 0) | |
2811 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2812 // 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
|
2813 // equal in them. |
7 | 2814 for (i = 0; i < DB_COUNT; ++i) |
819 | 2815 if (curtab->tp_diffbuf[i] != NULL && i != idx_from |
2816 && i != idx_to | |
7 | 2817 && !diff_equal_entry(dp, idx_from, i)) |
2818 break; | |
2819 if (i == DB_COUNT) | |
2820 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2821 // delete the diff entry, the buffers are now equal here |
7 | 2822 dfree = dp; |
2823 dp = dp->df_next; | |
2824 if (dprev == NULL) | |
672 | 2825 curtab->tp_first_diff = dp; |
7 | 2826 else |
2827 dprev->df_next = dp; | |
2828 } | |
2829 } | |
2830 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2831 // Adjust marks. This will change the following entries! |
7 | 2832 if (added != 0) |
2833 { | |
2834 mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added); | |
2835 if (curwin->w_cursor.lnum >= lnum) | |
2836 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2837 // 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
|
2838 // lines. |
7 | 2839 if (curwin->w_cursor.lnum >= lnum + count) |
2840 curwin->w_cursor.lnum += added; | |
2841 else if (added < 0) | |
2842 curwin->w_cursor.lnum = lnum; | |
2843 } | |
2844 } | |
2845 changed_lines(lnum, 0, lnum + count, (long)added); | |
2846 | |
2847 if (dfree != NULL) | |
2848 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2849 // Diff is deleted, update folds in other windows. |
7 | 2850 #ifdef FEAT_FOLDING |
2851 diff_fold_update(dfree, idx_to); | |
2852 #endif | |
2853 vim_free(dfree); | |
2854 } | |
2855 else | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2856 // mark_adjust() may have changed the count in a wrong way |
7 | 2857 dp->df_count[idx_to] = new_count; |
2858 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2859 // When changing the current buffer, keep track of line numbers |
7 | 2860 if (idx_cur == idx_to) |
2861 off += added; | |
2862 } | |
2863 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2864 // If before the range or not deleted, go to next diff. |
7 | 2865 if (dfree == NULL) |
2866 { | |
2867 dprev = dp; | |
2868 dp = dp->df_next; | |
2869 } | |
2870 } | |
2871 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2872 // restore curwin/curbuf and a few other things |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2873 if (eap->cmdidx != CMD_diffget) |
7 | 2874 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2875 // 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
|
2876 // 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
|
2877 // 100% right when ":diffput" is used in a function or mapping. |
7 | 2878 if (KeyTyped) |
825 | 2879 u_sync(FALSE); |
7 | 2880 aucmd_restbuf(&aco); |
2881 } | |
2882 | |
14776
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
2883 theend: |
7 | 2884 diff_busy = FALSE; |
14776
09c1f241e2f7
patch 8.1.0400: using freed memory with :diffget
Christian Brabandt <cb@256bit.org>
parents:
14770
diff
changeset
|
2885 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
|
2886 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
|
2887 |
14972
5d52b21b2e7f
patch 8.1.0497: :%diffput changes order of lines
Bram Moolenaar <Bram@vim.org>
parents:
14893
diff
changeset
|
2888 // 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
|
2889 // 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
|
2890 // invalid. |
291656f731c9
patch 8.1.0458: ml_get error and crash when using "do"
Bram Moolenaar <Bram@vim.org>
parents:
14780
diff
changeset
|
2891 check_cursor(); |
291656f731c9
patch 8.1.0458: ml_get error and crash when using "do"
Bram Moolenaar <Bram@vim.org>
parents:
14780
diff
changeset
|
2892 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
|
2893 |
291656f731c9
patch 8.1.0458: ml_get error and crash when using "do"
Bram Moolenaar <Bram@vim.org>
parents:
14780
diff
changeset
|
2894 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
|
2895 // 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
|
2896 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
|
2897 else |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
2898 { |
552523e44923
patch 8.1.0402: the DiffUpdate event isn't triggered for :diffput
Christian Brabandt <cb@256bit.org>
parents:
14776
diff
changeset
|
2899 // 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
|
2900 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
|
2901 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
|
2902 } |
7 | 2903 } |
2904 | |
2905 #ifdef FEAT_FOLDING | |
2906 /* | |
2907 * Update folds for all diff buffers for entry "dp". | |
2908 * Skip buffer with index "skip_idx". | |
2909 * When there are no diffs, all folds are removed. | |
2910 */ | |
2911 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2912 diff_fold_update(diff_T *dp, int skip_idx) |
7 | 2913 { |
2914 int i; | |
2915 win_T *wp; | |
2916 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2917 FOR_ALL_WINDOWS(wp) |
7 | 2918 for (i = 0; i < DB_COUNT; ++i) |
672 | 2919 if (curtab->tp_diffbuf[i] == wp->w_buffer && i != skip_idx) |
7 | 2920 foldUpdate(wp, dp->df_lnum[i], |
2921 dp->df_lnum[i] + dp->df_count[i]); | |
2922 } | |
2923 #endif | |
2924 | |
2925 /* | |
2926 * Return TRUE if buffer "buf" is in diff-mode. | |
2927 */ | |
2928 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2929 diff_mode_buf(buf_T *buf) |
7 | 2930 { |
672 | 2931 tabpage_T *tp; |
2932 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2933 FOR_ALL_TABPAGES(tp) |
672 | 2934 if (diff_buf_idx_tp(buf, tp) != DB_COUNT) |
2935 return TRUE; | |
2936 return FALSE; | |
7 | 2937 } |
2938 | |
2939 /* | |
2940 * Move "count" times in direction "dir" to the next diff block. | |
2941 * Return FAIL if there isn't such a diff block. | |
2942 */ | |
2943 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2944 diff_move_to(int dir, long count) |
7 | 2945 { |
2946 int idx; | |
2947 linenr_T lnum = curwin->w_cursor.lnum; | |
2948 diff_T *dp; | |
2949 | |
2950 idx = diff_buf_idx(curbuf); | |
672 | 2951 if (idx == DB_COUNT || curtab->tp_first_diff == NULL) |
7 | 2952 return FAIL; |
2953 | |
672 | 2954 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
|
2955 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
|
2956 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2957 if (curtab->tp_first_diff == NULL) // no diffs today |
7 | 2958 return FAIL; |
2959 | |
2960 while (--count >= 0) | |
2961 { | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2962 // Check if already before first diff. |
672 | 2963 if (dir == BACKWARD && lnum <= curtab->tp_first_diff->df_lnum[idx]) |
7 | 2964 break; |
2965 | |
672 | 2966 for (dp = curtab->tp_first_diff; ; dp = dp->df_next) |
7 | 2967 { |
2968 if (dp == NULL) | |
2969 break; | |
2970 if ((dir == FORWARD && lnum < dp->df_lnum[idx]) | |
2971 || (dir == BACKWARD | |
2972 && (dp->df_next == NULL | |
2973 || lnum <= dp->df_next->df_lnum[idx]))) | |
2974 { | |
2975 lnum = dp->df_lnum[idx]; | |
2976 break; | |
2977 } | |
2978 } | |
2979 } | |
2980 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2981 // don't end up past the end of the file |
7 | 2982 if (lnum > curbuf->b_ml.ml_line_count) |
2983 lnum = curbuf->b_ml.ml_line_count; | |
2984 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
2985 // When the cursor didn't move at all we fail. |
7 | 2986 if (lnum == curwin->w_cursor.lnum) |
2987 return FAIL; | |
2988 | |
2989 setpcmark(); | |
2990 curwin->w_cursor.lnum = lnum; | |
2991 curwin->w_cursor.col = 0; | |
2992 | |
2993 return OK; | |
2994 } | |
2995 | |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2996 /* |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2997 * 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
|
2998 * "buf1" in diff mode. |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2999 */ |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3000 static linenr_T |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3001 diff_get_corresponding_line_int( |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3002 buf_T *buf1, |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3003 linenr_T lnum1) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3004 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3005 int idx1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3006 int idx2; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3007 diff_T *dp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3008 int baseline = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3009 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3010 idx1 = diff_buf_idx(buf1); |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3011 idx2 = diff_buf_idx(curbuf); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3012 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
|
3013 return lnum1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3014 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3015 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
|
3016 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
|
3017 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3018 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
|
3019 return lnum1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3020 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
18777
diff
changeset
|
3021 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
|
3022 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3023 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
|
3024 return lnum1 - baseline; |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3025 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
|
3026 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3027 // Inside the diffblock |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3028 baseline = lnum1 - dp->df_lnum[idx1]; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3029 if (baseline > dp->df_count[idx2]) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3030 baseline = dp->df_count[idx2]; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3031 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3032 return dp->df_lnum[idx2] + baseline; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3033 } |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3034 if ( (dp->df_lnum[idx1] == lnum1) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3035 && (dp->df_count[idx1] == 0) |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3036 && (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
|
3037 && ((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
|
3038 > curwin->w_cursor.lnum)) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3039 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3040 * 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
|
3041 * 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
|
3042 * 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
|
3043 * 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
|
3044 * as expected. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3045 */ |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3046 return curwin->w_cursor.lnum; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3047 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
|
3048 - (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
|
3049 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3050 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3051 // 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
|
3052 return lnum1 - baseline; |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3053 } |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3054 |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3055 /* |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3056 * 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
|
3057 * "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
|
3058 */ |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3059 linenr_T |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3060 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
|
3061 { |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3062 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
|
3063 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3064 // 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
|
3065 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
|
3066 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
|
3067 return lnum; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3068 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2086
diff
changeset
|
3069 |
7 | 3070 /* |
3071 * For line "lnum" in the current window find the equivalent lnum in window | |
3072 * "wp", compensating for inserted/deleted lines. | |
3073 */ | |
3074 linenr_T | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3075 diff_lnum_win(linenr_T lnum, win_T *wp) |
7 | 3076 { |
3077 diff_T *dp; | |
3078 int idx; | |
3079 int i; | |
3080 linenr_T n; | |
3081 | |
3082 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
|
3083 if (idx == DB_COUNT) // safety check |
7 | 3084 return (linenr_T)0; |
3085 | |
672 | 3086 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
|
3087 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
|
3088 |
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3089 // 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
|
3090 FOR_ALL_DIFFBLOCKS_IN_TAB(curtab, dp) |
7 | 3091 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
3092 break; | |
3093 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3094 // When after the last change, compute relative to the last line number. |
7 | 3095 if (dp == NULL) |
3096 return wp->w_buffer->b_ml.ml_line_count | |
3097 - (curbuf->b_ml.ml_line_count - lnum); | |
3098 | |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3099 // Find index for "wp". |
7 | 3100 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
|
3101 if (i == DB_COUNT) // safety check |
7 | 3102 return (linenr_T)0; |
3103 | |
3104 n = lnum + (dp->df_lnum[i] - dp->df_lnum[idx]); | |
3105 if (n > dp->df_lnum[i] + dp->df_count[i]) | |
3106 n = dp->df_lnum[i] + dp->df_count[i]; | |
3107 return n; | |
3108 } | |
3109 | |
14696
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3110 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3111 * 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
|
3112 * 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
|
3113 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3114 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
|
3115 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
|
3116 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
|
3117 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
|
3118 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
|
3119 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
|
3120 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
|
3121 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3122 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
|
3123 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
|
3124 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
|
3125 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3126 // 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
|
3127 // 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
|
3128 // 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
|
3129 // 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
|
3130 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
|
3131 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
|
3132 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
|
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 ++p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3135 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
|
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 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3138 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
|
3139 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
|
3140 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
|
3141 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
|
3142 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
|
3143 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
|
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 ++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 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
|
3147 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3148 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3149 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
|
3150 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
|
3151 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
|
3152 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3153 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
|
3154 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3155 *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
|
3156 *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
|
3157 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3158 else |
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 *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
|
3161 *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
|
3162 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3163 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
|
3164 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3165 *lnum_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
|
3166 *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
|
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 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3169 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3170 *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
|
3171 *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
|
3172 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3173 return OK; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3174 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3175 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3176 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3177 * 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
|
3178 * 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
|
3179 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3180 static int |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3181 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
|
3182 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
|
3183 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
|
3184 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
|
3185 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
|
3186 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
|
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 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
|
3189 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
|
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 // 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
|
3192 // @@ -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
|
3193 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
|
3194 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
|
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 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
|
3197 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
|
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 ++p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3200 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
|
3201 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3202 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3203 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
|
3204 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
|
3205 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3206 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
|
3207 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
|
3208 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3209 ++p; |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3210 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
|
3211 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3212 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3213 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
|
3214 } |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3215 else |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3216 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
|
3217 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3218 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
|
3219 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
|
3220 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
|
3221 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
|
3222 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
|
3223 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
|
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 *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
|
3226 *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
|
3227 *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
|
3228 *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
|
3229 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3230 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
|
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 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3233 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
|
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 |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3236 /* |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3237 * 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
|
3238 * 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
|
3239 */ |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3240 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
|
3241 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
|
3242 { |
195e8b1fcbbf
patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3243 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
|
3244 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
|
3245 |
14982
d56f14540dda
patch 8.1.0502: internal diff fails when diffing a context diff
Bram Moolenaar <Bram@vim.org>
parents:
14972
diff
changeset
|
3246 // 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
|
3247 // 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
|
3248 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
|
3249 return 0; |
d56f14540dda
patch 8.1.0502: internal diff fails when diffing a context diff
Bram Moolenaar <Bram@vim.org>
parents:
14972
diff
changeset
|
3250 |
d56f14540dda
patch 8.1.0502: internal diff fails when diffing a context diff
Bram Moolenaar <Bram@vim.org>
parents:
14972
diff
changeset
|
3251 // sanity check |
d56f14540dda
patch 8.1.0502: internal diff fails when diffing a context diff
Bram Moolenaar <Bram@vim.org>
parents:
14972
diff
changeset
|
3252 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
|
3253 return 0; |
d56f14540dda
patch 8.1.0502: internal diff fails when diffing a context diff
Bram Moolenaar <Bram@vim.org>
parents:
14972
diff
changeset
|
3254 |
d56f14540dda
patch 8.1.0502: internal diff fails when diffing a context diff
Bram Moolenaar <Bram@vim.org>
parents:
14972
diff
changeset
|
3255 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
|
3256 return -1; |
d56f14540dda
patch 8.1.0502: internal diff fails when diffing a context diff
Bram Moolenaar <Bram@vim.org>
parents:
14972
diff
changeset
|
3257 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
|
3258 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
|
3259 return -1; |
d56f14540dda
patch 8.1.0502: internal diff fails when diffing a context diff
Bram Moolenaar <Bram@vim.org>
parents:
14972
diff
changeset
|
3260 ((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
|
3261 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
|
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 |
17986
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3264 #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
|
3265 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3266 #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
|
3267 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3268 /* |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3269 * "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
|
3270 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3271 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3272 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
|
3273 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3274 #ifdef FEAT_DIFF |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3275 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
|
3276 #endif |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3277 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3278 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3279 /* |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3280 * "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
|
3281 */ |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3282 void |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3283 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
|
3284 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3285 #ifdef FEAT_DIFF |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3286 linenr_T lnum = 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
|
3287 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
|
3288 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
|
3289 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
|
3290 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
|
3291 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
|
3292 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
|
3293 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
|
3294 int col; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3295 |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3296 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
|
3297 lnum = 0; |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3298 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
|
3299 || 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
|
3300 || 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
|
3301 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3302 // 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
|
3303 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
|
3304 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
|
3305 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3306 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
|
3307 { |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3308 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
|
3309 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
|
3310 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
|
3311 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
|
3312 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3313 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
|
3314 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3315 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3316 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
|
3317 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3318 else |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3319 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
|
3320 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
|
3321 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
|
3322 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
|
3323 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3324 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3325 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
|
3326 { |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3327 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
|
3328 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
|
3329 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
|
3330 else |
18777
3a68dc2a1bc1
patch 8.1.2378: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
3331 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
|
3332 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3333 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
|
3334 #endif |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3335 } |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3336 |
5c8906f653f5
patch 8.1.1989: the evalfunc.c file is still too big
Bram Moolenaar <Bram@vim.org>
parents:
17851
diff
changeset
|
3337 #endif |