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
8adbf2ed
Commit
8adbf2ed
authored
May 20, 2011
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite `git_config_open_global`
We have a lot of utility methods that make path building trivial. Use them!
parent
274f2c21
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
26 deletions
+8
-26
src/config.c
+6
-26
src/config.h
+2
-0
No files found.
src/config.c
View file @
8adbf2ed
...
...
@@ -72,36 +72,16 @@ int git_config_open_bare(git_config **out, const char *path)
int
git_config_open_global
(
git_config
**
out
)
{
char
*
home
=
NULL
,
*
filename
=
NULL
;
const
char
*
gitconfig
=
".gitconfig"
;
int
filename_len
,
ret
,
error
;
char
full_path
[
GIT_PATH_MAX
];
const
char
*
home
;
home
=
g
it__strdup
(
getenv
(
"HOME"
)
);
home
=
g
etenv
(
"HOME"
);
if
(
home
==
NULL
)
return
GIT_ENOMEM
;
filename_len
=
strlen
(
home
)
+
strlen
(
gitconfig
)
+
1
;
filename
=
git__malloc
(
filename_len
+
1
);
if
(
filename
==
NULL
)
{
error
=
GIT_ENOMEM
;
goto
out
;
}
return
git__throw
(
GIT_EOSERR
,
"Failed to find $HOME variable"
);
ret
=
snprintf
(
filename
,
filename_len
,
"%s/%s"
,
home
,
gitconfig
);
if
(
ret
<
0
)
{
error
=
git__throw
(
GIT_EOSERR
,
"Failed to build global filename. OS err: %s"
,
strerror
(
errno
));
goto
out
;
}
else
if
(
ret
>=
filename_len
)
{
error
=
git__throw
(
GIT_ERROR
,
"Failed to build global filename. Length calulation wrong"
);
goto
out
;
}
error
=
git_config_open_bare
(
out
,
filename
);
git__joinpath
(
full_path
,
home
,
GIT_CONFIG_FILENAME
);
out:
free
(
home
);
free
(
filename
);
return
error
;
return
git_config_open_bare
(
out
,
filename
);
}
void
git_config_free
(
git_config
*
cfg
)
...
...
src/config.h
View file @
8adbf2ed
...
...
@@ -5,6 +5,8 @@
#include "git2/config.h"
#include "vector.h"
#define GIT_CONFIG_FILENAME ".gitconfig"
struct
git_config
{
git_vector
backends
;
};
...
...
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