Skip to content

Commit

Permalink
teach --histogram to diff
Browse files Browse the repository at this point in the history
Port JGit's HistogramDiff algorithm over to C. Rough numbers (TODO) show
that it is faster than its --patience cousin, as well as the default
Meyers algorithm.

The implementation has been reworked to use structs and pointers,
instead of bitmasks, thus doing away with JGit's 2^28 line limit.

We also use xdiff's default hash table implementation (xdl_hash_bits()
with XDL_HASHLONG()) for convenience.

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Tay Ray Chuan authored and Junio C Hamano committed Jul 12, 2011
1 parent 46c8f29 commit 8c912ee
Show file tree
Hide file tree
Showing 8 changed files with 407 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,7 @@ ifndef NO_CURL
GIT_OBJS += http.o http-walker.o remote-curl.o
endif
XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \
xdiff/xmerge.o xdiff/xpatience.o
xdiff/xmerge.o xdiff/xpatience.o xdiff/xhistogram.o
VCSSVN_OBJS = vcs-svn/string_pool.o vcs-svn/line_buffer.o \
vcs-svn/repo_tree.o vcs-svn/fast_export.o vcs-svn/svndump.o
VCSSVN_TEST_OBJS = test-obj-pool.o test-string-pool.o \
Expand Down
2 changes: 2 additions & 0 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -3369,6 +3369,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL);
else if (!strcmp(arg, "--patience"))
DIFF_XDL_SET(options, PATIENCE_DIFF);
else if (!strcmp(arg, "--histogram"))
DIFF_XDL_SET(options, HISTOGRAM_DIFF);

/* flags options */
else if (!strcmp(arg, "--binary")) {
Expand Down
2 changes: 2 additions & 0 deletions merge-recursive.c
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,8 @@ int parse_merge_opt(struct merge_options *o, const char *s)
o->subtree_shift = s + strlen("subtree=");
else if (!strcmp(s, "patience"))
o->xdl_opts |= XDF_PATIENCE_DIFF;
else if (!strcmp(s, "histogram"))
o->xdl_opts |= XDF_HISTOGRAM_DIFF;
else if (!strcmp(s, "ignore-space-change"))
o->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE;
else if (!strcmp(s, "ignore-all-space"))
Expand Down
12 changes: 12 additions & 0 deletions t/t4049-diff-histogram.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

test_description='histogram diff algorithm'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-diff-alternative.sh

test_diff_frobnitz "histogram"

test_diff_unique "histogram"

test_done
1 change: 1 addition & 0 deletions xdiff/xdiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extern "C" {
#define XDF_IGNORE_WHITESPACE_CHANGE (1 << 3)
#define XDF_IGNORE_WHITESPACE_AT_EOL (1 << 4)
#define XDF_PATIENCE_DIFF (1 << 5)
#define XDF_HISTOGRAM_DIFF (1 << 6)
#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE | XDF_IGNORE_WHITESPACE_AT_EOL)

#define XDL_PATCH_NORMAL '-'
Expand Down
3 changes: 3 additions & 0 deletions xdiff/xdiffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
if (xpp->flags & XDF_PATIENCE_DIFF)
return xdl_do_patience_diff(mf1, mf2, xpp, xe);

if (xpp->flags & XDF_HISTOGRAM_DIFF)
return xdl_do_histogram_diff(mf1, mf2, xpp, xe);

if (xdl_prepare_env(mf1, mf2, xpp, xe) < 0) {

return -1;
Expand Down
2 changes: 2 additions & 0 deletions xdiff/xdiffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
xdemitconf_t const *xecfg);
int xdl_do_patience_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
xdfenv_t *env);
int xdl_do_histogram_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
xdfenv_t *env);

#endif /* #if !defined(XDIFFI_H) */
Loading

0 comments on commit 8c912ee

Please sign in to comment.