Permalink
Browse files

patch 8.1.0360: using an external diff program is slow and inflexible

Problem:    Using an external diff program is slow and inflexible.
Solution:   Include the xdiff library. (Christian Brabandt, closes #2732)
            Use it by default.
  • Loading branch information...
brammool committed Sep 10, 2018
1 parent 93a1df2 commit e828b7621cf9065a3582be0c4dd1e0e846e335bf
Showing with 5,376 additions and 209 deletions.
  1. +14 −0 Filelist
  2. +6 −3 runtime/doc/diff.txt
  3. +25 −5 runtime/doc/options.txt
  4. +53 −0 src/Make_cyg_ming.mak
  5. +39 −2 src/Make_mvc.mak
  6. +51 −2 src/Makefile
  7. +632 −181 src/diff.c
  8. +3 −1 src/structs.h
  9. +20 −0 src/testdir/dumps/Test_diff_01.dump
  10. +20 −0 src/testdir/dumps/Test_diff_02.dump
  11. +20 −0 src/testdir/dumps/Test_diff_03.dump
  12. +20 −0 src/testdir/dumps/Test_diff_04.dump
  13. +20 −0 src/testdir/dumps/Test_diff_05.dump
  14. +20 −0 src/testdir/dumps/Test_diff_06.dump
  15. +20 −0 src/testdir/dumps/Test_diff_07.dump
  16. +20 −0 src/testdir/dumps/Test_diff_08.dump
  17. +20 −0 src/testdir/dumps/Test_diff_09.dump
  18. +20 −0 src/testdir/dumps/Test_diff_10.dump
  19. +20 −0 src/testdir/dumps/Test_diff_11.dump
  20. +20 −0 src/testdir/dumps/Test_diff_12.dump
  21. +20 −0 src/testdir/dumps/Test_diff_13.dump
  22. +20 −0 src/testdir/dumps/Test_diff_14.dump
  23. +20 −0 src/testdir/dumps/Test_diff_15.dump
  24. +20 −0 src/testdir/dumps/Test_diff_16.dump
  25. +169 −15 src/testdir/test_diffmode.vim
  26. +2 −0 src/version.c
  27. +504 −0 src/xdiff/COPYING
  28. +14 −0 src/xdiff/README.txt
  29. +142 −0 src/xdiff/xdiff.h
  30. +1,043 −0 src/xdiff/xdiffi.c
  31. +64 −0 src/xdiff/xdiffi.h
  32. +312 −0 src/xdiff/xemit.c
  33. +36 −0 src/xdiff/xemit.h
  34. +386 −0 src/xdiff/xhistogram.c
  35. +61 −0 src/xdiff/xinclude.h
  36. +54 −0 src/xdiff/xmacros.h
  37. +390 −0 src/xdiff/xpatience.c
  38. +483 −0 src/xdiff/xprepare.c
  39. +34 −0 src/xdiff/xprepare.h
  40. +67 −0 src/xdiff/xtypes.h
  41. +425 −0 src/xdiff/xutils.c
  42. +47 −0 src/xdiff/xutils.h
@@ -273,6 +273,20 @@ SRC_ALL = \
src/libvterm/t/92lp1640917.test \
src/libvterm/t/harness.c \
src/libvterm/t/run-test.pl \
src/xdiff/xdiff.h \
src/xdiff/xdiffi.c \
src/xdiff/xdiffi.h \
src/xdiff/xemit.c \
src/xdiff/xemit.h \
src/xdiff/xhistogram.c \
src/xdiff/xinclude.h \
src/xdiff/xmacros.h \
src/xdiff/xpatience.c \
src/xdiff/xprepare.c \
src/xdiff/xprepare.h \
src/xdiff/xtypes.h \
src/xdiff/xutils.c \
src/xdiff/xutils.h \


# source files for Unix only
@@ -39,7 +39,9 @@ The second and following arguments may also be a directory name. Vim will
then append the file name of the first argument to the directory name to find
the file.

This only works when a standard "diff" command is available. See 'diffexpr'.
By default an internal diff library will be used. When 'diffopt' or
'diffexpr' has been set an external "diff" command will be used. This only
works when such a diff program is available.

Diffs are local to the current tab page |tab-page|. You can't see diffs with
a window in another tab page. This does make it possible to have several
@@ -344,8 +346,9 @@ between file1 and file2: >

The ">" is replaced with the value of 'shellredir'.

The output of "diff" must be a normal "ed" style diff. Do NOT use a context
diff. This example explains the format that Vim expects: >
The output of "diff" must be a normal "ed" style diff or a unified diff. Do
NOT use a context diff. This example explains the format that Vim expects for
the "ed" style diff: >

1a2
> bbb
@@ -2609,8 +2609,8 @@ A jump table for the options with a short description can be found at |Q_op|.
{not in Vi}
{not available when compiled without the |+diff|
feature}
Expression which is evaluated to obtain an ed-style diff file from two
versions of a file. See |diff-diffexpr|.
Expression which is evaluated to obtain a diff file (either ed-style
or unified-style) from two versions of a file. See |diff-diffexpr|.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.

This comment has been minimized.

@chdiza

chdiza Sep 10, 2018

Shouldn't this now be:

'diffopt' 'dip'              string (default "filler,internal")

instead of (default "filler")?

This comment has been minimized.

@brammool

brammool via email Sep 10, 2018

Author Contributor
@@ -2657,11 +2657,31 @@ A jump table for the options with a short description can be found at |Q_op|.
foldcolumn:{n} Set the 'foldcolumn' option to {n} when
starting diff mode. Without this 2 is used.

Examples: >
internal Use the internal diff library. This is
ignored when 'diffexpr' is set. *E960*
When running out of memory when writing a
buffer this item will be ignored for diffs
involving that buffer. Set the 'verbose'
option to see when this happens.

indent-heuristic
Use the indent heuristic for the internal
diff library.

algorithm:{text} Use the specified diff algorithm with the
internal diff engine. Currently supported
algorithms are:
myers the default algorithm
minimal spend extra time to generate the
smallest possible diff
patience patience diff algorithm
histogram histogram diff algorithm

:set diffopt=filler,context:4
Examples: >
:set diffopt=internal,filler,context:4
:set diffopt=
:set diffopt=filler,foldcolumn:3
:set diffopt=internal,filler,foldcolumn:3
:set diffopt-=internal " do NOT use the internal diff parser
<
*'digraph'* *'dg'* *'nodigraph'* *'nodg'*
'digraph' 'dg' boolean (default off)
@@ -166,6 +166,25 @@ else
ifndef CROSS_COMPILE
CROSS_COMPILE =
endif

# About the "sh.exe" condition, as explained by Ken Takata:
#
# If the makefile is executed with mingw32-make and sh.exe is not found in
# $PATH, then $SHELL is set to "sh.exe" (without any path). In this case,
# unix-like commands might not work and a dos-style path is needed.
#
# If the makefile is executed with mingw32-make and sh.exe IS found in $PATH,
# then $SHELL is set with the actual path of sh.exe (e.g.
# "C:/msys64/usr/bin/sh.exe"). In this case, unix-like commands can be used.
#
# If it is executed by the "make" command from cmd.exe, $SHELL is set to
# "/bin/sh". If the "make" command is in the $PATH, other unix-like commands
# might also work.
#
# If it is executed by the "make" command from a unix-like shell,
# $SHELL is set with the unix-style path (e.g. "/bin/bash").
# In this case, unix-like commands can be used.
#
ifneq (sh.exe, $(SHELL))
DEL = rm
MKDIR = mkdir -p
@@ -810,6 +829,23 @@ OBJ += $(OUTDIR)/terminal.o \
$(OUTDIR)/term_vterm.o
endif

# Include xdiff
OBJ += $(OUTDIR)/xdiffi.o \
$(OUTDIR)/xemit.o \
$(OUTDIR)/xprepare.o \
$(OUTDIR)/xutils.o \
$(OUTDIR)/xhistogram.o \
$(OUTDIR)/xpatience.o

XDIFF_DEPS = \
xdiff/xdiff.h \
xdiff/xdiffi.h \
xdiff/xemit.h \
xdiff/xinclude.h \
xdiff/xmacros.h \
xdiff/xprepare.h \
xdiff/xtypes.h \
xdiff/xutils.h

ifdef MZSCHEME
MZSCHEME_SUFFIX = Z
@@ -1055,6 +1091,23 @@ $(OUTDIR)/term_unicode.o: libvterm/src/unicode.c $(TERM_DEPS)
$(OUTDIR)/term_vterm.o: libvterm/src/vterm.c $(TERM_DEPS)
$(CCCTERM) libvterm/src/vterm.c -o $@

$(OUTDIR)/xdiffi.o: xdiff/xdiffi.c $(XDIFF_DEPS)
$(CC) -c $(CFLAGS) xdiff/xdiffi.c -o $(OUTDIR)/xdiffi.o

$(OUTDIR)/xemit.o: xdiff/xemit.c $(XDIFF_DEPS)
$(CC) -c $(CFLAGS) xdiff/xemit.c -o $(OUTDIR)/xemit.o

$(OUTDIR)/xprepare.o: xdiff/xprepare.c $(XDIFF_DEPS)
$(CC) -c $(CFLAGS) xdiff/xprepare.c -o $(OUTDIR)/xprepare.o

$(OUTDIR)/xutils.o: xdiff/xutils.c $(XDIFF_DEPS)
$(CC) -c $(CFLAGS) xdiff/xutils.c -o $(OUTDIR)/xutils.o

$(OUTDIR)/xhistogram.o: xdiff/xhistogram.c $(XDIFF_DEPS)
$(CC) -c $(CFLAGS) xdiff/xhistogram.c -o $(OUTDIR)/xhistogram.o

$(OUTDIR)/xpatience.o: xdiff/xpatience.c $(XDIFF_DEPS)
$(CC) -c $(CFLAGS) xdiff/xpatience.c -o $(OUTDIR)/xpatience.o

pathdef.c: $(INCL)
ifneq (sh.exe, $(SHELL))
@@ -813,6 +813,24 @@ CUI_OBJ = $(OUTDIR)\iscygpty.obj
!endif
SUBSYSTEM_TOOLS = console

XDIFF_OBJ = $(OBJDIR)/xdiffi.obj \
$(OBJDIR)/xemit.obj \
$(OBJDIR)/xprepare.obj \
$(OBJDIR)/xutils.obj \
$(OBJDIR)/xhistogram.obj \
$(OBJDIR)/xpatience.obj

XDIFF_DEPS = \
xdiff/xdiff.h \
xdiff/xdiffi.h \
xdiff/xemit.h \
xdiff/xinclude.h \
xdiff/xmacros.h \
xdiff/xprepare.h \
xdiff/xtypes.h \
xdiff/xutils.h


!if "$(SUBSYSTEM_VER)" != ""
SUBSYSTEM = $(SUBSYSTEM),$(SUBSYSTEM_VER)
SUBSYSTEM_TOOLS = $(SUBSYSTEM_TOOLS),$(SUBSYSTEM_VER)
@@ -1204,12 +1222,12 @@ all: $(VIM).exe \
tee/tee.exe \
GvimExt/gvimext.dll

$(VIM).exe: $(OUTDIR) $(OBJ) $(GUI_OBJ) $(CUI_OBJ) $(OLE_OBJ) $(OLE_IDL) $(MZSCHEME_OBJ) \
$(VIM).exe: $(OUTDIR) $(OBJ) $(XDIFF_OBJ) $(GUI_OBJ) $(CUI_OBJ) $(OLE_OBJ) $(OLE_IDL) $(MZSCHEME_OBJ) \
$(LUA_OBJ) $(PERL_OBJ) $(PYTHON_OBJ) $(PYTHON3_OBJ) $(RUBY_OBJ) $(TCL_OBJ) \
$(CSCOPE_OBJ) $(TERM_OBJ) $(NETBEANS_OBJ) $(CHANNEL_OBJ) $(XPM_OBJ) \
version.c version.h
$(CC) $(CFLAGS_OUTDIR) version.c
$(link) $(LINKARGS1) -out:$(VIM).exe $(OBJ) $(GUI_OBJ) $(CUI_OBJ) $(OLE_OBJ) \
$(link) $(LINKARGS1) -out:$(VIM).exe $(OBJ) $(XDIFF_OBJ) $(GUI_OBJ) $(CUI_OBJ) $(OLE_OBJ) \
$(LUA_OBJ) $(MZSCHEME_OBJ) $(PERL_OBJ) $(PYTHON_OBJ) $(PYTHON3_OBJ) $(RUBY_OBJ) \
$(TCL_OBJ) $(CSCOPE_OBJ) $(TERM_OBJ) $(NETBEANS_OBJ) $(CHANNEL_OBJ) \
$(XPM_OBJ) $(OUTDIR)\version.obj $(LINKARGS2)
@@ -1304,6 +1322,7 @@ $(NEW_TESTS):
$(MAKE) /NOLOGO -f Make_dos.mak nolog
$(MAKE) /NOLOGO -f Make_dos.mak $@.res
$(MAKE) /NOLOGO -f Make_dos.mak report
cat messages
cd ..

###########################################################################
@@ -1344,6 +1363,24 @@ $(OUTDIR)/dict.obj: $(OUTDIR) dict.c $(INCL)

$(OUTDIR)/diff.obj: $(OUTDIR) diff.c $(INCL)

$(OUTDIR)/xdiffi.obj: $(OUTDIR) xdiff/xdiffi.c $(XDIFF_DEPS)
$(CC) $(CFLAGS_OUTDIR) xdiff/xdiffi.c

$(OUTDIR)/xemit.obj: $(OUTDIR) xdiff/xemit.c $(XDIFF_DEPS)
$(CC) $(CFLAGS_OUTDIR) xdiff/xemit.c

$(OUTDIR)/xprepare.obj: $(OUTDIR) xdiff/xprepare.c $(XDIFF_DEPS)
$(CC) $(CFLAGS_OUTDIR) xdiff/xprepare.c

$(OUTDIR)/xutils.obj: $(OUTDIR) xdiff/xutils.c $(XDIFF_DEPS)
$(CC) $(CFLAGS_OUTDIR) xdiff/xutils.c

$(OUTDIR)/xhistogram.obj: $(OUTDIR) xdiff/xhistogram.c $(XDIFF_DEPS)
$(CC) $(CFLAGS_OUTDIR) xdiff/xhistogram.c

$(OUTDIR)/xpatience.obj: $(OUTDIR) xdiff/xpatience.c $(XDIFF_DEPS)
$(CC) $(CFLAGS_OUTDIR) xdiff/xpatience.c

$(OUTDIR)/digraph.obj: $(OUTDIR) digraph.c $(INCL)

$(OUTDIR)/edit.obj: $(OUTDIR) edit.c $(INCL)
@@ -1400,6 +1400,32 @@ TERM_DEPS = \

TERM_SRC = libvterm/src/*.c

XDIFF_SRC = \
xdiff/xdiffi.c \
xdiff/xemit.c \
xdiff/xprepare.c \
xdiff/xutils.c \
xdiff/xhistogram.c \
xdiff/xpatience.c \

XDIFF_OBJS = \
objects/xdiffi.o \
objects/xemit.o \
objects/xprepare.o \
objects/xutils.o \
objects/xhistogram.o \
objects/xpatience.o \

XDIFF_INCL = \
xdiff/xdiff.h \
xdiff/xdiffi.h \
xdiff/xemit.h \
xdiff/xinclude.h \
xdiff/xmacros.h \
xdiff/xprepare.h \
xdiff/xtypes.h \
xdiff/xutils.h \

### Command to create dependencies based on #include "..."
### prototype headers are ignored due to -DPROTO, system
### headers #include <...> are ignored if we use the -MM option, as
@@ -1611,6 +1637,7 @@ BASIC_SRC = \
SRC = $(BASIC_SRC) \
$(GUI_SRC) \
$(TERM_SRC) \
$(XDIFF_SRC) \
$(HANGULIN_SRC) \
$(LUA_SRC) \
$(MZSCHEME_SRC) \
@@ -1728,6 +1755,7 @@ OBJ_COMMON = \
$(WORKSHOP_OBJ) \
$(NETBEANS_OBJ) \
$(CHANNEL_OBJ) \
$(XDIFF_OBJS) \
$(WSDEBUG_OBJ)

# The files included by tests are not in OBJ_COMMON.
@@ -2731,7 +2759,7 @@ SHADOWDIR = shadow

shadow: runtime pixmaps
$(MKDIR_P) $(SHADOWDIR)
cd $(SHADOWDIR); ln -s ../*.[chm] ../*.in ../*.sh ../*.xs ../*.xbm ../gui_gtk_res.xml ../toolcheck ../proto ../libvterm ../vimtutor ../gvimtutor ../install-sh ../Make_all.mak .
cd $(SHADOWDIR); ln -s ../*.[chm] ../*.in ../*.sh ../*.xs ../*.xbm ../gui_gtk_res.xml ../toolcheck ../proto ../xdiff ../libvterm ../vimtutor ../gvimtutor ../install-sh ../Make_all.mak .
mkdir $(SHADOWDIR)/auto
cd $(SHADOWDIR)/auto; ln -s ../../auto/configure .
$(MKDIR_P) $(SHADOWDIR)/po
@@ -2915,7 +2943,7 @@ objects/crypt_zip.o: crypt_zip.c
objects/dict.o: dict.c
$(CCC) -o $@ dict.c

objects/diff.o: diff.c
objects/diff.o: diff.c $(XDIFF_INCL)
$(CCC) -o $@ diff.c

objects/digraph.o: digraph.c
@@ -3229,6 +3257,27 @@ objects/term_unicode.o: libvterm/src/unicode.c $(TERM_DEPS)
objects/term_vterm.o: libvterm/src/vterm.c $(TERM_DEPS)
$(CCCTERM) -o $@ libvterm/src/vterm.c

CCCDIFF = $(CCC_NF) $(ALL_CFLAGS)

objects/xdiffi.o: xdiff/xdiffi.c $(XDIFF_INCL)
$(CCCDIFF) -o $@ xdiff/xdiffi.c

objects/xprepare.o: xdiff/xprepare.c $(XDIFF_INCL)
$(CCCDIFF) -o $@ xdiff/xprepare.c

objects/xutils.o: xdiff/xutils.c $(XDIFF_INCL)
$(CCCDIFF) -o $@ xdiff/xutils.c

objects/xemit.o: xdiff/xemit.c $(XDIFF_INCL)
$(CCCDIFF) -o $@ xdiff/xemit.c

objects/xhistogram.o: xdiff/xhistogram.c $(XDIFF_INCL)
$(CCCDIFF) -o $@ xdiff/xhistogram.c

objects/xpatience.o: xdiff/xpatience.c $(XDIFF_INCL)
$(CCCDIFF) -o $@ xdiff/xpatience.c


###############################################################################
### MacOS X installation
###
Oops, something went wrong.

0 comments on commit e828b76

Please sign in to comment.