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
270160b9
Commit
270160b9
authored
Nov 17, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config: Opening a nonexistent file returns ENOTFOUND
parent
d36451c9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
12 deletions
+69
-12
include/git2/config.h
+6
-5
src/config.c
+19
-7
src/repository.c
+23
-0
tests-clar/config/new.c
+1
-0
tests-clar/config/read.c
+20
-0
No files found.
include/git2/config.h
View file @
270160b9
...
...
@@ -189,7 +189,8 @@ GIT_EXTERN(int) git_config_add_file(
* @param force if a config file already exists for the given
* priority level, replace it
* @return 0 on success, GIT_EEXISTS when adding more than one file
* for a given priority level (and force_replace set to 0), or error code
* for a given priority level (and force_replace set to 0),
* GIT_ENOTFOUND when the file doesn't exist or error code
*/
GIT_EXTERN
(
int
)
git_config_add_file_ondisk
(
git_config
*
cfg
,
...
...
@@ -197,7 +198,6 @@ GIT_EXTERN(int) git_config_add_file_ondisk(
unsigned
int
level
,
int
force
);
/**
* Create a new config instance containing a single on-disk file
*
...
...
@@ -206,11 +206,12 @@ GIT_EXTERN(int) git_config_add_file_ondisk(
* - git_config_new
* - git_config_add_file_ondisk
*
* @param
cfg
The configuration instance to create
* @param
out
The configuration instance to create
* @param path Path to the on-disk file to open
* @return 0 or an error code
* @return 0 on success, GIT_ENOTFOUND when the file doesn't exist
* or an error code
*/
GIT_EXTERN
(
int
)
git_config_open_ondisk
(
git_config
**
cfg
,
const
char
*
path
);
GIT_EXTERN
(
int
)
git_config_open_ondisk
(
git_config
**
out
,
const
char
*
path
);
/**
* Build a single-level focused config object from a multi-level one.
...
...
src/config.c
View file @
270160b9
...
...
@@ -90,6 +90,13 @@ int git_config_add_file_ondisk(
git_config_file
*
file
=
NULL
;
int
res
;
assert
(
cfg
&&
path
);
if
(
!
git_path_isfile
(
path
))
{
giterr_set
(
GITERR_CONFIG
,
"File '%s' doesn't exists."
,
path
);
return
GIT_ENOTFOUND
;
}
if
(
git_config_file__ondisk
(
&
file
,
path
)
<
0
)
return
-
1
;
...
...
@@ -105,17 +112,22 @@ int git_config_add_file_ondisk(
return
0
;
}
int
git_config_open_ondisk
(
git_config
**
cfg
,
const
char
*
path
)
int
git_config_open_ondisk
(
git_config
**
out
,
const
char
*
path
)
{
i
f
(
git_config_new
(
cfg
)
<
0
)
return
-
1
;
i
nt
error
;
git_config
*
config
;
if
(
git_config_add_file_ondisk
(
*
cfg
,
path
,
GIT_CONFIG_LEVEL_LOCAL
,
0
)
<
0
)
{
git_config_free
(
*
cfg
);
*
out
=
NULL
;
if
(
git_config_new
(
&
config
)
<
0
)
return
-
1
;
}
return
0
;
if
((
error
=
git_config_add_file_ondisk
(
config
,
path
,
GIT_CONFIG_LEVEL_LOCAL
,
0
))
<
0
)
git_config_free
(
config
);
else
*
out
=
config
;
return
error
;
}
static
int
find_internal_file_by_level
(
...
...
src/repository.c
View file @
270160b9
...
...
@@ -750,6 +750,23 @@ static bool are_symlinks_supported(const char *wd_path)
return
_symlinks_supported
;
}
static
int
create_empty_file
(
const
char
*
path
,
mode_t
mode
)
{
int
fd
;
if
((
fd
=
p_creat
(
path
,
mode
))
<
0
)
{
giterr_set
(
GITERR_OS
,
"Error while creating '%s'"
,
path
);
return
-
1
;
}
if
(
p_close
(
fd
)
<
0
)
{
giterr_set
(
GITERR_OS
,
"Error while closing '%s'"
,
path
);
return
-
1
;
}
return
0
;
}
static
int
repo_init_config
(
const
char
*
repo_dir
,
const
char
*
work_dir
,
...
...
@@ -766,6 +783,12 @@ static int repo_init_config(
if
(
git_buf_joinpath
(
&
cfg_path
,
repo_dir
,
GIT_CONFIG_FILENAME_INREPO
)
<
0
)
return
-
1
;
if
(
!
git_path_isfile
(
git_buf_cstr
(
&
cfg_path
))
&&
create_empty_file
(
git_buf_cstr
(
&
cfg_path
),
GIT_CONFIG_FILE_MODE
)
<
0
)
{
git_buf_free
(
&
cfg_path
);
return
-
1
;
}
if
(
git_config_open_ondisk
(
&
config
,
git_buf_cstr
(
&
cfg_path
))
<
0
)
{
git_buf_free
(
&
cfg_path
);
return
-
1
;
...
...
tests-clar/config/new.c
View file @
270160b9
...
...
@@ -11,6 +11,7 @@ void test_config_new__write_new_config(void)
const
char
*
out
;
git_config
*
config
;
cl_git_mkfile
(
TEST_CONFIG
,
""
);
cl_git_pass
(
git_config_open_ondisk
(
&
config
,
TEST_CONFIG
));
cl_git_pass
(
git_config_set_string
(
config
,
"color.ui"
,
"auto"
));
...
...
tests-clar/config/read.c
View file @
270160b9
...
...
@@ -430,3 +430,23 @@ void test_config_read__simple_read_from_specific_level(void)
git_config_free
(
cfg_specific
);
git_config_free
(
cfg
);
}
void
test_config_read__can_load_and_parse_an_empty_config_file
(
void
)
{
git_config
*
cfg
;
int
i
;
cl_git_mkfile
(
"./empty"
,
""
);
cl_git_pass
(
git_config_open_ondisk
(
&
cfg
,
"./empty"
));
cl_assert_equal_i
(
GIT_ENOTFOUND
,
git_config_get_int32
(
&
i
,
cfg
,
"nope.neither"
));
git_config_free
(
cfg
);
}
void
test_config_read__cannot_load_a_non_existing_config_file
(
void
)
{
git_config
*
cfg
;
int
i
;
cl_assert_equal_i
(
GIT_ENOTFOUND
,
git_config_open_ondisk
(
&
cfg
,
"./no.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