Skip to content

Commit ca01600

Browse files
committed
Merge branch 'rc/histogram-diff'
* 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()
2 parents 2f5cb6a + 6486a84 commit ca01600

14 files changed

+655
-285
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,7 @@ ifndef NO_CURL
18761876
GIT_OBJS += http.o http-walker.o remote-curl.o
18771877
endif
18781878
XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \
1879-
xdiff/xmerge.o xdiff/xpatience.o
1879+
xdiff/xmerge.o xdiff/xpatience.o xdiff/xhistogram.o
18801880
VCSSVN_OBJS = vcs-svn/string_pool.o vcs-svn/line_buffer.o \
18811881
vcs-svn/repo_tree.o vcs-svn/fast_export.o vcs-svn/svndump.o
18821882
VCSSVN_TEST_OBJS = test-obj-pool.o test-string-pool.o \

diff.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3393,6 +3393,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
33933393
DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL);
33943394
else if (!strcmp(arg, "--patience"))
33953395
DIFF_XDL_SET(options, PATIENCE_DIFF);
3396+
else if (!strcmp(arg, "--histogram"))
3397+
DIFF_XDL_SET(options, HISTOGRAM_DIFF);
33963398

33973399
/* flags options */
33983400
else if (!strcmp(arg, "--binary")) {

merge-recursive.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,8 @@ int parse_merge_opt(struct merge_options *o, const char *s)
17591759
o->subtree_shift = s + strlen("subtree=");
17601760
else if (!strcmp(s, "patience"))
17611761
o->xdl_opts |= XDF_PATIENCE_DIFF;
1762+
else if (!strcmp(s, "histogram"))
1763+
o->xdl_opts |= XDF_HISTOGRAM_DIFF;
17621764
else if (!strcmp(s, "ignore-space-change"))
17631765
o->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE;
17641766
else if (!strcmp(s, "ignore-all-space"))

t/lib-diff-alternative.sh

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#!/bin/sh
2+
3+
test_diff_frobnitz() {
4+
cat >file1 <<\EOF
5+
#include <stdio.h>
6+
7+
// Frobs foo heartily
8+
int frobnitz(int foo)
9+
{
10+
int i;
11+
for(i = 0; i < 10; i++)
12+
{
13+
printf("Your answer is: ");
14+
printf("%d\n", foo);
15+
}
16+
}
17+
18+
int fact(int n)
19+
{
20+
if(n > 1)
21+
{
22+
return fact(n-1) * n;
23+
}
24+
return 1;
25+
}
26+
27+
int main(int argc, char **argv)
28+
{
29+
frobnitz(fact(10));
30+
}
31+
EOF
32+
33+
cat >file2 <<\EOF
34+
#include <stdio.h>
35+
36+
int fib(int n)
37+
{
38+
if(n > 2)
39+
{
40+
return fib(n-1) + fib(n-2);
41+
}
42+
return 1;
43+
}
44+
45+
// Frobs foo heartily
46+
int frobnitz(int foo)
47+
{
48+
int i;
49+
for(i = 0; i < 10; i++)
50+
{
51+
printf("%d\n", foo);
52+
}
53+
}
54+
55+
int main(int argc, char **argv)
56+
{
57+
frobnitz(fib(10));
58+
}
59+
EOF
60+
61+
cat >expect <<\EOF
62+
diff --git a/file1 b/file2
63+
index 6faa5a3..e3af329 100644
64+
--- a/file1
65+
+++ b/file2
66+
@@ -1,26 +1,25 @@
67+
#include <stdio.h>
68+
69+
+int fib(int n)
70+
+{
71+
+ if(n > 2)
72+
+ {
73+
+ return fib(n-1) + fib(n-2);
74+
+ }
75+
+ return 1;
76+
+}
77+
+
78+
// Frobs foo heartily
79+
int frobnitz(int foo)
80+
{
81+
int i;
82+
for(i = 0; i < 10; i++)
83+
{
84+
- printf("Your answer is: ");
85+
printf("%d\n", foo);
86+
}
87+
}
88+
89+
-int fact(int n)
90+
-{
91+
- if(n > 1)
92+
- {
93+
- return fact(n-1) * n;
94+
- }
95+
- return 1;
96+
-}
97+
-
98+
int main(int argc, char **argv)
99+
{
100+
- frobnitz(fact(10));
101+
+ frobnitz(fib(10));
102+
}
103+
EOF
104+
105+
STRATEGY=$1
106+
107+
test_expect_success "$STRATEGY diff" '
108+
test_must_fail git diff --no-index "--$STRATEGY" file1 file2 > output &&
109+
test_cmp expect output
110+
'
111+
112+
test_expect_success "$STRATEGY diff output is valid" '
113+
mv file2 expect &&
114+
git apply < output &&
115+
test_cmp expect file2
116+
'
117+
}
118+
119+
test_diff_unique() {
120+
cat >uniq1 <<\EOF
121+
1
122+
2
123+
3
124+
4
125+
5
126+
6
127+
EOF
128+
129+
cat >uniq2 <<\EOF
130+
a
131+
b
132+
c
133+
d
134+
e
135+
f
136+
EOF
137+
138+
cat >expect <<\EOF
139+
diff --git a/uniq1 b/uniq2
140+
index b414108..0fdf397 100644
141+
--- a/uniq1
142+
+++ b/uniq2
143+
@@ -1,6 +1,6 @@
144+
-1
145+
-2
146+
-3
147+
-4
148+
-5
149+
-6
150+
+a
151+
+b
152+
+c
153+
+d
154+
+e
155+
+f
156+
EOF
157+
158+
STRATEGY=$1
159+
160+
test_expect_success 'completely different files' '
161+
test_must_fail git diff --no-index "--$STRATEGY" uniq1 uniq2 > output &&
162+
test_cmp expect output
163+
'
164+
}
165+

t/t4033-diff-patience.sh

Lines changed: 3 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -3,166 +3,10 @@
33
test_description='patience diff algorithm'
44

55
. ./test-lib.sh
6+
. "$TEST_DIRECTORY"/lib-diff-alternative.sh
67

7-
cat >file1 <<\EOF
8-
#include <stdio.h>
8+
test_diff_frobnitz "patience"
99

10-
// Frobs foo heartily
11-
int frobnitz(int foo)
12-
{
13-
int i;
14-
for(i = 0; i < 10; i++)
15-
{
16-
printf("Your answer is: ");
17-
printf("%d\n", foo);
18-
}
19-
}
20-
21-
int fact(int n)
22-
{
23-
if(n > 1)
24-
{
25-
return fact(n-1) * n;
26-
}
27-
return 1;
28-
}
29-
30-
int main(int argc, char **argv)
31-
{
32-
frobnitz(fact(10));
33-
}
34-
EOF
35-
36-
cat >file2 <<\EOF
37-
#include <stdio.h>
38-
39-
int fib(int n)
40-
{
41-
if(n > 2)
42-
{
43-
return fib(n-1) + fib(n-2);
44-
}
45-
return 1;
46-
}
47-
48-
// Frobs foo heartily
49-
int frobnitz(int foo)
50-
{
51-
int i;
52-
for(i = 0; i < 10; i++)
53-
{
54-
printf("%d\n", foo);
55-
}
56-
}
57-
58-
int main(int argc, char **argv)
59-
{
60-
frobnitz(fib(10));
61-
}
62-
EOF
63-
64-
cat >expect <<\EOF
65-
diff --git a/file1 b/file2
66-
index 6faa5a3..e3af329 100644
67-
--- a/file1
68-
+++ b/file2
69-
@@ -1,26 +1,25 @@
70-
#include <stdio.h>
71-
72-
+int fib(int n)
73-
+{
74-
+ if(n > 2)
75-
+ {
76-
+ return fib(n-1) + fib(n-2);
77-
+ }
78-
+ return 1;
79-
+}
80-
+
81-
// Frobs foo heartily
82-
int frobnitz(int foo)
83-
{
84-
int i;
85-
for(i = 0; i < 10; i++)
86-
{
87-
- printf("Your answer is: ");
88-
printf("%d\n", foo);
89-
}
90-
}
91-
92-
-int fact(int n)
93-
-{
94-
- if(n > 1)
95-
- {
96-
- return fact(n-1) * n;
97-
- }
98-
- return 1;
99-
-}
100-
-
101-
int main(int argc, char **argv)
102-
{
103-
- frobnitz(fact(10));
104-
+ frobnitz(fib(10));
105-
}
106-
EOF
107-
108-
test_expect_success 'patience diff' '
109-
110-
test_must_fail git diff --no-index --patience file1 file2 > output &&
111-
test_cmp expect output
112-
113-
'
114-
115-
test_expect_success 'patience diff output is valid' '
116-
117-
mv file2 expect &&
118-
git apply < output &&
119-
test_cmp expect file2
120-
121-
'
122-
123-
cat >uniq1 <<\EOF
124-
1
125-
2
126-
3
127-
4
128-
5
129-
6
130-
EOF
131-
132-
cat >uniq2 <<\EOF
133-
a
134-
b
135-
c
136-
d
137-
e
138-
f
139-
EOF
140-
141-
cat >expect <<\EOF
142-
diff --git a/uniq1 b/uniq2
143-
index b414108..0fdf397 100644
144-
--- a/uniq1
145-
+++ b/uniq2
146-
@@ -1,6 +1,6 @@
147-
-1
148-
-2
149-
-3
150-
-4
151-
-5
152-
-6
153-
+a
154-
+b
155-
+c
156-
+d
157-
+e
158-
+f
159-
EOF
160-
161-
test_expect_success 'completely different files' '
162-
163-
test_must_fail git diff --no-index --patience uniq1 uniq2 > output &&
164-
test_cmp expect output
165-
166-
'
10+
test_diff_unique "patience"
16711

16812
test_done

t/t4050-diff-histogram.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
test_description='histogram diff algorithm'
4+
5+
. ./test-lib.sh
6+
. "$TEST_DIRECTORY"/lib-diff-alternative.sh
7+
8+
test_diff_frobnitz "histogram"
9+
10+
test_diff_unique "histogram"
11+
12+
test_done

xdiff/xdiff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern "C" {
3333
#define XDF_IGNORE_WHITESPACE_CHANGE (1 << 3)
3434
#define XDF_IGNORE_WHITESPACE_AT_EOL (1 << 4)
3535
#define XDF_PATIENCE_DIFF (1 << 5)
36+
#define XDF_HISTOGRAM_DIFF (1 << 6)
3637
#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE | XDF_IGNORE_WHITESPACE_AT_EOL)
3738

3839
#define XDL_PATCH_NORMAL '-'
@@ -105,7 +106,6 @@ typedef struct s_bdiffparam {
105106
#define xdl_realloc(ptr,x) realloc(ptr,x)
106107

107108
void *xdl_mmfile_first(mmfile_t *mmf, long *size);
108-
void *xdl_mmfile_next(mmfile_t *mmf, long *size);
109109
long xdl_mmfile_size(mmfile_t *mmf);
110110

111111
int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,

0 commit comments

Comments
 (0)