Commit 6aac706
patch 9.1.1921: xdiff: included xdiff code is outdated
Problem: xdiff: included xdiff code is outdated because it is based on
git 2.40.0
Solution: Sync with xdiff from git 2.52 (Yee Cheng Chin).
Git [v2.52](https://github.com/git/git/releases/tag/v2.52.0) has just been
released. Merge from upstream to get the latest version of xdiff. Vim's xdiff
was last updated in #12181 (Patch v9.0.1418) from Git v2.33 to v2.40.
I have refined the strategy for merging from upstream a bit compared to last
time. I use the following commands to create an orphaned branch that extracts
the before/after xdiff source code from the Git codebase, and then perform a
subtree merge. The commits in the orphaned branch are reproducible
deterministically so a reviewer can reproduce the steps and it should result in
identical commit hashes (63264f229d and d741f0e230). The commands are as
follows (you could run in a separate Vim repo to keep things clean):
```bash
git remote add --no-tags git https://github.com/git/git.git
git fetch git
git switch --orphan xdiff-orig
git read-tree --reset -u 73876f4861:xdiff/ # Git v2.40.0
git rm -f xmerge.c # Vim doesn't use xmerge
(GIT_COMMITTER_NAME="dummy" GIT_COMMITTER_EMAIL="dummy" GIT_COMMITTER_DATE="1600000000 +0000" \
git commit --no-gpg-sign --reuse-message=73876f4861)
git switch -c xdiff-new
git read-tree --reset -u 9a2fb147f2:xdiff/ # Git v2.52.0
git rm -f xmerge.c
(GIT_COMMITTER_NAME="dummy" GIT_COMMITTER_EMAIL="dummy" GIT_COMMITTER_DATE="1600000000 +0000" \
git commit --no-gpg-sign --reuse-message=9a2fb147f2)
git switch master
git switch -c xdiff-upstream-v2.52.0
git merge -s ours --no-edit --allow-unrelated-histories xdiff-orig
git merge -Xsubtree=xdiff xdiff-new
```
The commit graph looks like so:
```
* a005e268bd 2025-11-17 17:11:26 Yee Cheng Chin (HEAD -> xdiff-upstream-v2.52.0) Update xdiff README
* d353c6f2c8 2025-11-17 16:26:15 Yee Cheng Chin Merge branch 'xdiff-new' into xdiff-upstream-v2.52.0
|\
| * d741f0e230 2025-11-17 07:35:33 Junio C Hamano (xdiff-new) Git 2.52
* | c4f8b15dd9 2025-11-17 16:22:30 Yee Cheng Chin Merge branch 'xdiff-orig' into xdiff-upstream-v2.52.0
|\|
| * 63264f229d 2023-03-12 14:34:41 Junio C Hamano (xdiff-orig) Git 2.40
* 6437997 2025-11-16 18:30:42 Girish Palya (tag: v9.1.1918, origin/master, origin/HEAD, master) patch 9.1.1918: completion: crash with fuzzy completion
```
For reviewing I recommend using the following commands which simplifies the diff to only what we care about:
- `git show --remerge-diff d353c6f2c8`: This shows how my merge actually
resolved the merge conflicts.
- `vimdiff <(git diff-tree -U0 63264f229d master:src/xdiff/) \
<(git diff-tree -U0 d741f0e230 xdiff-upstream-v2.52.0:src/xdiff) \
-c "silent windo %s/^index.*/index/" \
-c "silent windo %s/^@@ [-+, 0-9]* @@/@@/"`:
This shows how the patch (downstream changes done in Vim on top of Git) has
changed. Note that some local changes for fixing compiler warnings are now gone
because they are fixed upstream.
- git/git@d39e28e
added a dependency (`signed_add_overflows`) to Git code base. I replaced it
with a custom one since it's not hard to implement.
- Upstream had fixed a lot of compiler warnings with signed/unsigned integers,
so the compiler warning fixes that were done in Vim downstream were removed.
- Replace new `BUG()` calls with `xdl_bug()` where we use Vim's assertion
mechanisms instead.
- Performance improvement due to optimizations in the line hashing function
(git/git@41d9783 and
git/git@a4bbe8a).
- From personal unscientific testing (Apple M1 Max, macOS 15), when using the
new xdiff, for simple/normal diff's this could result in **11%/29%** overall
diff speed improvement. For larger more pathologically complicated diff this
results in a more modest **4%/7%** improvement.
- The two improvement numbers above are for compiling Vim with `-O3 -flto` vs
`-O2`. The more optimized version of Vim results in lower performance
improvement as it was already doing inlining via link-time-optimization
before.
- Just for reference, the command I used to test this was the following (use
either test case and comment out the other one):
```bash
# Simple/normal diff test case
(COMMIT=0d9160e11ce; git show ${COMMIT}:src/diff.c > test1.txt; git show ${COMMIT}~:src/diff.c > test2.txt)
# Larger diff test case
(COMMIT=9670f61d468; git show ${COMMIT}:src/auto/configure > test1.txt; git show ${COMMIT}~:src/auto/configure > test2.txt)
# Build Vim with old/new xdiff, then copy ./src/vim to ./src/vim_orig / ./src/vim_new respectively.
hyperfine --warmup 4 --runs 20 -L vimcmd vim_orig,vim_new \
"./src/{vimcmd} -u NONE -U NONE -es -V1 -c \"let g:f1=readfile('test1.txt')\" -c \"let g:f2=readfile('test2.txt')\" -c \"for i in range(1,200) | call diff(g:f1, g:f2) | endfor\" -c 'q'"
```
closes: #18765
Signed-off-by: Yee Cheng Chin <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>1 parent eb33c2e commit 6aac706
File tree
13 files changed
+353
-342
lines changed- src
- xdiff
13 files changed
+353
-342
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
729 | 729 | | |
730 | 730 | | |
731 | 731 | | |
| 732 | + | |
| 733 | + | |
732 | 734 | | |
733 | 735 | | |
734 | 736 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
| |||
42 | 47 | | |
43 | 48 | | |
44 | 49 | | |
45 | | - | |
46 | | - | |
| 50 | + | |
| 51 | + | |
47 | 52 | | |
48 | 53 | | |
49 | 54 | | |
| |||
87 | 92 | | |
88 | 93 | | |
89 | 94 | | |
90 | | - | |
| 95 | + | |
91 | 96 | | |
92 | 97 | | |
93 | 98 | | |
| |||
124 | 129 | | |
125 | 130 | | |
126 | 131 | | |
127 | | - | |
| 132 | + | |
128 | 133 | | |
129 | 134 | | |
130 | 135 | | |
| |||
159 | 164 | | |
160 | 165 | | |
161 | 166 | | |
162 | | - | |
| 167 | + | |
163 | 168 | | |
164 | 169 | | |
165 | 170 | | |
| |||
183 | 188 | | |
184 | 189 | | |
185 | 190 | | |
186 | | - | |
| 191 | + | |
187 | 192 | | |
188 | 193 | | |
189 | 194 | | |
| |||
211 | 216 | | |
212 | 217 | | |
213 | 218 | | |
214 | | - | |
215 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
216 | 223 | | |
217 | 224 | | |
218 | 225 | | |
| |||
223 | 230 | | |
224 | 231 | | |
225 | 232 | | |
226 | | - | |
227 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
228 | 237 | | |
229 | 238 | | |
230 | 239 | | |
| |||
253 | 262 | | |
254 | 263 | | |
255 | 264 | | |
256 | | - | |
257 | | - | |
| 265 | + | |
| 266 | + | |
258 | 267 | | |
259 | | - | |
260 | 268 | | |
261 | 269 | | |
262 | 270 | | |
263 | 271 | | |
264 | | - | |
265 | | - | |
| 272 | + | |
| 273 | + | |
266 | 274 | | |
267 | 275 | | |
268 | 276 | | |
269 | 277 | | |
270 | 278 | | |
271 | 279 | | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | 280 | | |
276 | | - | |
| 281 | + | |
277 | 282 | | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | 283 | | |
282 | | - | |
| 284 | + | |
283 | 285 | | |
284 | 286 | | |
285 | 287 | | |
286 | 288 | | |
287 | 289 | | |
288 | 290 | | |
289 | 291 | | |
290 | | - | |
| 292 | + | |
291 | 293 | | |
292 | 294 | | |
293 | 295 | | |
| |||
296 | 298 | | |
297 | 299 | | |
298 | 300 | | |
299 | | - | |
| 301 | + | |
300 | 302 | | |
301 | | - | |
| 303 | + | |
302 | 304 | | |
303 | 305 | | |
304 | 306 | | |
| |||
314 | 316 | | |
315 | 317 | | |
316 | 318 | | |
317 | | - | |
318 | 319 | | |
319 | 320 | | |
320 | 321 | | |
| |||
353 | 354 | | |
354 | 355 | | |
355 | 356 | | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
| 357 | + | |
366 | 358 | | |
367 | 359 | | |
368 | 360 | | |
| |||
497 | 489 | | |
498 | 490 | | |
499 | 491 | | |
500 | | - | |
| 492 | + | |
501 | 493 | | |
502 | 494 | | |
503 | 495 | | |
504 | 496 | | |
505 | 497 | | |
506 | | - | |
| 498 | + | |
507 | 499 | | |
508 | 500 | | |
509 | 501 | | |
| |||
516 | 508 | | |
517 | 509 | | |
518 | 510 | | |
519 | | - | |
| 511 | + | |
520 | 512 | | |
521 | 513 | | |
522 | 514 | | |
| |||
716 | 708 | | |
717 | 709 | | |
718 | 710 | | |
719 | | - | |
| 711 | + | |
720 | 712 | | |
721 | 713 | | |
722 | 714 | | |
| |||
730 | 722 | | |
731 | 723 | | |
732 | 724 | | |
733 | | - | |
| 725 | + | |
734 | 726 | | |
735 | 727 | | |
736 | 728 | | |
| |||
746 | 738 | | |
747 | 739 | | |
748 | 740 | | |
749 | | - | |
| 741 | + | |
750 | 742 | | |
751 | 743 | | |
752 | 744 | | |
| |||
760 | 752 | | |
761 | 753 | | |
762 | 754 | | |
763 | | - | |
764 | | - | |
765 | | - | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
766 | 758 | | |
767 | | - | |
| 759 | + | |
768 | 760 | | |
769 | 761 | | |
770 | 762 | | |
| |||
781 | 773 | | |
782 | 774 | | |
783 | 775 | | |
784 | | - | |
785 | | - | |
786 | | - | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
787 | 779 | | |
788 | | - | |
| 780 | + | |
789 | 781 | | |
790 | 782 | | |
791 | 783 | | |
| |||
794 | 786 | | |
795 | 787 | | |
796 | 788 | | |
797 | | - | |
| 789 | + | |
798 | 790 | | |
799 | 791 | | |
800 | 792 | | |
| |||
946 | 938 | | |
947 | 939 | | |
948 | 940 | | |
949 | | - | |
| 941 | + | |
950 | 942 | | |
951 | 943 | | |
952 | 944 | | |
953 | 945 | | |
954 | 946 | | |
955 | 947 | | |
956 | | - | |
957 | | - | |
958 | | - | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
959 | 951 | | |
960 | 952 | | |
961 | 953 | | |
| |||
1002 | 994 | | |
1003 | 995 | | |
1004 | 996 | | |
1005 | | - | |
| 997 | + | |
1006 | 998 | | |
1007 | 999 | | |
1008 | 1000 | | |
1009 | 1001 | | |
1010 | | - | |
| 1002 | + | |
1011 | 1003 | | |
1012 | 1004 | | |
1013 | 1005 | | |
1014 | | - | |
| 1006 | + | |
1015 | 1007 | | |
1016 | 1008 | | |
1017 | 1009 | | |
| |||
1020 | 1012 | | |
1021 | 1013 | | |
1022 | 1014 | | |
1023 | | - | |
| 1015 | + | |
1024 | 1016 | | |
1025 | 1017 | | |
1026 | 1018 | | |
| |||
1036 | 1028 | | |
1037 | 1029 | | |
1038 | 1030 | | |
1039 | | - | |
| 1031 | + | |
1040 | 1032 | | |
1041 | 1033 | | |
1042 | 1034 | | |
| |||
1048 | 1040 | | |
1049 | 1041 | | |
1050 | 1042 | | |
1051 | | - | |
| 1043 | + | |
1052 | 1044 | | |
1053 | 1045 | | |
1054 | 1046 | | |
1055 | | - | |
| 1047 | + | |
1056 | 1048 | | |
1057 | 1049 | | |
1058 | 1050 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | 27 | | |
35 | 28 | | |
36 | 29 | | |
| |||
46 | 39 | | |
47 | 40 | | |
48 | 41 | | |
49 | | - | |
50 | | - | |
| 42 | + | |
| 43 | + | |
51 | 44 | | |
52 | 45 | | |
53 | 46 | | |
| |||
0 commit comments