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
513e794e
Commit
513e794e
authored
Nov 13, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1068 from carlosmn/config-empty-value
Deal with empty and nonexsitent values in config
parents
f6c18dda
0da81d2b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
25 deletions
+46
-25
src/config.c
+24
-14
src/config_file.c
+3
-1
src/remote.c
+4
-2
src/util.c
+4
-7
tests-clar/config/read.c
+9
-1
tests-clar/resources/config/config4
+2
-0
No files found.
src/config.c
View file @
513e794e
...
...
@@ -393,24 +393,11 @@ int git_config_get_int32(int32_t *out, git_config *cfg, const char *name)
return
git_config_parse_int32
(
out
,
value
);
}
int
git_config_get_bool
(
int
*
out
,
git_config
*
cfg
,
const
char
*
name
)
{
const
char
*
value
;
int
ret
;
if
((
ret
=
git_config_get_string
(
&
value
,
cfg
,
name
))
<
0
)
return
ret
;
return
git_config_parse_bool
(
out
,
value
);
}
static
int
get_string_at_file
(
const
char
**
out
,
git_config_file
*
file
,
const
char
*
name
)
{
const
git_config_entry
*
entry
;
int
res
;
*
out
=
NULL
;
res
=
file
->
get
(
file
,
name
,
&
entry
);
if
(
!
res
)
*
out
=
entry
->
value
;
...
...
@@ -418,7 +405,7 @@ static int get_string_at_file(const char **out, git_config_file *file, const cha
return
res
;
}
int
git_config_
get_string
(
const
char
**
out
,
git_config
*
cfg
,
const
char
*
name
)
static
int
get_string
(
const
char
**
out
,
git_config
*
cfg
,
const
char
*
name
)
{
file_internal
*
internal
;
unsigned
int
i
;
...
...
@@ -435,6 +422,29 @@ int git_config_get_string(const char **out, git_config *cfg, const char *name)
return
GIT_ENOTFOUND
;
}
int
git_config_get_bool
(
int
*
out
,
git_config
*
cfg
,
const
char
*
name
)
{
const
char
*
value
;
int
ret
;
if
((
ret
=
get_string
(
&
value
,
cfg
,
name
))
<
0
)
return
ret
;
return
git_config_parse_bool
(
out
,
value
);
}
int
git_config_get_string
(
const
char
**
out
,
git_config
*
cfg
,
const
char
*
name
)
{
int
ret
;
const
char
*
str
;
if
((
ret
=
get_string
(
&
str
,
cfg
,
name
))
<
0
)
return
ret
;
*
out
=
str
==
NULL
?
""
:
str
;
return
0
;
}
int
git_config_get_entry
(
const
git_config_entry
**
out
,
git_config
*
cfg
,
const
char
*
name
)
{
file_internal
*
internal
;
...
...
src/config_file.c
View file @
513e794e
...
...
@@ -1432,8 +1432,10 @@ static int parse_variable(diskfile_backend *cfg, char **var_name, char **var_val
else
if
(
value_start
[
0
]
!=
'\0'
)
{
*
var_value
=
fixup_line
(
value_start
,
0
);
GITERR_CHECK_ALLOC
(
*
var_value
);
}
else
{
/* equals sign but missing rhs */
*
var_value
=
git__strdup
(
""
);
GITERR_CHECK_ALLOC
(
*
var_value
);
}
}
git__free
(
line
);
...
...
src/remote.c
View file @
513e794e
...
...
@@ -136,7 +136,7 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
if
((
error
=
git_config_get_string
(
&
val
,
config
,
git_buf_cstr
(
&
buf
)))
<
0
)
goto
cleanup
;
if
(
!
val
)
{
if
(
strlen
(
val
)
==
0
)
{
giterr_set
(
GITERR_INVALID
,
"Malformed remote '%s' - missing URL"
,
name
);
error
=
-
1
;
goto
cleanup
;
...
...
@@ -153,8 +153,10 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
}
error
=
git_config_get_string
(
&
val
,
config
,
git_buf_cstr
(
&
buf
));
if
(
error
==
GIT_ENOTFOUND
)
if
(
error
==
GIT_ENOTFOUND
)
{
val
=
NULL
;
error
=
0
;
}
if
(
error
<
0
)
{
error
=
-
1
;
...
...
src/util.c
View file @
513e794e
...
...
@@ -432,12 +432,8 @@ int git__strcmp_cb(const void *a, const void *b)
int
git__parse_bool
(
int
*
out
,
const
char
*
value
)
{
/* A missing value means true */
if
(
value
==
NULL
)
{
*
out
=
1
;
return
0
;
}
if
(
!
strcasecmp
(
value
,
"true"
)
||
if
(
value
==
NULL
||
!
strcasecmp
(
value
,
"true"
)
||
!
strcasecmp
(
value
,
"yes"
)
||
!
strcasecmp
(
value
,
"on"
))
{
*
out
=
1
;
...
...
@@ -445,7 +441,8 @@ int git__parse_bool(int *out, const char *value)
}
if
(
!
strcasecmp
(
value
,
"false"
)
||
!
strcasecmp
(
value
,
"no"
)
||
!
strcasecmp
(
value
,
"off"
))
{
!
strcasecmp
(
value
,
"off"
)
||
value
[
0
]
==
'\0'
)
{
*
out
=
0
;
return
0
;
}
...
...
tests-clar/config/read.c
View file @
513e794e
...
...
@@ -87,12 +87,20 @@ void test_config_read__lone_variable(void)
cl_git_pass
(
git_config_open_ondisk
(
&
cfg
,
cl_fixture
(
"config/config4"
)));
cl_git_fail
(
git_config_get_int32
(
&
i
,
cfg
,
"some.section.variable"
));
cl_git_pass
(
git_config_get_string
(
&
str
,
cfg
,
"some.section.variable"
));
cl_assert
(
str
==
NULL
);
cl_assert
_equal_s
(
str
,
""
);
cl_git_pass
(
git_config_get_bool
(
&
i
,
cfg
,
"some.section.variable"
));
cl_assert
(
i
==
1
);
cl_git_pass
(
git_config_get_string
(
&
str
,
cfg
,
"some.section.variableeq"
));
cl_assert_equal_s
(
str
,
""
);
cl_git_pass
(
git_config_get_bool
(
&
i
,
cfg
,
"some.section.variableeq"
));
cl_assert
(
i
==
0
);
git_config_free
(
cfg
);
}
...
...
tests-clar/resources/config/config4
View file @
513e794e
# A variable name on its own is valid
[some.section]
variable
# A variable and '=' is accepted, but it's not considered true
variableeq =
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