Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
9a29f8d5
Commit
9a29f8d5
authored
May 04, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
diff: fix the diffing of two identical blobs
parent
28ef7f9b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
9 deletions
+50
-9
src/diff_output.c
+8
-0
tests-clar/diff/blob.c
+31
-0
tests-clar/diff/diff_helpers.c
+1
-0
tests-clar/diff/diff_helpers.h
+1
-0
tests-clar/diff/tree.c
+9
-9
No files found.
src/diff_output.c
View file @
9a29f8d5
...
...
@@ -747,6 +747,10 @@ int git_diff_blobs(
delta
.
status
=
new
?
(
old
?
GIT_DELTA_MODIFIED
:
GIT_DELTA_ADDED
)
:
(
old
?
GIT_DELTA_DELETED
:
GIT_DELTA_UNTRACKED
);
if
(
git_oid_cmp
(
&
delta
.
new_file
.
oid
,
&
delta
.
old_file
.
oid
)
==
0
)
delta
.
status
=
GIT_DELTA_UNMODIFIED
;
delta
.
old_file
.
size
=
old_data
.
size
;
delta
.
new_file
.
size
=
new_data
.
size
;
...
...
@@ -762,6 +766,10 @@ int git_diff_blobs(
return
error
;
}
/* don't do hunk and line diffs if the two blobs are identical */
if
(
delta
.
status
==
GIT_DELTA_UNMODIFIED
)
return
0
;
/* don't do hunk and line diffs if file is binary */
if
(
delta
.
binary
==
1
)
return
0
;
...
...
tests-clar/diff/blob.c
View file @
9a29f8d5
...
...
@@ -173,6 +173,37 @@ void test_diff_blob__can_compare_against_null_blobs(void)
cl_assert
(
exp
.
lines
==
0
);
}
void
assert_identical_blobs_comparison
(
diff_expects
exp
)
{
cl_assert
(
exp
.
files
==
1
);
cl_assert
(
exp
.
file_unmodified
==
1
);
cl_assert
(
exp
.
hunks
==
0
);
cl_assert
(
exp
.
lines
==
0
);
}
void
test_diff_blob__can_compare_identical_blobs
(
void
)
{
cl_git_pass
(
git_diff_blobs
(
d
,
d
,
&
opts
,
&
exp
,
diff_file_fn
,
diff_hunk_fn
,
diff_line_fn
));
cl_assert
(
exp
.
at_least_one_of_them_is_binary
==
false
);
assert_identical_blobs_comparison
(
exp
);
memset
(
&
exp
,
0
,
sizeof
(
exp
));
cl_git_pass
(
git_diff_blobs
(
NULL
,
NULL
,
&
opts
,
&
exp
,
diff_file_fn
,
diff_hunk_fn
,
diff_line_fn
));
cl_assert
(
exp
.
at_least_one_of_them_is_binary
==
false
);
assert_identical_blobs_comparison
(
exp
);
memset
(
&
exp
,
0
,
sizeof
(
exp
));
cl_git_pass
(
git_diff_blobs
(
alien
,
alien
,
&
opts
,
&
exp
,
diff_file_fn
,
diff_hunk_fn
,
diff_line_fn
));
cl_assert
(
exp
.
at_least_one_of_them_is_binary
==
true
);
assert_identical_blobs_comparison
(
exp
);
}
void
assert_binary_blobs_comparison
(
diff_expects
exp
)
{
cl_assert
(
exp
.
at_least_one_of_them_is_binary
==
true
);
...
...
tests-clar/diff/diff_helpers.c
View file @
9a29f8d5
...
...
@@ -39,6 +39,7 @@ int diff_file_fn(
case
GIT_DELTA_MODIFIED
:
e
->
file_mods
++
;
break
;
case
GIT_DELTA_IGNORED
:
e
->
file_ignored
++
;
break
;
case
GIT_DELTA_UNTRACKED
:
e
->
file_untracked
++
;
break
;
case
GIT_DELTA_UNMODIFIED
:
e
->
file_unmodified
++
;
break
;
default:
break
;
}
return
0
;
...
...
tests-clar/diff/diff_helpers.h
View file @
9a29f8d5
...
...
@@ -11,6 +11,7 @@ typedef struct {
int
file_mods
;
int
file_ignored
;
int
file_untracked
;
int
file_unmodified
;
int
hunks
;
int
hunk_new_lines
;
...
...
tests-clar/diff/tree.c
View file @
9a29f8d5
...
...
@@ -113,16 +113,16 @@ void test_diff_tree__options(void)
*/
diff_expects
test_expects
[]
=
{
/* a vs b tests */
{
5
,
3
,
0
,
2
,
0
,
0
,
4
,
0
,
0
,
51
,
2
,
46
,
3
},
{
5
,
3
,
0
,
2
,
0
,
0
,
4
,
0
,
0
,
53
,
4
,
46
,
3
},
{
5
,
0
,
3
,
2
,
0
,
0
,
4
,
0
,
0
,
52
,
3
,
3
,
46
},
{
5
,
3
,
0
,
2
,
0
,
0
,
5
,
0
,
0
,
54
,
3
,
48
,
3
},
{
5
,
3
,
0
,
2
,
0
,
0
,
0
,
4
,
0
,
0
,
51
,
2
,
46
,
3
},
{
5
,
3
,
0
,
2
,
0
,
0
,
0
,
4
,
0
,
0
,
53
,
4
,
46
,
3
},
{
5
,
0
,
3
,
2
,
0
,
0
,
0
,
4
,
0
,
0
,
52
,
3
,
3
,
46
},
{
5
,
3
,
0
,
2
,
0
,
0
,
0
,
5
,
0
,
0
,
54
,
3
,
48
,
3
},
/* c vs d tests */
{
1
,
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
,
22
,
9
,
10
,
3
},
{
1
,
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
,
19
,
12
,
7
,
0
},
{
1
,
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
,
20
,
11
,
8
,
1
},
{
1
,
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
,
20
,
11
,
8
,
1
},
{
1
,
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
,
18
,
11
,
0
,
7
},
{
1
,
0
,
0
,
1
,
0
,
0
,
0
,
1
,
0
,
0
,
22
,
9
,
10
,
3
},
{
1
,
0
,
0
,
1
,
0
,
0
,
0
,
1
,
0
,
0
,
19
,
12
,
7
,
0
},
{
1
,
0
,
0
,
1
,
0
,
0
,
0
,
1
,
0
,
0
,
20
,
11
,
8
,
1
},
{
1
,
0
,
0
,
1
,
0
,
0
,
0
,
1
,
0
,
0
,
20
,
11
,
8
,
1
},
{
1
,
0
,
0
,
1
,
0
,
0
,
0
,
1
,
0
,
0
,
18
,
11
,
0
,
7
},
{
0
},
};
diff_expects
*
expected
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment