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
5d6c2f26
Commit
5d6c2f26
authored
Apr 05, 2020
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
diff: use GIT_ASSERT
parent
81609902
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
34 deletions
+53
-34
src/diff.c
+11
-8
src/diff_driver.c
+1
-1
src/diff_generate.c
+19
-10
src/diff_print.c
+8
-4
src/diff_stats.c
+7
-5
src/diff_tform.c
+7
-6
No files found.
src/diff.c
View file @
5d6c2f26
...
...
@@ -77,7 +77,7 @@ void git_diff_addref(git_diff *diff)
size_t
git_diff_num_deltas
(
const
git_diff
*
diff
)
{
assert
(
diff
);
GIT_ASSERT_ARG
(
diff
);
return
diff
->
deltas
.
length
;
}
...
...
@@ -86,7 +86,7 @@ size_t git_diff_num_deltas_of_type(const git_diff *diff, git_delta_t type)
size_t
i
,
count
=
0
;
const
git_diff_delta
*
delta
;
assert
(
diff
);
GIT_ASSERT_ARG
(
diff
);
git_vector_foreach
(
&
diff
->
deltas
,
i
,
delta
)
{
count
+=
(
delta
->
status
==
type
);
...
...
@@ -97,7 +97,7 @@ size_t git_diff_num_deltas_of_type(const git_diff *diff, git_delta_t type)
const
git_diff_delta
*
git_diff_get_delta
(
const
git_diff
*
diff
,
size_t
idx
)
{
assert
(
diff
);
GIT_ASSERT_ARG_WITH_RETVAL
(
diff
,
NULL
);
return
git_vector_get
(
&
diff
->
deltas
,
idx
);
}
...
...
@@ -108,7 +108,7 @@ int git_diff_is_sorted_icase(const git_diff *diff)
int
git_diff_get_perfdata
(
git_diff_perfdata
*
out
,
const
git_diff
*
diff
)
{
assert
(
out
);
GIT_ASSERT_ARG
(
out
);
GIT_ERROR_CHECK_VERSION
(
out
,
GIT_DIFF_PERFDATA_VERSION
,
"git_diff_perfdata"
);
out
->
stat_calls
=
diff
->
perf
.
stat_calls
;
out
->
oid_calculations
=
diff
->
perf
.
oid_calculations
;
...
...
@@ -127,7 +127,7 @@ int git_diff_foreach(
git_diff_delta
*
delta
;
size_t
idx
;
assert
(
diff
);
GIT_ASSERT_ARG
(
diff
);
git_vector_foreach
(
&
diff
->
deltas
,
idx
,
delta
)
{
git_patch
*
patch
;
...
...
@@ -243,8 +243,9 @@ int git_diff_format_email(
size_t
allocsize
;
int
error
;
assert
(
out
&&
diff
&&
opts
);
assert
(
opts
->
summary
&&
opts
->
id
&&
opts
->
author
);
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
diff
);
GIT_ASSERT_ARG
(
opts
&&
opts
->
summary
&&
opts
->
id
&&
opts
->
author
);
GIT_ERROR_CHECK_VERSION
(
opts
,
GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION
,
...
...
@@ -326,7 +327,9 @@ int git_diff_commit_as_email(
GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT
;
int
error
;
assert
(
out
&&
repo
&&
commit
);
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
repo
);
GIT_ASSERT_ARG
(
commit
);
opts
.
flags
=
flags
;
opts
.
patch_no
=
patch_no
;
...
...
src/diff_driver.c
View file @
5d6c2f26
...
...
@@ -358,7 +358,7 @@ int git_diff_driver_lookup(
int
error
=
0
;
const
char
*
values
[
1
],
*
attrs
[]
=
{
"diff"
};
assert
(
out
);
GIT_ASSERT_ARG
(
out
);
*
out
=
NULL
;
if
(
!
repo
||
!
path
||
!
strlen
(
path
))
...
...
src/diff_generate.c
View file @
5d6c2f26
...
...
@@ -128,7 +128,7 @@ static int diff_delta__from_one(
git_diff_delta
*
delta
;
const
char
*
matched_pathspec
;
assert
((
oitem
!=
NULL
)
^
(
nitem
!=
NULL
));
GIT_ASSERT_ARG
((
oitem
!=
NULL
)
^
(
nitem
!=
NULL
));
if
(
oitem
)
{
entry
=
oitem
;
...
...
@@ -160,7 +160,7 @@ static int diff_delta__from_one(
GIT_ERROR_CHECK_ALLOC
(
delta
);
/* This fn is just for single-sided diffs */
assert
(
status
!=
GIT_DELTA_MODIFIED
);
GIT_ASSERT
(
status
!=
GIT_DELTA_MODIFIED
);
delta
->
nfiles
=
1
;
if
(
has_old
)
{
...
...
@@ -408,7 +408,9 @@ static git_diff_generated *diff_generated_alloc(
git_diff_generated
*
diff
;
git_diff_options
dflt
=
GIT_DIFF_OPTIONS_INIT
;
assert
(
repo
&&
old_iter
&&
new_iter
);
GIT_ASSERT_ARG_WITH_RETVAL
(
repo
,
NULL
);
GIT_ASSERT_ARG_WITH_RETVAL
(
old_iter
,
NULL
);
GIT_ASSERT_ARG_WITH_RETVAL
(
new_iter
,
NULL
);
if
((
diff
=
git__calloc
(
1
,
sizeof
(
git_diff_generated
)))
==
NULL
)
return
NULL
;
...
...
@@ -589,7 +591,7 @@ int git_diff__oid_for_entry(
git_filter_list
*
fl
=
NULL
;
int
error
=
0
;
assert
(
d
->
type
==
GIT_DIFF_TYPE_GENERATED
);
GIT_ASSERT
(
d
->
type
==
GIT_DIFF_TYPE_GENERATED
);
diff
=
(
git_diff_generated
*
)
d
;
memset
(
out
,
0
,
sizeof
(
*
out
));
...
...
@@ -1302,7 +1304,8 @@ int git_diff_tree_to_tree(
char
*
prefix
=
NULL
;
int
error
=
0
;
assert
(
out
&&
repo
);
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
repo
);
*
out
=
NULL
;
...
...
@@ -1358,7 +1361,8 @@ int git_diff_tree_to_index(
bool
index_ignore_case
=
false
;
int
error
=
0
;
assert
(
out
&&
repo
);
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
repo
);
*
out
=
NULL
;
...
...
@@ -1401,7 +1405,8 @@ int git_diff_index_to_workdir(
char
*
prefix
=
NULL
;
int
error
=
0
;
assert
(
out
&&
repo
);
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
repo
);
*
out
=
NULL
;
...
...
@@ -1444,7 +1449,8 @@ int git_diff_tree_to_workdir(
git_index
*
index
;
int
error
;
assert
(
out
&&
repo
);
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
repo
);
*
out
=
NULL
;
...
...
@@ -1477,7 +1483,8 @@ int git_diff_tree_to_workdir_with_index(
git_index
*
index
=
NULL
;
int
error
=
0
;
assert
(
out
&&
repo
);
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
repo
);
*
out
=
NULL
;
...
...
@@ -1513,7 +1520,9 @@ int git_diff_index_to_index(
char
*
prefix
=
NULL
;
int
error
;
assert
(
out
&&
old_index
&&
new_index
);
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
old_index
);
GIT_ASSERT_ARG
(
new_index
);
*
out
=
NULL
;
...
...
src/diff_print.c
View file @
5d6c2f26
...
...
@@ -95,7 +95,7 @@ static int diff_print_info_init_frompatch(
git_diff_line_cb
cb
,
void
*
payload
)
{
assert
(
patch
);
GIT_ASSERT_ARG
(
patch
);
memset
(
pi
,
0
,
sizeof
(
diff_print_info
));
...
...
@@ -766,7 +766,9 @@ int git_diff_to_buf(git_buf *out, git_diff *diff, git_diff_format_t format)
{
int
error
;
assert
(
out
&&
diff
);
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
diff
);
if
((
error
=
git_buf_sanitize
(
out
))
<
0
)
return
error
;
...
...
@@ -783,7 +785,8 @@ int git_patch_print(
diff_print_info
pi
;
int
error
;
assert
(
patch
&&
print_cb
);
GIT_ASSERT_ARG
(
patch
);
GIT_ASSERT_ARG
(
print_cb
);
if
((
error
=
diff_print_info_init_frompatch
(
&
pi
,
&
temp
,
patch
,
GIT_DIFF_FORMAT_PATCH
,
print_cb
,
payload
))
<
0
)
...
...
@@ -805,7 +808,8 @@ int git_patch_to_buf(git_buf *out, git_patch *patch)
{
int
error
;
assert
(
out
&&
patch
);
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
patch
);
if
((
error
=
git_buf_sanitize
(
out
))
<
0
)
return
error
;
...
...
src/diff_stats.c
View file @
5d6c2f26
...
...
@@ -183,7 +183,8 @@ int git_diff_get_stats(
git_diff_stats
*
stats
=
NULL
;
int
error
=
0
;
assert
(
out
&&
diff
);
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
diff
);
stats
=
git__calloc
(
1
,
sizeof
(
git_diff_stats
));
GIT_ERROR_CHECK_ALLOC
(
stats
);
...
...
@@ -251,7 +252,7 @@ int git_diff_get_stats(
size_t
git_diff_stats_files_changed
(
const
git_diff_stats
*
stats
)
{
assert
(
stats
);
GIT_ASSERT_ARG
(
stats
);
return
stats
->
files_changed
;
}
...
...
@@ -259,7 +260,7 @@ size_t git_diff_stats_files_changed(
size_t
git_diff_stats_insertions
(
const
git_diff_stats
*
stats
)
{
assert
(
stats
);
GIT_ASSERT_ARG
(
stats
);
return
stats
->
insertions
;
}
...
...
@@ -267,7 +268,7 @@ size_t git_diff_stats_insertions(
size_t
git_diff_stats_deletions
(
const
git_diff_stats
*
stats
)
{
assert
(
stats
);
GIT_ASSERT_ARG
(
stats
);
return
stats
->
deletions
;
}
...
...
@@ -282,7 +283,8 @@ int git_diff_stats_to_buf(
size_t
i
;
const
git_diff_delta
*
delta
;
assert
(
out
&&
stats
);
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
stats
);
if
(
format
&
GIT_DIFF_STATS_NUMBER
)
{
for
(
i
=
0
;
i
<
stats
->
files_changed
;
++
i
)
{
...
...
src/diff_tform.c
View file @
5d6c2f26
...
...
@@ -87,7 +87,7 @@ git_diff_delta *git_diff__merge_like_cgit(
a
->
status
==
GIT_DELTA_UNREADABLE
)
return
dup
;
assert
(
b
->
status
!=
GIT_DELTA_UNMODIFIED
);
GIT_ASSERT_WITH_RETVAL
(
b
->
status
!=
GIT_DELTA_UNMODIFIED
,
NULL
);
/* A cgit exception is that the diff of a file that is only in the
* index (i.e. not in HEAD nor workdir) is given as empty.
...
...
@@ -121,7 +121,8 @@ int git_diff__merge(
bool
ignore_case
,
reversed
;
unsigned
int
i
,
j
;
assert
(
onto
&&
from
);
GIT_ASSERT_ARG
(
onto
);
GIT_ASSERT_ARG
(
from
);
if
(
!
from
->
deltas
.
length
)
return
0
;
...
...
@@ -815,7 +816,7 @@ int git_diff_find_similar(
diff_find_match
*
best_match
;
git_diff_file
swap
;
assert
(
diff
);
GIT_ASSERT_ARG
(
diff
);
if
((
error
=
normalize_find_opts
(
diff
,
&
opts
,
given_opts
))
<
0
)
return
error
;
...
...
@@ -978,7 +979,7 @@ find_best_matches:
src
->
flags
|=
GIT_DIFF_FLAG__TO_DELETE
;
num_rewrites
++
;
}
else
{
assert
(
delta_is_split
(
tgt
));
GIT_ASSERT
(
delta_is_split
(
tgt
));
if
(
best_match
->
similarity
<
opts
.
rename_from_rewrite_threshold
)
continue
;
...
...
@@ -988,7 +989,7 @@ find_best_matches:
delta_make_rename
(
tgt
,
src
,
best_match
->
similarity
);
num_rewrites
--
;
assert
(
src
->
status
==
GIT_DELTA_DELETED
);
GIT_ASSERT
(
src
->
status
==
GIT_DELTA_DELETED
);
memcpy
(
&
src
->
old_file
,
&
swap
,
sizeof
(
src
->
old_file
));
memset
(
&
src
->
new_file
,
0
,
sizeof
(
src
->
new_file
));
src
->
new_file
.
path
=
src
->
old_file
.
path
;
...
...
@@ -1024,7 +1025,7 @@ find_best_matches:
num_updates
++
;
}
else
{
assert
(
delta_is_split
(
src
));
GIT_ASSERT
(
delta_is_split
(
src
));
if
(
best_match
->
similarity
<
opts
.
rename_from_rewrite_threshold
)
continue
;
...
...
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