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
0ba62ba5
Commit
0ba62ba5
authored
Aug 15, 2015
by
Edward Thomson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3384 from libgit2/cmn/regex-nofail
diff: don't error out on an invalid regex
parents
f594b6ff
e451cd5c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
7 deletions
+32
-7
src/diff_driver.c
+6
-7
tests/diff/drivers.c
+26
-0
No files found.
src/diff_driver.c
View file @
0ba62ba5
...
...
@@ -97,8 +97,7 @@ static int diff_driver_add_patterns(
for
(
scan
=
regex_str
;
scan
;
scan
=
end
)
{
/* get pattern to fill in */
if
((
pat
=
git_array_alloc
(
drv
->
fn_patterns
))
==
NULL
)
{
error
=
-
1
;
break
;
return
-
1
;
}
pat
->
flags
=
regex_flags
;
...
...
@@ -117,10 +116,9 @@ static int diff_driver_add_patterns(
break
;
if
((
error
=
regcomp
(
&
pat
->
re
,
buf
.
ptr
,
regex_flags
))
!=
0
)
{
/* if regex fails to compile, warn? fail? */
error
=
giterr_set_regex
(
&
pat
->
re
,
error
);
regfree
(
&
pat
->
re
);
break
;
/*
* TODO: issue a warning
*/
}
}
...
...
@@ -128,7 +126,8 @@ static int diff_driver_add_patterns(
(
void
)
git_array_pop
(
drv
->
fn_patterns
);
/* release last item */
git_buf_free
(
&
buf
);
return
error
;
/* We want to ignore bad patterns, so return success regardless */
return
0
;
}
static
int
diff_driver_xfuncname
(
const
git_config_entry
*
entry
,
void
*
payload
)
...
...
tests/diff/drivers.c
View file @
0ba62ba5
...
...
@@ -250,3 +250,29 @@ void test_diff_drivers__builtins(void)
git_buf_free
(
&
expected
);
git_vector_free
(
&
files
);
}
void
test_diff_drivers__invalid_pattern
(
void
)
{
git_config
*
cfg
;
git_index
*
idx
;
git_diff
*
diff
;
git_patch
*
patch
;
git_diff_options
opts
=
GIT_DIFF_OPTIONS_INIT
;
g_repo
=
cl_git_sandbox_init
(
"userdiff"
);
cl_git_mkfile
(
"userdiff/.gitattributes"
,
"*.storyboard diff=storyboard
\n
"
);
cl_git_pass
(
git_repository_config__weakptr
(
&
cfg
,
g_repo
));
cl_git_pass
(
git_config_set_string
(
cfg
,
"diff.storyboard.xfuncname"
,
"<!--(.*?)-->"
));
cl_git_mkfile
(
"userdiff/dummy.storyboard"
,
""
);
cl_git_pass
(
git_repository_index__weakptr
(
&
idx
,
g_repo
));
cl_git_pass
(
git_index_add_bypath
(
idx
,
"dummy.storyboard"
));
cl_git_mkfile
(
"userdiff/dummy.storyboard"
,
"some content
\n
"
);
cl_git_pass
(
git_diff_index_to_workdir
(
&
diff
,
g_repo
,
NULL
,
&
opts
));
cl_git_pass
(
git_patch_from_diff
(
&
patch
,
diff
,
0
));
git_patch_free
(
patch
);
git_diff_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