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
880b6f0c
Commit
880b6f0c
authored
Nov 25, 2011
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #497 from carlosmn/config
Don't fail when opening a new config file
parents
e42ea1f4
533fda3b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
7 deletions
+69
-7
src/config_file.c
+21
-5
tests-clay/clay.h
+1
-0
tests-clay/clay_main.c
+11
-2
tests-clay/config/new.c
+36
-0
No files found.
src/config_file.c
View file @
880b6f0c
...
@@ -256,7 +256,11 @@ static int config_open(git_config_file *cfg)
...
@@ -256,7 +256,11 @@ static int config_open(git_config_file *cfg)
diskfile_backend
*
b
=
(
diskfile_backend
*
)
cfg
;
diskfile_backend
*
b
=
(
diskfile_backend
*
)
cfg
;
error
=
git_futils_readbuffer
(
&
b
->
reader
.
buffer
,
b
->
file_path
);
error
=
git_futils_readbuffer
(
&
b
->
reader
.
buffer
,
b
->
file_path
);
if
(
error
<
GIT_SUCCESS
)
/* It's fine if the file doesn't exist */
if
(
error
==
GIT_ENOTFOUND
)
return
GIT_SUCCESS
;
if
(
error
<
GIT_SUCCESS
)
goto
cleanup
;
goto
cleanup
;
error
=
config_parse
(
b
);
error
=
config_parse
(
b
);
...
@@ -714,6 +718,9 @@ static int skip_bom(diskfile_backend *cfg)
...
@@ -714,6 +718,9 @@ static int skip_bom(diskfile_backend *cfg)
{
{
static
const
char
*
utf8_bom
=
"
\xef\xbb\xbf
"
;
static
const
char
*
utf8_bom
=
"
\xef\xbb\xbf
"
;
if
(
cfg
->
reader
.
buffer
.
len
<
sizeof
(
utf8_bom
))
return
GIT_SUCCESS
;
if
(
memcmp
(
cfg
->
reader
.
read_ptr
,
utf8_bom
,
sizeof
(
utf8_bom
))
==
0
)
if
(
memcmp
(
cfg
->
reader
.
read_ptr
,
utf8_bom
,
sizeof
(
utf8_bom
))
==
0
)
cfg
->
reader
.
read_ptr
+=
sizeof
(
utf8_bom
);
cfg
->
reader
.
read_ptr
+=
sizeof
(
utf8_bom
);
...
@@ -882,14 +889,23 @@ static int config_write(diskfile_backend *cfg, cvar_t *var)
...
@@ -882,14 +889,23 @@ static int config_write(diskfile_backend *cfg, cvar_t *var)
/* We need to read in our own config file */
/* We need to read in our own config file */
error
=
git_futils_readbuffer
(
&
cfg
->
reader
.
buffer
,
cfg
->
file_path
);
error
=
git_futils_readbuffer
(
&
cfg
->
reader
.
buffer
,
cfg
->
file_path
);
if
(
error
<
GIT_SUCCESS
)
{
if
(
error
<
GIT_SUCCESS
&&
error
!=
GIT_ENOTFOUND
)
{
return
git__rethrow
(
error
,
"Failed to read existing config file %s"
,
cfg
->
file_path
);
return
git__rethrow
(
error
,
"Failed to read existing config file %s"
,
cfg
->
file_path
);
}
}
/* Initialise the reading position */
/* Initialise the reading position */
cfg
->
reader
.
read_ptr
=
cfg
->
reader
.
buffer
.
data
;
if
(
error
==
GIT_ENOTFOUND
)
{
cfg
->
reader
.
eof
=
0
;
error
=
GIT_SUCCESS
;
data_start
=
cfg
->
reader
.
read_ptr
;
cfg
->
reader
.
read_ptr
=
NULL
;
cfg
->
reader
.
eof
=
1
;
data_start
=
NULL
;
cfg
->
reader
.
buffer
.
len
=
0
;
cfg
->
reader
.
buffer
.
data
=
NULL
;
}
else
{
cfg
->
reader
.
read_ptr
=
cfg
->
reader
.
buffer
.
data
;
cfg
->
reader
.
eof
=
0
;
data_start
=
cfg
->
reader
.
read_ptr
;
}
/* Lock the file */
/* Lock the file */
error
=
git_filebuf_open
(
&
file
,
cfg
->
file_path
,
0
);
error
=
git_filebuf_open
(
&
file
,
cfg
->
file_path
,
0
);
...
...
tests-clay/clay.h
View file @
880b6f0c
...
@@ -59,6 +59,7 @@ void cl_fixture_cleanup(const char *fixture_name);
...
@@ -59,6 +59,7 @@ void cl_fixture_cleanup(const char *fixture_name);
*/
*/
extern
void
test_buf_basic__printf
(
void
);
extern
void
test_buf_basic__printf
(
void
);
extern
void
test_buf_basic__resize
(
void
);
extern
void
test_buf_basic__resize
(
void
);
extern
void
test_config_new__write_new_config
(
void
);
extern
void
test_config_stress__cleanup
(
void
);
extern
void
test_config_stress__cleanup
(
void
);
extern
void
test_config_stress__dont_break_on_invalid_input
(
void
);
extern
void
test_config_stress__dont_break_on_invalid_input
(
void
);
extern
void
test_config_stress__initialize
(
void
);
extern
void
test_config_stress__initialize
(
void
);
...
...
tests-clay/clay_main.c
View file @
880b6f0c
...
@@ -108,6 +108,9 @@ static const struct clay_func _clay_cb_buf_basic[] = {
...
@@ -108,6 +108,9 @@ static const struct clay_func _clay_cb_buf_basic[] = {
{
"printf"
,
&
test_buf_basic__printf
},
{
"printf"
,
&
test_buf_basic__printf
},
{
"resize"
,
&
test_buf_basic__resize
}
{
"resize"
,
&
test_buf_basic__resize
}
};
};
static
const
struct
clay_func
_clay_cb_config_new
[]
=
{
{
"write_new_config"
,
&
test_config_new__write_new_config
}
};
static
const
struct
clay_func
_clay_cb_config_stress
[]
=
{
static
const
struct
clay_func
_clay_cb_config_stress
[]
=
{
{
"dont_break_on_invalid_input"
,
&
test_config_stress__dont_break_on_invalid_input
}
{
"dont_break_on_invalid_input"
,
&
test_config_stress__dont_break_on_invalid_input
}
};
};
...
@@ -229,6 +232,12 @@ static const struct clay_suite _clay_suites[] = {
...
@@ -229,6 +232,12 @@ static const struct clay_suite _clay_suites[] = {
_clay_cb_buf_basic
,
2
_clay_cb_buf_basic
,
2
},
},
{
{
"config::new"
,
{
NULL
,
NULL
},
{
NULL
,
NULL
},
_clay_cb_config_new
,
1
},
{
"config::stress"
,
"config::stress"
,
{
"initialize"
,
&
test_config_stress__initialize
},
{
"initialize"
,
&
test_config_stress__initialize
},
{
"cleanup"
,
&
test_config_stress__cleanup
},
{
"cleanup"
,
&
test_config_stress__cleanup
},
...
@@ -362,8 +371,8 @@ static const struct clay_suite _clay_suites[] = {
...
@@ -362,8 +371,8 @@ static const struct clay_suite _clay_suites[] = {
}
}
};
};
static
size_t
_clay_suite_count
=
2
3
;
static
size_t
_clay_suite_count
=
2
4
;
static
size_t
_clay_callback_count
=
7
0
;
static
size_t
_clay_callback_count
=
7
1
;
/* Core test functions */
/* Core test functions */
static
void
static
void
...
...
tests-clay/config/new.c
0 → 100644
View file @
880b6f0c
#include "clay_libgit2.h"
#include "filebuf.h"
#include "fileops.h"
#include "posix.h"
#define TEST_CONFIG "git-new-config"
void
test_config_new__write_new_config
(
void
)
{
const
char
*
out
;
struct
git_config_file
*
file
;
git_config
*
config
;
cl_git_pass
(
git_config_file__ondisk
(
&
file
,
TEST_CONFIG
));
cl_git_pass
(
git_config_new
(
&
config
));
cl_git_pass
(
git_config_add_file
(
config
,
file
,
0
));
cl_git_pass
(
git_config_set_string
(
config
,
"color.ui"
,
"auto"
));
cl_git_pass
(
git_config_set_string
(
config
,
"core.editor"
,
"ed"
));
git_config_free
(
config
);
cl_git_pass
(
git_config_file__ondisk
(
&
file
,
TEST_CONFIG
));
cl_git_pass
(
git_config_new
(
&
config
));
cl_git_pass
(
git_config_add_file
(
config
,
file
,
0
));
cl_git_pass
(
git_config_get_string
(
config
,
"color.ui"
,
&
out
));
cl_assert
(
strcmp
(
out
,
"auto"
)
==
0
);
cl_git_pass
(
git_config_get_string
(
config
,
"core.editor"
,
&
out
));
cl_assert
(
strcmp
(
out
,
"ed"
)
==
0
);
git_config_free
(
config
);
p_unlink
(
TEST_CONFIG
);
}
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