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
2f0450f4
Commit
2f0450f4
authored
Mar 29, 2016
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3712 from ethomson/config_duplicate_section
config: don't write duplicate section
parents
b085ecbe
76e1a679
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
4 deletions
+33
-4
src/config_file.c
+9
-4
tests/config/write.c
+24
-0
No files found.
src/config_file.c
View file @
2f0450f4
...
...
@@ -1483,7 +1483,7 @@ static int config_parse(
int
(
*
on_section
)(
struct
reader
**
reader
,
const
char
*
current_section
,
const
char
*
line
,
size_t
line_len
,
void
*
data
),
int
(
*
on_variable
)(
struct
reader
**
reader
,
const
char
*
current_section
,
char
*
var_name
,
char
*
var_value
,
const
char
*
line
,
size_t
line_len
,
void
*
data
),
int
(
*
on_comment
)(
struct
reader
**
reader
,
const
char
*
line
,
size_t
line_len
,
void
*
data
),
int
(
*
on_eof
)(
struct
reader
**
reader
,
void
*
data
),
int
(
*
on_eof
)(
struct
reader
**
reader
,
const
char
*
current_section
,
void
*
data
),
void
*
data
)
{
char
*
current_section
=
NULL
,
*
var_name
,
*
var_value
,
*
line_start
;
...
...
@@ -1534,7 +1534,7 @@ static int config_parse(
}
if
(
on_eof
)
result
=
on_eof
(
&
reader
,
data
);
result
=
on_eof
(
&
reader
,
current_section
,
data
);
git__free
(
current_section
);
return
result
;
...
...
@@ -1850,7 +1850,8 @@ static int write_on_comment(struct reader **reader, const char *line, size_t lin
return
write_line_to
(
&
write_data
->
buffered_comment
,
line
,
line_len
);
}
static
int
write_on_eof
(
struct
reader
**
reader
,
void
*
data
)
static
int
write_on_eof
(
struct
reader
**
reader
,
const
char
*
current_section
,
void
*
data
)
{
struct
write_data
*
write_data
=
(
struct
write_data
*
)
data
;
int
result
=
0
;
...
...
@@ -1869,7 +1870,11 @@ static int write_on_eof(struct reader **reader, void *data)
* value.
*/
if
((
!
write_data
->
preg
||
!
write_data
->
preg_replaced
)
&&
write_data
->
value
)
{
if
((
result
=
write_section
(
write_data
->
buf
,
write_data
->
section
))
==
0
)
/* write the section header unless we're already in it */
if
(
!
current_section
||
strcmp
(
current_section
,
write_data
->
section
))
result
=
write_section
(
write_data
->
buf
,
write_data
->
section
);
if
(
!
result
)
result
=
write_value
(
write_data
);
}
...
...
tests/config/write.c
View file @
2f0450f4
...
...
@@ -695,3 +695,27 @@ void test_config_write__locking(void)
git_config_free
(
cfg
);
}
void
test_config_write__repeated
(
void
)
{
const
char
*
filename
=
"config-repeated"
;
git_config
*
cfg
;
git_buf
result
=
GIT_BUF_INIT
;
const
char
*
expected
=
"[sample
\"
prefix
\"
]
\n
\
\t
setting1 = someValue1
\n
\
\t
setting2 = someValue2
\n
\
\t
setting3 = someValue3
\n
\
\t
setting4 = someValue4
\n
\
"
;
cl_git_pass
(
git_config_open_ondisk
(
&
cfg
,
filename
));
cl_git_pass
(
git_config_set_string
(
cfg
,
"sample.prefix.setting1"
,
"someValue1"
));
cl_git_pass
(
git_config_set_string
(
cfg
,
"sample.prefix.setting2"
,
"someValue2"
));
cl_git_pass
(
git_config_set_string
(
cfg
,
"sample.prefix.setting3"
,
"someValue3"
));
cl_git_pass
(
git_config_set_string
(
cfg
,
"sample.prefix.setting4"
,
"someValue4"
));
cl_git_pass
(
git_config_open_ondisk
(
&
cfg
,
filename
));
cl_git_pass
(
git_futils_readbuffer
(
&
result
,
filename
));
cl_assert_equal_s
(
expected
,
result
.
ptr
);
git_buf_free
(
&
result
);
}
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