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
19cb6857
Commit
19cb6857
authored
Jun 18, 2011
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config: Bring back `git_config_open_global`
Scott commands, I obey.
parent
920e000d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
1 deletions
+66
-1
include/git2/config.h
+33
-1
src/config.c
+33
-0
No files found.
include/git2/config.h
View file @
19cb6857
...
@@ -53,6 +53,34 @@ struct git_config_file {
...
@@ -53,6 +53,34 @@ struct git_config_file {
};
};
/**
/**
* Locate the path to the global configuration file
*
* The user or global configuration file is usually
* located in `$HOME/.gitconfig`.
*
* This method will try to guess the full path to that
* file, if the file exists. The returned path
* may be used on any `git_config` call to load the
* global configuration file.
*
* @param path Buffer of GIT_PATH_MAX length to store the path
* @return GIT_SUCCESS if a global configuration file has been
* found. Its path will be stored in `buffer`.
*/
GIT_EXTERN
(
int
)
git_config_find_global
(
char
*
global_config_path
);
/**
* Open the global configuration file
*
* Utility wrapper that calls `git_config_find_global`
* and opens the located file, if it exists.
*
* @param out Pointer to store the config instance
* @return GIT_SUCCESS on success; error code otherwise
*/
GIT_EXTERN
(
int
)
git_config_open_global
(
git_config
**
out
);
/**
* Create a configuration file backend for ondisk files
* Create a configuration file backend for ondisk files
*
*
* These are the normal `.gitconfig` files that Core Git
* These are the normal `.gitconfig` files that Core Git
...
@@ -61,7 +89,7 @@ struct git_config_file {
...
@@ -61,7 +89,7 @@ struct git_config_file {
* variables.
* variables.
*
*
* @param out the new backend
* @param out the new backend
* @path where the config file is located
* @pa
ram pa
th where the config file is located
*/
*/
GIT_EXTERN
(
int
)
git_config_file__ondisk
(
struct
git_config_file
**
out
,
const
char
*
path
);
GIT_EXTERN
(
int
)
git_config_file__ondisk
(
struct
git_config_file
**
out
,
const
char
*
path
);
...
@@ -72,6 +100,7 @@ GIT_EXTERN(int) git_config_file__ondisk(struct git_config_file **out, const char
...
@@ -72,6 +100,7 @@ GIT_EXTERN(int) git_config_file__ondisk(struct git_config_file **out, const char
* can do anything with it.
* can do anything with it.
*
*
* @param out pointer to the new configuration
* @param out pointer to the new configuration
* @return GIT_SUCCESS on success; error code otherwise
*/
*/
GIT_EXTERN
(
int
)
git_config_new
(
git_config
**
out
);
GIT_EXTERN
(
int
)
git_config_new
(
git_config
**
out
);
...
@@ -88,6 +117,7 @@ GIT_EXTERN(int) git_config_new(git_config **out);
...
@@ -88,6 +117,7 @@ GIT_EXTERN(int) git_config_new(git_config **out);
* @param cfg the configuration to add the file to
* @param cfg the configuration to add the file to
* @param file the configuration file (backend) to add
* @param file the configuration file (backend) to add
* @param priority the priority the backend should have
* @param priority the priority the backend should have
* @return GIT_SUCCESS on success; error code otherwise
*/
*/
GIT_EXTERN
(
int
)
git_config_add_file
(
git_config
*
cfg
,
git_config_file
*
file
,
int
priority
);
GIT_EXTERN
(
int
)
git_config_add_file
(
git_config
*
cfg
,
git_config_file
*
file
,
int
priority
);
...
@@ -108,6 +138,7 @@ GIT_EXTERN(int) git_config_add_file(git_config *cfg, git_config_file *file, int
...
@@ -108,6 +138,7 @@ GIT_EXTERN(int) git_config_add_file(git_config *cfg, git_config_file *file, int
* @param cfg the configuration to add the file to
* @param cfg the configuration to add the file to
* @param file path to the configuration file (backend) to add
* @param file path to the configuration file (backend) to add
* @param priority the priority the backend should have
* @param priority the priority the backend should have
* @return GIT_SUCCESS on success; error code otherwise
*/
*/
GIT_EXTERN
(
int
)
git_config_add_file_ondisk
(
git_config
*
cfg
,
const
char
*
path
,
int
priority
);
GIT_EXTERN
(
int
)
git_config_add_file_ondisk
(
git_config
*
cfg
,
const
char
*
path
,
int
priority
);
...
@@ -122,6 +153,7 @@ GIT_EXTERN(int) git_config_add_file_ondisk(git_config *cfg, const char *path, in
...
@@ -122,6 +153,7 @@ GIT_EXTERN(int) git_config_add_file_ondisk(git_config *cfg, const char *path, in
*
*
* @param cfg The configuration instance to create
* @param cfg The configuration instance to create
* @param path Path to the on-disk file to open
* @param path Path to the on-disk file to open
* @return GIT_SUCCESS on success; error code otherwise
*/
*/
GIT_EXTERN
(
int
)
git_config_open_ondisk
(
git_config
**
cfg
,
const
char
*
path
);
GIT_EXTERN
(
int
)
git_config_open_ondisk
(
git_config
**
cfg
,
const
char
*
path
);
...
...
src/config.c
View file @
19cb6857
...
@@ -319,3 +319,36 @@ int git_config_get_string(git_config *cfg, const char *name, const char **out)
...
@@ -319,3 +319,36 @@ int git_config_get_string(git_config *cfg, const char *name, const char **out)
return
git__throw
(
error
,
"Config value '%s' not found"
,
name
);
return
git__throw
(
error
,
"Config value '%s' not found"
,
name
);
}
}
int
git_config_find_global
(
char
*
global_config_path
)
{
const
char
*
home
;
home
=
getenv
(
"HOME"
);
#ifdef GIT_WIN32
if
(
home
==
NULL
)
home
=
getenv
(
"USERPROFILE"
);
#endif
if
(
home
==
NULL
)
return
git__throw
(
GIT_EOSERR
,
"Failed to open global config file. Cannot locate the user's home directory"
);
git__joinpath
(
global_config_path
,
home
,
GIT_CONFIG_FILENAME
);
if
(
gitfo_exists
(
global_config_path
)
<
GIT_SUCCESS
)
return
git__throw
(
GIT_EOSERR
,
"Failed to open global config file. The file does not exist"
);
return
GIT_SUCCESS
;
}
int
git_config_open_global
(
git_config
**
out
)
{
int
error
;
char
global_path
[
GIT_PATH_MAX
];
if
((
error
=
git_config_find_global
(
global_path
))
<
GIT_SUCCESS
)
return
error
;
return
git_config_open_ondisk
(
out
,
global_path
);
}
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