Skip to content

Commit

Permalink
Merge branch 'rc/histogram-diff'
Browse files Browse the repository at this point in the history
* rc/histogram-diff:
  xdiff/xhistogram: drop need for additional variable
  xdiff/xhistogram: rely on xdl_trim_ends()
  xdiff/xhistogram: rework handling of recursed results
  xdiff: do away with xdl_mmfile_next()
  Make test number unique
  xdiff/xprepare: use a smaller sample size for histogram diff
  xdiff/xprepare: skip classification
  teach --histogram to diff
  t4033-diff-patience: factor out tests
  xdiff/xpatience: factor out fall-back-diff function
  xdiff/xprepare: refactor abort cleanups
  xdiff/xprepare: use memset()
  • Loading branch information
Junio C Hamano committed Aug 18, 2011
2 parents 2f5cb6a + 6486a84 commit ca01600
Show file tree
Hide file tree
Showing 14 changed files with 655 additions and 285 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,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 @@ -3393,6 +3393,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
165 changes: 165 additions & 0 deletions t/lib-diff-alternative.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#!/bin/sh

test_diff_frobnitz() {
cat >file1 <<\EOF
#include <stdio.h>
// Frobs foo heartily
int frobnitz(int foo)
{
int i;
for(i = 0; i < 10; i++)
{
printf("Your answer is: ");
printf("%d\n", foo);
}
}
int fact(int n)
{
if(n > 1)
{
return fact(n-1) * n;
}
return 1;
}
int main(int argc, char **argv)
{
frobnitz(fact(10));
}
EOF

cat >file2 <<\EOF
#include <stdio.h>
int fib(int n)
{
if(n > 2)
{
return fib(n-1) + fib(n-2);
}
return 1;
}
// Frobs foo heartily
int frobnitz(int foo)
{
int i;
for(i = 0; i < 10; i++)
{
printf("%d\n", foo);
}
}
int main(int argc, char **argv)
{
frobnitz(fib(10));
}
EOF

cat >expect <<\EOF
diff --git a/file1 b/file2
index 6faa5a3..e3af329 100644
--- a/file1
+++ b/file2
@@ -1,26 +1,25 @@
#include <stdio.h>
+int fib(int n)
+{
+ if(n > 2)
+ {
+ return fib(n-1) + fib(n-2);
+ }
+ return 1;
+}
+
// Frobs foo heartily
int frobnitz(int foo)
{
int i;
for(i = 0; i < 10; i++)
{
- printf("Your answer is: ");
printf("%d\n", foo);
}
}
-int fact(int n)
-{
- if(n > 1)
- {
- return fact(n-1) * n;
- }
- return 1;
-}
-
int main(int argc, char **argv)
{
- frobnitz(fact(10));
+ frobnitz(fib(10));
}
EOF

STRATEGY=$1

test_expect_success "$STRATEGY diff" '
test_must_fail git diff --no-index "--$STRATEGY" file1 file2 > output &&
test_cmp expect output
'

test_expect_success "$STRATEGY diff output is valid" '
mv file2 expect &&
git apply < output &&
test_cmp expect file2
'
}

test_diff_unique() {
cat >uniq1 <<\EOF
1
2
3
4
5
6
EOF

cat >uniq2 <<\EOF
a
b
c
d
e
f
EOF

cat >expect <<\EOF
diff --git a/uniq1 b/uniq2
index b414108..0fdf397 100644
--- a/uniq1
+++ b/uniq2
@@ -1,6 +1,6 @@
-1
-2
-3
-4
-5
-6
+a
+b
+c
+d
+e
+f
EOF

STRATEGY=$1

test_expect_success 'completely different files' '
test_must_fail git diff --no-index "--$STRATEGY" uniq1 uniq2 > output &&
test_cmp expect output
'
}

162 changes: 3 additions & 159 deletions t/t4033-diff-patience.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,166 +3,10 @@
test_description='patience diff algorithm'

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

cat >file1 <<\EOF
#include <stdio.h>
test_diff_frobnitz "patience"

// Frobs foo heartily
int frobnitz(int foo)
{
int i;
for(i = 0; i < 10; i++)
{
printf("Your answer is: ");
printf("%d\n", foo);
}
}
int fact(int n)
{
if(n > 1)
{
return fact(n-1) * n;
}
return 1;
}
int main(int argc, char **argv)
{
frobnitz(fact(10));
}
EOF

cat >file2 <<\EOF
#include <stdio.h>
int fib(int n)
{
if(n > 2)
{
return fib(n-1) + fib(n-2);
}
return 1;
}
// Frobs foo heartily
int frobnitz(int foo)
{
int i;
for(i = 0; i < 10; i++)
{
printf("%d\n", foo);
}
}
int main(int argc, char **argv)
{
frobnitz(fib(10));
}
EOF

cat >expect <<\EOF
diff --git a/file1 b/file2
index 6faa5a3..e3af329 100644
--- a/file1
+++ b/file2
@@ -1,26 +1,25 @@
#include <stdio.h>
+int fib(int n)
+{
+ if(n > 2)
+ {
+ return fib(n-1) + fib(n-2);
+ }
+ return 1;
+}
+
// Frobs foo heartily
int frobnitz(int foo)
{
int i;
for(i = 0; i < 10; i++)
{
- printf("Your answer is: ");
printf("%d\n", foo);
}
}
-int fact(int n)
-{
- if(n > 1)
- {
- return fact(n-1) * n;
- }
- return 1;
-}
-
int main(int argc, char **argv)
{
- frobnitz(fact(10));
+ frobnitz(fib(10));
}
EOF

test_expect_success 'patience diff' '
test_must_fail git diff --no-index --patience file1 file2 > output &&
test_cmp expect output
'

test_expect_success 'patience diff output is valid' '
mv file2 expect &&
git apply < output &&
test_cmp expect file2
'

cat >uniq1 <<\EOF
1
2
3
4
5
6
EOF

cat >uniq2 <<\EOF
a
b
c
d
e
f
EOF

cat >expect <<\EOF
diff --git a/uniq1 b/uniq2
index b414108..0fdf397 100644
--- a/uniq1
+++ b/uniq2
@@ -1,6 +1,6 @@
-1
-2
-3
-4
-5
-6
+a
+b
+c
+d
+e
+f
EOF

test_expect_success 'completely different files' '
test_must_fail git diff --no-index --patience uniq1 uniq2 > output &&
test_cmp expect output
'
test_diff_unique "patience"

test_done
12 changes: 12 additions & 0 deletions t/t4050-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
2 changes: 1 addition & 1 deletion 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 Expand Up @@ -105,7 +106,6 @@ typedef struct s_bdiffparam {
#define xdl_realloc(ptr,x) realloc(ptr,x)

void *xdl_mmfile_first(mmfile_t *mmf, long *size);
void *xdl_mmfile_next(mmfile_t *mmf, long *size);
long xdl_mmfile_size(mmfile_t *mmf);

int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
Expand Down
Loading

0 comments on commit ca01600

Please sign in to comment.