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
d2794b0e
Commit
d2794b0e
authored
Aug 04, 2016
by
Carlos Martín Nieto
Committed by
GitHub
Aug 04, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3877 from libgit2/ethomson/paths_init
sysdir: don't assume an empty dir is uninitialized
parents
0d84de02
031d34b7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
52 deletions
+41
-52
src/sysdir.c
+41
-47
src/sysdir.h
+0
-5
No files found.
src/sysdir.c
View file @
d2794b0e
...
...
@@ -83,45 +83,43 @@ static int git_sysdir_guess_template_dirs(git_buf *out)
#endif
}
typedef
int
(
*
git_sysdir_guess_cb
)(
git_buf
*
out
);
static
git_buf
git_sysdir__dirs
[
GIT_SYSDIR__MAX
]
=
{
GIT_BUF_INIT
,
GIT_BUF_INIT
,
GIT_BUF_INIT
,
GIT_BUF_INIT
,
GIT_BUF_INIT
};
struct
git_sysdir__dir
{
git_buf
buf
;
int
(
*
guess
)(
git_buf
*
out
);
};
static
git_sysdir_guess_cb
git_sysdir__dir_guess
[
GIT_SYSDIR__MAX
]
=
{
git_sysdir_guess_system_dirs
,
git_sysdir_guess_global_dirs
,
git_sysdir_guess_xdg_dirs
,
git_sysdir_guess_programdata_dirs
,
git_sysdir_guess_template_dirs
,
static
struct
git_sysdir__dir
git_sysdir__dirs
[
]
=
{
{
GIT_BUF_INIT
,
git_sysdir_guess_system_dirs
}
,
{
GIT_BUF_INIT
,
git_sysdir_guess_global_dirs
}
,
{
GIT_BUF_INIT
,
git_sysdir_guess_xdg_dirs
}
,
{
GIT_BUF_INIT
,
git_sysdir_guess_programdata_dirs
}
,
{
GIT_BUF_INIT
,
git_sysdir_guess_template_dirs
}
,
};
static
int
git_sysdir__dirs_shutdown_set
=
0
;
static
void
git_sysdir_global_shutdown
(
void
)
{
size_t
i
;
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
git_sysdir__dirs
);
++
i
)
git_buf_free
(
&
git_sysdir__dirs
[
i
].
buf
);
}
int
git_sysdir_global_init
(
void
)
{
git_sysdir_t
i
;
const
git_buf
*
path
;
size_t
i
;
int
error
=
0
;
for
(
i
=
0
;
!
error
&&
i
<
GIT_SYSDIR__MAX
;
i
++
)
error
=
git_sysdir_
get
(
&
path
,
i
);
for
(
i
=
0
;
!
error
&&
i
<
ARRAY_SIZE
(
git_sysdir__dirs
)
;
i
++
)
error
=
git_sysdir_
_dirs
[
i
].
guess
(
&
git_sysdir__dirs
[
i
].
buf
);
return
error
;
}
git__on_shutdown
(
git_sysdir_global_shutdown
);
void
git_sysdir_global_shutdown
(
void
)
{
int
i
;
for
(
i
=
0
;
i
<
GIT_SYSDIR__MAX
;
++
i
)
git_buf_free
(
&
git_sysdir__dirs
[
i
]);
git_sysdir__dirs_shutdown_set
=
0
;
return
error
;
}
static
int
git_sysdir_check_selector
(
git_sysdir_t
which
)
{
if
(
which
<
GIT_SYSDIR__MAX
)
if
(
which
<
ARRAY_SIZE
(
git_sysdir__dirs
)
)
return
0
;
giterr_set
(
GITERR_INVALID
,
"config directory selector out of range"
);
...
...
@@ -137,18 +135,7 @@ int git_sysdir_get(const git_buf **out, git_sysdir_t which)
GITERR_CHECK_ERROR
(
git_sysdir_check_selector
(
which
));
if
(
!
git_buf_len
(
&
git_sysdir__dirs
[
which
]))
{
/* prepare shutdown if we're going to need it */
if
(
!
git_sysdir__dirs_shutdown_set
)
{
git__on_shutdown
(
git_sysdir_global_shutdown
);
git_sysdir__dirs_shutdown_set
=
1
;
}
GITERR_CHECK_ERROR
(
git_sysdir__dir_guess
[
which
](
&
git_sysdir__dirs
[
which
]));
}
*
out
=
&
git_sysdir__dirs
[
which
];
*
out
=
&
git_sysdir__dirs
[
which
].
buf
;
return
0
;
}
...
...
@@ -183,31 +170,38 @@ int git_sysdir_set(git_sysdir_t which, const char *search_path)
if
(
search_path
!=
NULL
)
expand_path
=
strstr
(
search_path
,
PATH_MAGIC
);
/* init with default if not yet done and needed (ignoring error) */
if
((
!
search_path
||
expand_path
)
&&
!
git_buf_len
(
&
git_sysdir__dirs
[
which
]))
git_sysdir__dir_guess
[
which
](
&
git_sysdir__dirs
[
which
]);
/* reset the default if this path has been cleared */
if
(
!
search_path
||
expand_path
)
git_sysdir__dirs
[
which
].
guess
(
&
git_sysdir__dirs
[
which
].
buf
);
/* if $PATH is not referenced, then just set the path */
if
(
!
expand_path
)
return
git_buf_sets
(
&
git_sysdir__dirs
[
which
],
search_path
);
if
(
!
expand_path
)
{
if
(
search_path
)
git_buf_sets
(
&
git_sysdir__dirs
[
which
].
buf
,
search_path
);
goto
done
;
}
/* otherwise set to join(before $PATH, old value, after $PATH) */
if
(
expand_path
>
search_path
)
git_buf_set
(
&
merge
,
search_path
,
expand_path
-
search_path
);
if
(
git_buf_len
(
&
git_sysdir__dirs
[
which
]))
if
(
git_buf_len
(
&
git_sysdir__dirs
[
which
]
.
buf
))
git_buf_join
(
&
merge
,
GIT_PATH_LIST_SEPARATOR
,
merge
.
ptr
,
git_sysdir__dirs
[
which
].
ptr
);
merge
.
ptr
,
git_sysdir__dirs
[
which
].
buf
.
ptr
);
expand_path
+=
strlen
(
PATH_MAGIC
);
if
(
*
expand_path
)
git_buf_join
(
&
merge
,
GIT_PATH_LIST_SEPARATOR
,
merge
.
ptr
,
expand_path
);
git_buf_swap
(
&
git_sysdir__dirs
[
which
],
&
merge
);
git_buf_swap
(
&
git_sysdir__dirs
[
which
]
.
buf
,
&
merge
);
git_buf_free
(
&
merge
);
return
git_buf_oom
(
&
git_sysdir__dirs
[
which
])
?
-
1
:
0
;
done:
if
(
git_buf_oom
(
&
git_sysdir__dirs
[
which
].
buf
))
return
-
1
;
return
0
;
}
static
int
git_sysdir_find_in_dirlist
(
...
...
src/sysdir.h
View file @
d2794b0e
...
...
@@ -103,9 +103,4 @@ extern int git_sysdir_get_str(char *out, size_t outlen, git_sysdir_t which);
*/
extern
int
git_sysdir_set
(
git_sysdir_t
which
,
const
char
*
paths
);
/**
* Free the configuration file search paths.
*/
extern
void
git_sysdir_global_shutdown
(
void
);
#endif
/* INCLUDE_sysdir_h__ */
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