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
11fccddc
Commit
11fccddc
authored
Jan 08, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1212 from arrbee/fix-diff-empty-file
Resolve crash with diff against empty file
parents
f7e4a7c2
de590550
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
1 deletions
+47
-1
src/diff_output.c
+3
-0
src/fileops.c
+1
-1
tests-clar/diff/workdir.c
+43
-0
No files found.
src/diff_output.c
View file @
11fccddc
...
...
@@ -376,6 +376,9 @@ static int get_workdir_content(
goto
close_and_cleanup
;
if
(
error
==
0
)
{
/* note: git_filters_load returns filter count */
if
(
!
file
->
size
)
goto
close_and_cleanup
;
error
=
git_futils_mmap_ro
(
map
,
fd
,
0
,
(
size_t
)
file
->
size
);
file
->
flags
|=
GIT_DIFF_FILE_UNMAP_DATA
;
}
else
{
...
...
src/fileops.c
View file @
11fccddc
...
...
@@ -121,7 +121,7 @@ mode_t git_futils_canonical_mode(mode_t raw_mode)
int
git_futils_readbuffer_fd
(
git_buf
*
buf
,
git_file
fd
,
size_t
len
)
{
ssize_t
read_size
;
ssize_t
read_size
=
0
;
git_buf_clear
(
buf
);
...
...
tests-clar/diff/workdir.c
View file @
11fccddc
...
...
@@ -881,3 +881,46 @@ void test_diff_workdir__checks_options_version(void)
err
=
giterr_last
();
cl_assert_equal_i
(
GITERR_INVALID
,
err
->
klass
);
}
void
test_diff_workdir__can_diff_empty_file
(
void
)
{
git_diff_list
*
diff
;
git_tree
*
tree
;
git_diff_options
opts
=
GIT_DIFF_OPTIONS_INIT
;
struct
stat
st
;
git_diff_patch
*
patch
;
g_repo
=
cl_git_sandbox_init
(
"attr_index"
);
tree
=
resolve_commit_oid_to_tree
(
g_repo
,
"3812cfef3661"
);
/* HEAD */
/* baseline - make sure there are no outstanding diffs */
cl_git_pass
(
git_diff_tree_to_workdir
(
&
diff
,
g_repo
,
tree
,
&
opts
));
cl_assert_equal_i
(
2
,
(
int
)
git_diff_num_deltas
(
diff
));
git_diff_list_free
(
diff
);
/* empty contents of file */
cl_git_rewritefile
(
"attr_index/README.txt"
,
""
);
cl_git_pass
(
git_path_lstat
(
"attr_index/README.txt"
,
&
st
));
cl_assert_equal_i
(
0
,
(
int
)
st
.
st_size
);
cl_git_pass
(
git_diff_tree_to_workdir
(
&
diff
,
g_repo
,
tree
,
&
opts
));
cl_assert_equal_i
(
3
,
(
int
)
git_diff_num_deltas
(
diff
));
/* diffs are: .gitattributes, README.txt, sub/sub/.gitattributes */
cl_git_pass
(
git_diff_get_patch
(
&
patch
,
NULL
,
diff
,
1
));
git_diff_patch_free
(
patch
);
git_diff_list_free
(
diff
);
/* remove a file altogether */
cl_git_pass
(
p_unlink
(
"attr_index/README.txt"
));
cl_assert
(
!
git_path_exists
(
"attr_index/README.txt"
));
cl_git_pass
(
git_diff_tree_to_workdir
(
&
diff
,
g_repo
,
tree
,
&
opts
));
cl_assert_equal_i
(
3
,
(
int
)
git_diff_num_deltas
(
diff
));
cl_git_pass
(
git_diff_get_patch
(
&
patch
,
NULL
,
diff
,
1
));
git_diff_patch_free
(
patch
);
git_diff_list_free
(
diff
);
}
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