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
3f663178
Commit
3f663178
authored
May 01, 2013
by
Russell Belfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More care catching and setting config errors
parent
155ee751
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
8 deletions
+20
-8
src/config.c
+20
-8
No files found.
src/config.c
View file @
3f663178
...
@@ -344,6 +344,13 @@ int git_config_delete_entry(git_config *cfg, const char *name)
...
@@ -344,6 +344,13 @@ int git_config_delete_entry(git_config *cfg, const char *name)
* Setters
* Setters
**************/
**************/
static
int
config_error_nofiles
(
const
char
*
name
)
{
giterr_set
(
GITERR_CONFIG
,
"Cannot set value for '%s' when no config files exist"
,
name
);
return
GIT_ENOTFOUND
;
}
int
git_config_set_int64
(
git_config
*
cfg
,
const
char
*
name
,
int64_t
value
)
int
git_config_set_int64
(
git_config
*
cfg
,
const
char
*
name
,
int64_t
value
)
{
{
char
str_value
[
32
];
/* All numbers should fit in here */
char
str_value
[
32
];
/* All numbers should fit in here */
...
@@ -373,12 +380,9 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value)
...
@@ -373,12 +380,9 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value)
}
}
internal
=
git_vector_get
(
&
cfg
->
files
,
0
);
internal
=
git_vector_get
(
&
cfg
->
files
,
0
);
if
(
!
internal
)
{
if
(
!
internal
)
/* Should we auto-vivify .git/config? Tricky from this location */
/* Should we auto-vivify .git/config? Tricky from this location */
giterr_set
(
GITERR_CONFIG
,
"Cannot set value when no config files exist"
);
return
config_error_nofiles
(
name
);
return
GIT_ENOTFOUND
;
}
file
=
internal
->
file
;
file
=
internal
->
file
;
error
=
file
->
set
(
file
,
name
,
value
);
error
=
file
->
set
(
file
,
name
,
value
);
...
@@ -442,6 +446,12 @@ static int get_string_at_file(const char **out, const git_config_backend *file,
...
@@ -442,6 +446,12 @@ static int get_string_at_file(const char **out, const git_config_backend *file,
return
res
;
return
res
;
}
}
static
int
config_error_notfound
(
const
char
*
name
)
{
giterr_set
(
GITERR_CONFIG
,
"Config value '%s' was not found"
,
name
);
return
GIT_ENOTFOUND
;
}
static
int
get_string
(
const
char
**
out
,
const
git_config
*
cfg
,
const
char
*
name
)
static
int
get_string
(
const
char
**
out
,
const
git_config
*
cfg
,
const
char
*
name
)
{
{
file_internal
*
internal
;
file_internal
*
internal
;
...
@@ -454,7 +464,7 @@ static int get_string(const char **out, const git_config *cfg, const char *name)
...
@@ -454,7 +464,7 @@ static int get_string(const char **out, const git_config *cfg, const char *name)
return
res
;
return
res
;
}
}
return
GIT_ENOTFOUND
;
return
config_error_notfound
(
name
)
;
}
}
int
git_config_get_bool
(
int
*
out
,
const
git_config
*
cfg
,
const
char
*
name
)
int
git_config_get_bool
(
int
*
out
,
const
git_config
*
cfg
,
const
char
*
name
)
...
@@ -494,7 +504,7 @@ int git_config_get_entry(const git_config_entry **out, const git_config *cfg, co
...
@@ -494,7 +504,7 @@ int git_config_get_entry(const git_config_entry **out, const git_config *cfg, co
return
ret
;
return
ret
;
}
}
return
GIT_ENOTFOUND
;
return
config_error_notfound
(
name
)
;
}
}
int
git_config_get_multivar
(
const
git_config
*
cfg
,
const
char
*
name
,
const
char
*
regexp
,
int
git_config_get_multivar
(
const
git_config
*
cfg
,
const
char
*
name
,
const
char
*
regexp
,
...
@@ -517,7 +527,7 @@ int git_config_get_multivar(const git_config *cfg, const char *name, const char
...
@@ -517,7 +527,7 @@ int git_config_get_multivar(const git_config *cfg, const char *name, const char
return
ret
;
return
ret
;
}
}
return
0
;
return
(
ret
==
GIT_ENOTFOUND
)
?
config_error_notfound
(
name
)
:
0
;
}
}
int
git_config_set_multivar
(
git_config
*
cfg
,
const
char
*
name
,
const
char
*
regexp
,
const
char
*
value
)
int
git_config_set_multivar
(
git_config
*
cfg
,
const
char
*
name
,
const
char
*
regexp
,
const
char
*
value
)
...
@@ -526,6 +536,8 @@ int git_config_set_multivar(git_config *cfg, const char *name, const char *regex
...
@@ -526,6 +536,8 @@ int git_config_set_multivar(git_config *cfg, const char *name, const char *regex
file_internal
*
internal
;
file_internal
*
internal
;
internal
=
git_vector_get
(
&
cfg
->
files
,
0
);
internal
=
git_vector_get
(
&
cfg
->
files
,
0
);
if
(
!
internal
)
return
config_error_nofiles
(
name
);
file
=
internal
->
file
;
file
=
internal
->
file
;
return
file
->
set_multivar
(
file
,
name
,
regexp
,
value
);
return
file
->
set_multivar
(
file
,
name
,
regexp
,
value
);
...
...
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