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
650a9dff
Commit
650a9dff
authored
Jul 19, 2023
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config: rename config_entries to config_list
parent
f85e0af2
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
185 additions
and
184 deletions
+185
-184
src/libgit2/config_entries.h
+0
-24
src/libgit2/config_file.c
+62
-62
src/libgit2/config_list.c
+64
-63
src/libgit2/config_list.h
+24
-0
src/libgit2/config_mem.c
+14
-14
src/libgit2/config_snapshot.c
+21
-21
No files found.
src/libgit2/config_entries.h
deleted
100644 → 0
View file @
f85e0af2
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
#include "git2/sys/config.h"
#include "config.h"
typedef
struct
git_config_entries
git_config_entries
;
int
git_config_entries_new
(
git_config_entries
**
out
);
int
git_config_entries_dup
(
git_config_entries
**
out
,
git_config_entries
*
entries
);
int
git_config_entries_dup_entry
(
git_config_entries
*
entries
,
const
git_config_entry
*
entry
);
void
git_config_entries_incref
(
git_config_entries
*
entries
);
void
git_config_entries_free
(
git_config_entries
*
entries
);
/* Add or append the new config option */
int
git_config_entries_append
(
git_config_entries
*
entries
,
git_config_entry
*
entry
);
int
git_config_entries_get
(
git_config_entry
**
out
,
git_config_entries
*
entries
,
const
char
*
key
);
int
git_config_entries_get_unique
(
git_config_entry
**
out
,
git_config_entries
*
entries
,
const
char
*
key
);
int
git_config_entries_iterator_new
(
git_config_iterator
**
out
,
git_config_entries
*
entries
);
src/libgit2/config_file.c
View file @
650a9dff
...
...
@@ -13,7 +13,7 @@
#include "array.h"
#include "str.h"
#include "config_backend.h"
#include "config_
entries
.h"
#include "config_
list
.h"
#include "config_parse.h"
#include "filebuf.h"
#include "regexp.h"
...
...
@@ -34,7 +34,7 @@ typedef struct config_file {
typedef
struct
{
git_config_backend
parent
;
git_mutex
values_mutex
;
git_config_
entries
*
entries
;
git_config_
list
*
config_list
;
const
git_repository
*
repo
;
git_config_level_t
level
;
...
...
@@ -50,13 +50,13 @@ typedef struct {
typedef
struct
{
const
git_repository
*
repo
;
config_file
*
file
;
git_config_
entries
*
entries
;
git_config_
list
*
config_list
;
git_config_level_t
level
;
unsigned
int
depth
;
}
config_file_parse_data
;
static
int
config_file_read
(
git_config_
entries
*
entries
,
const
git_repository
*
repo
,
config_file
*
file
,
git_config_level_t
level
,
int
depth
);
static
int
config_file_read_buffer
(
git_config_
entries
*
entries
,
const
git_repository
*
repo
,
config_file
*
file
,
git_config_level_t
level
,
int
depth
,
const
char
*
buf
,
size_t
buflen
);
static
int
config_file_read
(
git_config_
list
*
config_list
,
const
git_repository
*
repo
,
config_file
*
file
,
git_config_level_t
level
,
int
depth
);
static
int
config_file_read_buffer
(
git_config_
list
*
config_list
,
const
git_repository
*
repo
,
config_file
*
file
,
git_config_level_t
level
,
int
depth
,
const
char
*
buf
,
size_t
buflen
);
static
int
config_file_write
(
config_file_backend
*
cfg
,
const
char
*
orig_key
,
const
char
*
key
,
const
git_regexp
*
preg
,
const
char
*
value
);
static
char
*
escape_value
(
const
char
*
ptr
);
...
...
@@ -65,7 +65,7 @@ static char *escape_value(const char *ptr);
* refcount. This is its own function to make sure we use the mutex to
* avoid the map pointer from changing under us.
*/
static
int
config_file_
entries_take
(
git_config_entries
**
out
,
config_file_backend
*
b
)
static
int
config_file_
take_list
(
git_config_list
**
out
,
config_file_backend
*
b
)
{
int
error
;
...
...
@@ -74,8 +74,8 @@ static int config_file_entries_take(git_config_entries **out, config_file_backen
return
error
;
}
git_config_
entries_incref
(
b
->
entries
);
*
out
=
b
->
entries
;
git_config_
list_incref
(
b
->
config_list
);
*
out
=
b
->
config_list
;
git_mutex_unlock
(
&
b
->
values_mutex
);
...
...
@@ -106,7 +106,7 @@ static int config_file_open(git_config_backend *cfg, git_config_level_t level, c
b
->
level
=
level
;
b
->
repo
=
repo
;
if
((
res
=
git_config_
entries_new
(
&
b
->
entries
))
<
0
)
if
((
res
=
git_config_
list_new
(
&
b
->
config_list
))
<
0
)
return
res
;
if
(
!
git_fs_path_exists
(
b
->
file
.
path
))
...
...
@@ -121,9 +121,9 @@ static int config_file_open(git_config_backend *cfg, git_config_level_t level, c
if
(
p_access
(
b
->
file
.
path
,
R_OK
)
<
0
)
return
GIT_ENOTFOUND
;
if
(
res
<
0
||
(
res
=
config_file_read
(
b
->
entries
,
repo
,
&
b
->
file
,
level
,
0
))
<
0
)
{
git_config_
entries_free
(
b
->
entries
);
b
->
entries
=
NULL
;
if
(
res
<
0
||
(
res
=
config_file_read
(
b
->
config_list
,
repo
,
&
b
->
file
,
level
,
0
))
<
0
)
{
git_config_
list_free
(
b
->
config_list
);
b
->
config_list
=
NULL
;
}
return
res
;
...
...
@@ -175,10 +175,10 @@ static void config_file_clear_includes(config_file_backend *cfg)
git_array_clear
(
cfg
->
file
.
includes
);
}
static
int
config_file_set_entries
(
git_config_backend
*
cfg
,
git_config_
entries
*
entries
)
static
int
config_file_set_entries
(
git_config_backend
*
cfg
,
git_config_
list
*
config_list
)
{
config_file_backend
*
b
=
GIT_CONTAINER_OF
(
cfg
,
config_file_backend
,
parent
);
git_config_
entries
*
old
=
NULL
;
git_config_
list
*
old
=
NULL
;
int
error
;
if
(
b
->
parent
.
readonly
)
{
...
...
@@ -191,40 +191,40 @@ static int config_file_set_entries(git_config_backend *cfg, git_config_entries *
goto
out
;
}
old
=
b
->
entries
;
b
->
entries
=
entries
;
old
=
b
->
config_list
;
b
->
config_list
=
config_list
;
git_mutex_unlock
(
&
b
->
values_mutex
);
out:
git_config_
entries
_free
(
old
);
git_config_
list
_free
(
old
);
return
error
;
}
static
int
config_file_refresh_from_buffer
(
git_config_backend
*
cfg
,
const
char
*
buf
,
size_t
buflen
)
{
config_file_backend
*
b
=
GIT_CONTAINER_OF
(
cfg
,
config_file_backend
,
parent
);
git_config_
entries
*
entries
=
NULL
;
git_config_
list
*
config_list
=
NULL
;
int
error
;
config_file_clear_includes
(
b
);
if
((
error
=
git_config_
entries_new
(
&
entries
))
<
0
||
(
error
=
config_file_read_buffer
(
entries
,
b
->
repo
,
&
b
->
file
,
if
((
error
=
git_config_
list_new
(
&
config_list
))
<
0
||
(
error
=
config_file_read_buffer
(
config_list
,
b
->
repo
,
&
b
->
file
,
b
->
level
,
0
,
buf
,
buflen
))
<
0
||
(
error
=
config_file_set_entries
(
cfg
,
entries
))
<
0
)
(
error
=
config_file_set_entries
(
cfg
,
config_list
))
<
0
)
goto
out
;
entries
=
NULL
;
config_list
=
NULL
;
out:
git_config_
entries_free
(
entries
);
git_config_
list_free
(
config_list
);
return
error
;
}
static
int
config_file_refresh
(
git_config_backend
*
cfg
)
{
config_file_backend
*
b
=
GIT_CONTAINER_OF
(
cfg
,
config_file_backend
,
parent
);
git_config_
entries
*
entries
=
NULL
;
git_config_
list
*
config_list
=
NULL
;
int
error
,
modified
;
if
(
cfg
->
readonly
)
...
...
@@ -238,14 +238,14 @@ static int config_file_refresh(git_config_backend *cfg)
config_file_clear_includes
(
b
);
if
((
error
=
git_config_
entries_new
(
&
entries
))
<
0
||
(
error
=
config_file_read
(
entries
,
b
->
repo
,
&
b
->
file
,
b
->
level
,
0
))
<
0
||
(
error
=
config_file_set_entries
(
cfg
,
entries
))
<
0
)
if
((
error
=
git_config_
list_new
(
&
config_list
))
<
0
||
(
error
=
config_file_read
(
config_list
,
b
->
repo
,
&
b
->
file
,
b
->
level
,
0
))
<
0
||
(
error
=
config_file_set_entries
(
cfg
,
config_list
))
<
0
)
goto
out
;
entries
=
NULL
;
config_list
=
NULL
;
out:
git_config_
entries_free
(
entries
);
git_config_
list_free
(
config_list
);
return
(
error
==
GIT_ENOTFOUND
)
?
0
:
error
;
}
...
...
@@ -258,7 +258,7 @@ static void config_file_free(git_config_backend *_backend)
return
;
config_file_clear
(
&
backend
->
file
);
git_config_
entries_free
(
backend
->
entries
);
git_config_
list_free
(
backend
->
config_list
);
git_mutex_free
(
&
backend
->
values_mutex
);
git__free
(
backend
);
}
...
...
@@ -268,19 +268,19 @@ static int config_file_iterator(
struct
git_config_backend
*
backend
)
{
config_file_backend
*
b
=
GIT_CONTAINER_OF
(
backend
,
config_file_backend
,
parent
);
git_config_
entries
*
dupped
=
NULL
,
*
entries
=
NULL
;
git_config_
list
*
dupped
=
NULL
,
*
config_list
=
NULL
;
int
error
;
if
((
error
=
config_file_refresh
(
backend
))
<
0
||
(
error
=
config_file_
entries_take
(
&
entries
,
b
))
<
0
||
(
error
=
git_config_
entries_dup
(
&
dupped
,
entries
))
<
0
||
(
error
=
git_config_
entries
_iterator_new
(
iter
,
dupped
))
<
0
)
(
error
=
config_file_
take_list
(
&
config_list
,
b
))
<
0
||
(
error
=
git_config_
list_dup
(
&
dupped
,
config_list
))
<
0
||
(
error
=
git_config_
list
_iterator_new
(
iter
,
dupped
))
<
0
)
goto
out
;
out:
/* Let iterator delete duplicated
entries
when it's done */
git_config_
entries_free
(
entries
);
git_config_
entries
_free
(
dupped
);
/* Let iterator delete duplicated
config_list
when it's done */
git_config_
list_free
(
config_list
);
git_config_
list
_free
(
dupped
);
return
error
;
}
...
...
@@ -292,7 +292,7 @@ static int config_file_snapshot(git_config_backend **out, git_config_backend *ba
static
int
config_file_set
(
git_config_backend
*
cfg
,
const
char
*
name
,
const
char
*
value
)
{
config_file_backend
*
b
=
GIT_CONTAINER_OF
(
cfg
,
config_file_backend
,
parent
);
git_config_
entries
*
entries
;
git_config_
list
*
config_list
;
git_config_entry
*
existing
;
char
*
key
,
*
esc_value
=
NULL
;
int
error
;
...
...
@@ -300,11 +300,11 @@ static int config_file_set(git_config_backend *cfg, const char *name, const char
if
((
error
=
git_config__normalize_name
(
name
,
&
key
))
<
0
)
return
error
;
if
((
error
=
config_file_
entries_take
(
&
entries
,
b
))
<
0
)
if
((
error
=
config_file_
take_list
(
&
config_list
,
b
))
<
0
)
return
error
;
/* Check whether we'd be modifying an included or multivar key */
if
((
error
=
git_config_
entries_get_unique
(
&
existing
,
entries
,
key
))
<
0
)
{
if
((
error
=
git_config_
list_get_unique
(
&
existing
,
config_list
,
key
))
<
0
)
{
if
(
error
!=
GIT_ENOTFOUND
)
goto
out
;
error
=
0
;
...
...
@@ -325,7 +325,7 @@ static int config_file_set(git_config_backend *cfg, const char *name, const char
goto
out
;
out:
git_config_
entries_free
(
entries
);
git_config_
list_free
(
config_list
);
git__free
(
esc_value
);
git__free
(
key
);
return
error
;
...
...
@@ -334,8 +334,8 @@ out:
/* release the map containing the entry as an equivalent to freeing it */
static
void
config_file_entry_free
(
git_config_entry
*
entry
)
{
git_config_
entries
*
entries
=
(
git_config_entries
*
)
entry
->
payload
;
git_config_
entries_free
(
entries
);
git_config_
list
*
config_list
=
(
git_config_list
*
)
entry
->
payload
;
git_config_
list_free
(
config_list
);
}
/*
...
...
@@ -344,18 +344,18 @@ static void config_file_entry_free(git_config_entry *entry)
static
int
config_file_get
(
git_config_backend
*
cfg
,
const
char
*
key
,
git_config_entry
**
out
)
{
config_file_backend
*
h
=
GIT_CONTAINER_OF
(
cfg
,
config_file_backend
,
parent
);
git_config_
entries
*
entries
=
NULL
;
git_config_
list
*
config_list
=
NULL
;
git_config_entry
*
entry
;
int
error
=
0
;
if
(
!
h
->
parent
.
readonly
&&
((
error
=
config_file_refresh
(
cfg
))
<
0
))
return
error
;
if
((
error
=
config_file_
entries_take
(
&
entries
,
h
))
<
0
)
if
((
error
=
config_file_
take_list
(
&
config_list
,
h
))
<
0
)
return
error
;
if
((
error
=
(
git_config_
entries_get
(
&
entry
,
entries
,
key
)))
<
0
)
{
git_config_
entries_free
(
entries
);
if
((
error
=
(
git_config_
list_get
(
&
entry
,
config_list
,
key
)))
<
0
)
{
git_config_
list_free
(
config_list
);
return
error
;
}
...
...
@@ -394,7 +394,7 @@ out:
static
int
config_file_delete
(
git_config_backend
*
cfg
,
const
char
*
name
)
{
config_file_backend
*
b
=
GIT_CONTAINER_OF
(
cfg
,
config_file_backend
,
parent
);
git_config_
entries
*
entries
=
NULL
;
git_config_
list
*
config_list
=
NULL
;
git_config_entry
*
entry
;
char
*
key
=
NULL
;
int
error
;
...
...
@@ -402,11 +402,11 @@ static int config_file_delete(git_config_backend *cfg, const char *name)
if
((
error
=
git_config__normalize_name
(
name
,
&
key
))
<
0
)
goto
out
;
if
((
error
=
config_file_
entries_take
(
&
entries
,
b
))
<
0
)
if
((
error
=
config_file_
take_list
(
&
config_list
,
b
))
<
0
)
goto
out
;
/* Check whether we'd be modifying an included or multivar key */
if
((
error
=
git_config_
entries_get_unique
(
&
entry
,
entries
,
key
))
<
0
)
{
if
((
error
=
git_config_
list_get_unique
(
&
entry
,
config_list
,
key
))
<
0
)
{
if
(
error
==
GIT_ENOTFOUND
)
git_error_set
(
GIT_ERROR_CONFIG
,
"could not find key '%s' to delete"
,
name
);
goto
out
;
...
...
@@ -416,7 +416,7 @@ static int config_file_delete(git_config_backend *cfg, const char *name)
goto
out
;
out:
git_config_
entries_free
(
entries
);
git_config_
list_free
(
config_list
);
git__free
(
key
);
return
error
;
}
...
...
@@ -424,7 +424,7 @@ out:
static
int
config_file_delete_multivar
(
git_config_backend
*
cfg
,
const
char
*
name
,
const
char
*
regexp
)
{
config_file_backend
*
b
=
GIT_CONTAINER_OF
(
cfg
,
config_file_backend
,
parent
);
git_config_
entries
*
entries
=
NULL
;
git_config_
list
*
config_list
=
NULL
;
git_config_entry
*
entry
=
NULL
;
git_regexp
preg
=
GIT_REGEX_INIT
;
char
*
key
=
NULL
;
...
...
@@ -433,10 +433,10 @@ static int config_file_delete_multivar(git_config_backend *cfg, const char *name
if
((
result
=
git_config__normalize_name
(
name
,
&
key
))
<
0
)
goto
out
;
if
((
result
=
config_file_
entries_take
(
&
entries
,
b
))
<
0
)
if
((
result
=
config_file_
take_list
(
&
config_list
,
b
))
<
0
)
goto
out
;
if
((
result
=
git_config_
entries_get
(
&
entry
,
entries
,
key
))
<
0
)
{
if
((
result
=
git_config_
list_get
(
&
entry
,
config_list
,
key
))
<
0
)
{
if
(
result
==
GIT_ENOTFOUND
)
git_error_set
(
GIT_ERROR_CONFIG
,
"could not find key '%s' to delete"
,
name
);
goto
out
;
...
...
@@ -449,7 +449,7 @@ static int config_file_delete_multivar(git_config_backend *cfg, const char *name
goto
out
;
out:
git_config_
entries_free
(
entries
);
git_config_
list_free
(
config_list
);
git__free
(
key
);
git_regexp_dispose
(
&
preg
);
return
result
;
...
...
@@ -589,7 +589,7 @@ static int parse_include(config_file_parse_data *parse_data, const char *file)
git_array_init
(
include
->
includes
);
include
->
path
=
git_str_detach
(
&
path
);
result
=
config_file_read
(
parse_data
->
entries
,
parse_data
->
repo
,
include
,
result
=
config_file_read
(
parse_data
->
config_list
,
parse_data
->
repo
,
include
,
parse_data
->
level
,
parse_data
->
depth
+
1
);
if
(
result
==
GIT_ENOTFOUND
)
{
...
...
@@ -804,9 +804,9 @@ static int read_on_variable(
entry
->
level
=
parse_data
->
level
;
entry
->
include_depth
=
parse_data
->
depth
;
entry
->
free
=
config_file_entry_free
;
entry
->
payload
=
parse_data
->
entries
;
entry
->
payload
=
parse_data
->
config_list
;
if
((
result
=
git_config_
entries_append
(
parse_data
->
entries
,
entry
))
<
0
)
if
((
result
=
git_config_
list_append
(
parse_data
->
config_list
,
entry
))
<
0
)
return
result
;
result
=
0
;
...
...
@@ -822,7 +822,7 @@ static int read_on_variable(
}
static
int
config_file_read_buffer
(
git_config_
entries
*
entries
,
git_config_
list
*
config_list
,
const
git_repository
*
repo
,
config_file
*
file
,
git_config_level_t
level
,
...
...
@@ -851,7 +851,7 @@ static int config_file_read_buffer(
parse_data
.
repo
=
repo
;
parse_data
.
file
=
file
;
parse_data
.
entries
=
entries
;
parse_data
.
config_list
=
config_list
;
parse_data
.
level
=
level
;
parse_data
.
depth
=
depth
;
...
...
@@ -862,7 +862,7 @@ out:
}
static
int
config_file_read
(
git_config_
entries
*
entries
,
git_config_
list
*
config_list
,
const
git_repository
*
repo
,
config_file
*
file
,
git_config_level_t
level
,
...
...
@@ -884,7 +884,7 @@ static int config_file_read(
if
((
error
=
git_hash_buf
(
file
->
checksum
,
contents
.
ptr
,
contents
.
size
,
GIT_HASH_ALGORITHM_SHA256
))
<
0
)
goto
out
;
if
((
error
=
config_file_read_buffer
(
entries
,
repo
,
file
,
level
,
depth
,
if
((
error
=
config_file_read_buffer
(
config_list
,
repo
,
file
,
level
,
depth
,
contents
.
ptr
,
contents
.
size
))
<
0
)
goto
out
;
...
...
src/libgit2/config_
entries
.c
→
src/libgit2/config_
list
.c
View file @
650a9dff
...
...
@@ -5,7 +5,7 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
#include "config_
entries
.h"
#include "config_
list
.h"
typedef
struct
config_entry_list
{
struct
config_entry_list
*
next
;
...
...
@@ -18,36 +18,36 @@ typedef struct {
bool
multivar
;
}
config_entry_map_head
;
typedef
struct
config_
entries
_iterator
{
typedef
struct
config_
list
_iterator
{
git_config_iterator
parent
;
git_config_
entries
*
entries
;
git_config_
list
*
list
;
config_entry_list
*
head
;
}
config_
entries
_iterator
;
}
config_
list
_iterator
;
struct
git_config_
entries
{
struct
git_config_
list
{
git_refcount
rc
;
git_strmap
*
map
;
config_entry_list
*
list
;
config_entry_list
*
entries
;
};
int
git_config_
entries_new
(
git_config_entries
**
out
)
int
git_config_
list_new
(
git_config_list
**
out
)
{
git_config_
entries
*
entries
;
git_config_
list
*
config_list
;
int
error
;
entries
=
git__calloc
(
1
,
sizeof
(
git_config_entries
));
GIT_ERROR_CHECK_ALLOC
(
entries
);
GIT_REFCOUNT_INC
(
entries
);
config_list
=
git__calloc
(
1
,
sizeof
(
git_config_list
));
GIT_ERROR_CHECK_ALLOC
(
config_list
);
GIT_REFCOUNT_INC
(
config_list
);
if
((
error
=
git_strmap_new
(
&
entries
->
map
))
<
0
)
git__free
(
entries
);
if
((
error
=
git_strmap_new
(
&
config_list
->
map
))
<
0
)
git__free
(
config_list
);
else
*
out
=
entries
;
*
out
=
config_list
;
return
error
;
}
int
git_config_
entries_dup_entry
(
git_config_entries
*
entries
,
const
git_config_entry
*
entry
)
int
git_config_
list_dup_entry
(
git_config_list
*
config_list
,
const
git_config_entry
*
entry
)
{
git_config_entry
*
duplicated
;
int
error
;
...
...
@@ -65,7 +65,7 @@ int git_config_entries_dup_entry(git_config_entries *entries, const git_config_e
duplicated
->
level
=
entry
->
level
;
duplicated
->
include_depth
=
entry
->
include_depth
;
if
((
error
=
git_config_
entries_append
(
entries
,
duplicated
))
<
0
)
if
((
error
=
git_config_
list_append
(
config_list
,
duplicated
))
<
0
)
goto
out
;
out:
...
...
@@ -77,78 +77,79 @@ out:
return
error
;
}
int
git_config_
entries_dup
(
git_config_entries
**
out
,
git_config_entries
*
entries
)
int
git_config_
list_dup
(
git_config_list
**
out
,
git_config_list
*
config_list
)
{
git_config_
entries
*
result
=
NULL
;
git_config_
list
*
result
=
NULL
;
config_entry_list
*
head
;
int
error
;
if
((
error
=
git_config_
entries
_new
(
&
result
))
<
0
)
if
((
error
=
git_config_
list
_new
(
&
result
))
<
0
)
goto
out
;
for
(
head
=
entries
->
list
;
head
;
head
=
head
->
next
)
if
((
git_config_
entries
_dup_entry
(
result
,
head
->
entry
))
<
0
)
for
(
head
=
config_list
->
entries
;
head
;
head
=
head
->
next
)
if
((
git_config_
list
_dup_entry
(
result
,
head
->
entry
))
<
0
)
goto
out
;
*
out
=
result
;
result
=
NULL
;
out:
git_config_
entries
_free
(
result
);
git_config_
list
_free
(
result
);
return
error
;
}
void
git_config_
entries_incref
(
git_config_entries
*
entries
)
void
git_config_
list_incref
(
git_config_list
*
config_list
)
{
GIT_REFCOUNT_INC
(
entries
);
GIT_REFCOUNT_INC
(
config_list
);
}
static
void
config_
entries_free
(
git_config_entries
*
entries
)
static
void
config_
list_free
(
git_config_list
*
config_list
)
{
config_entry_list
*
list
=
NULL
,
*
next
;
config_entry_list
*
entry_
list
=
NULL
,
*
next
;
config_entry_map_head
*
head
;
git_strmap_foreach_value
(
entries
->
map
,
head
,
git__free
((
char
*
)
head
->
entry
->
name
);
git__free
(
head
)
);
git_strmap_free
(
entries
->
map
);
list
=
entries
->
list
;
while
(
list
!=
NULL
)
{
next
=
list
->
next
;
git__free
((
char
*
)
list
->
entry
->
value
);
git__free
(
list
->
entry
);
git__free
(
list
);
list
=
next
;
git_strmap_foreach_value
(
config_list
->
map
,
head
,
{
git__free
((
char
*
)
head
->
entry
->
name
);
git__free
(
head
);
});
git_strmap_free
(
config_list
->
map
);
entry_list
=
config_list
->
entries
;
while
(
entry_list
!=
NULL
)
{
next
=
entry_list
->
next
;
git__free
((
char
*
)
entry_list
->
entry
->
value
);
git__free
(
entry_list
->
entry
);
git__free
(
entry_list
);
entry_list
=
next
;
}
git__free
(
entries
);
git__free
(
config_list
);
}
void
git_config_
entries_free
(
git_config_entries
*
entries
)
void
git_config_
list_free
(
git_config_list
*
config_list
)
{
if
(
entries
)
GIT_REFCOUNT_DEC
(
entries
,
config_entries
_free
);
if
(
config_list
)
GIT_REFCOUNT_DEC
(
config_list
,
config_list
_free
);
}
int
git_config_
entries_append
(
git_config_entries
*
entries
,
git_config_entry
*
entry
)
int
git_config_
list_append
(
git_config_list
*
config_list
,
git_config_entry
*
entry
)
{
config_entry_list
*
list_head
;
config_entry_map_head
*
map_head
;
if
((
map_head
=
git_strmap_get
(
entries
->
map
,
entry
->
name
))
!=
NULL
)
{
if
((
map_head
=
git_strmap_get
(
config_list
->
map
,
entry
->
name
))
!=
NULL
)
{
map_head
->
multivar
=
true
;
/*
* This is a micro-optimization for configuration files
* with a lot of same keys. As for multivars the entry's
* key will be the same for all
entries
, we can just free
* key will be the same for all
list
, we can just free
* all except the first entry's name and just re-use it.
*/
git__free
((
char
*
)
entry
->
name
);
entry
->
name
=
map_head
->
entry
->
name
;
}
else
{
map_head
=
git__calloc
(
1
,
sizeof
(
*
map_head
));
if
((
git_strmap_set
(
entries
->
map
,
entry
->
name
,
map_head
))
<
0
)
if
((
git_strmap_set
(
config_list
->
map
,
entry
->
name
,
map_head
))
<
0
)
return
-
1
;
}
map_head
->
entry
=
entry
;
...
...
@@ -157,29 +158,29 @@ int git_config_entries_append(git_config_entries *entries, git_config_entry *ent
GIT_ERROR_CHECK_ALLOC
(
list_head
);
list_head
->
entry
=
entry
;
if
(
entries
->
list
)
entries
->
list
->
last
->
next
=
list_head
;
if
(
config_list
->
entries
)
config_list
->
entries
->
last
->
next
=
list_head
;
else
entries
->
list
=
list_head
;
entries
->
list
->
last
=
list_head
;
config_list
->
entries
=
list_head
;
config_list
->
entries
->
last
=
list_head
;
return
0
;
}
int
git_config_
entries_get
(
git_config_entry
**
out
,
git_config_entries
*
entries
,
const
char
*
key
)
int
git_config_
list_get
(
git_config_entry
**
out
,
git_config_list
*
config_list
,
const
char
*
key
)
{
config_entry_map_head
*
entry
;
if
((
entry
=
git_strmap_get
(
entries
->
map
,
key
))
==
NULL
)
if
((
entry
=
git_strmap_get
(
config_list
->
map
,
key
))
==
NULL
)
return
GIT_ENOTFOUND
;
*
out
=
entry
->
entry
;
return
0
;
}
int
git_config_
entries_get_unique
(
git_config_entry
**
out
,
git_config_entries
*
entries
,
const
char
*
key
)
int
git_config_
list_get_unique
(
git_config_entry
**
out
,
git_config_list
*
config_list
,
const
char
*
key
)
{
config_entry_map_head
*
entry
;
if
((
entry
=
git_strmap_get
(
entries
->
map
,
key
))
==
NULL
)
if
((
entry
=
git_strmap_get
(
config_list
->
map
,
key
))
==
NULL
)
return
GIT_ENOTFOUND
;
if
(
entry
->
multivar
)
{
...
...
@@ -199,8 +200,8 @@ int git_config_entries_get_unique(git_config_entry **out, git_config_entries *en
static
void
config_iterator_free
(
git_config_iterator
*
iter
)
{
config_
entries_iterator
*
it
=
(
config_entries
_iterator
*
)
iter
;
git_config_
entries_free
(
it
->
entries
);
config_
list_iterator
*
it
=
(
config_list
_iterator
*
)
iter
;
git_config_
list_free
(
it
->
list
);
git__free
(
it
);
}
...
...
@@ -208,7 +209,7 @@ static int config_iterator_next(
git_config_entry
**
entry
,
git_config_iterator
*
iter
)
{
config_
entries_iterator
*
it
=
(
config_entries
_iterator
*
)
iter
;
config_
list_iterator
*
it
=
(
config_list
_iterator
*
)
iter
;
if
(
!
it
->
head
)
return
GIT_ITEROVER
;
...
...
@@ -219,18 +220,18 @@ static int config_iterator_next(
return
0
;
}
int
git_config_
entries_iterator_new
(
git_config_iterator
**
out
,
git_config_entries
*
entries
)
int
git_config_
list_iterator_new
(
git_config_iterator
**
out
,
git_config_list
*
config_list
)
{
config_
entries
_iterator
*
it
;
config_
list
_iterator
*
it
;
it
=
git__calloc
(
1
,
sizeof
(
config_
entries
_iterator
));
it
=
git__calloc
(
1
,
sizeof
(
config_
list
_iterator
));
GIT_ERROR_CHECK_ALLOC
(
it
);
it
->
parent
.
next
=
config_iterator_next
;
it
->
parent
.
free
=
config_iterator_free
;
it
->
head
=
entries
->
list
;
it
->
entries
=
entries
;
it
->
head
=
config_list
->
entries
;
it
->
list
=
config_list
;
git_config_
entries_incref
(
entries
);
git_config_
list_incref
(
config_list
);
*
out
=
&
it
->
parent
;
return
0
;
...
...
src/libgit2/config_list.h
0 → 100644
View file @
650a9dff
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
#include "git2/sys/config.h"
#include "config.h"
typedef
struct
git_config_list
git_config_list
;
int
git_config_list_new
(
git_config_list
**
out
);
int
git_config_list_dup
(
git_config_list
**
out
,
git_config_list
*
list
);
int
git_config_list_dup_entry
(
git_config_list
*
list
,
const
git_config_entry
*
entry
);
void
git_config_list_incref
(
git_config_list
*
list
);
void
git_config_list_free
(
git_config_list
*
list
);
/* Add or append the new config option */
int
git_config_list_append
(
git_config_list
*
list
,
git_config_entry
*
entry
);
int
git_config_list_get
(
git_config_entry
**
out
,
git_config_list
*
list
,
const
char
*
key
);
int
git_config_list_get_unique
(
git_config_entry
**
out
,
git_config_list
*
list
,
const
char
*
key
);
int
git_config_list_iterator_new
(
git_config_iterator
**
out
,
git_config_list
*
list
);
src/libgit2/config_mem.c
View file @
650a9dff
...
...
@@ -9,16 +9,16 @@
#include "config_backend.h"
#include "config_parse.h"
#include "config_
entries
.h"
#include "config_
list
.h"
typedef
struct
{
git_config_backend
parent
;
git_config_
entries
*
entries
;
git_config_
list
*
config_list
;
git_str
cfg
;
}
config_memory_backend
;
typedef
struct
{
git_config_
entries
*
entries
;
git_config_
list
*
config_list
;
git_config_level_t
level
;
}
config_memory_parse_data
;
...
...
@@ -69,7 +69,7 @@ static int read_variable_cb(
entry
->
level
=
parse_data
->
level
;
entry
->
include_depth
=
0
;
if
((
result
=
git_config_
entries_append
(
parse_data
->
entries
,
entry
))
<
0
)
if
((
result
=
git_config_
list_append
(
parse_data
->
config_list
,
entry
))
<
0
)
return
result
;
return
result
;
...
...
@@ -87,7 +87,7 @@ static int config_memory_open(git_config_backend *backend, git_config_level_t le
if
((
error
=
git_config_parser_init
(
&
parser
,
"in-memory"
,
memory_backend
->
cfg
.
ptr
,
memory_backend
->
cfg
.
size
))
<
0
)
goto
out
;
parse_data
.
entries
=
memory_backend
->
entries
;
parse_data
.
config_list
=
memory_backend
->
config_list
;
parse_data
.
level
=
level
;
if
((
error
=
git_config_parse
(
&
parser
,
NULL
,
read_variable_cb
,
NULL
,
NULL
,
&
parse_data
))
<
0
)
...
...
@@ -101,7 +101,7 @@ out:
static
int
config_memory_get
(
git_config_backend
*
backend
,
const
char
*
key
,
git_config_entry
**
out
)
{
config_memory_backend
*
memory_backend
=
(
config_memory_backend
*
)
backend
;
return
git_config_
entries_get
(
out
,
memory_backend
->
entries
,
key
);
return
git_config_
list_get
(
out
,
memory_backend
->
config_list
,
key
);
}
static
int
config_memory_iterator
(
...
...
@@ -109,18 +109,18 @@ static int config_memory_iterator(
git_config_backend
*
backend
)
{
config_memory_backend
*
memory_backend
=
(
config_memory_backend
*
)
backend
;
git_config_
entries
*
entries
;
git_config_
list
*
config_list
;
int
error
;
if
((
error
=
git_config_
entries_dup
(
&
entries
,
memory_backend
->
entries
))
<
0
)
if
((
error
=
git_config_
list_dup
(
&
config_list
,
memory_backend
->
config_list
))
<
0
)
goto
out
;
if
((
error
=
git_config_
entries_iterator_new
(
iter
,
entries
))
<
0
)
if
((
error
=
git_config_
list_iterator_new
(
iter
,
config_list
))
<
0
)
goto
out
;
out:
/* Let iterator delete duplicated
entries
when it's done */
git_config_
entries_free
(
entries
);
/* Let iterator delete duplicated
config_list
when it's done */
git_config_
list_free
(
config_list
);
return
error
;
}
...
...
@@ -177,7 +177,7 @@ static void config_memory_free(git_config_backend *_backend)
if
(
backend
==
NULL
)
return
;
git_config_
entries_free
(
backend
->
entries
);
git_config_
list_free
(
backend
->
config_list
);
git_str_dispose
(
&
backend
->
cfg
);
git__free
(
backend
);
}
...
...
@@ -189,13 +189,13 @@ int git_config_backend_from_string(git_config_backend **out, const char *cfg, si
backend
=
git__calloc
(
1
,
sizeof
(
config_memory_backend
));
GIT_ERROR_CHECK_ALLOC
(
backend
);
if
(
git_config_
entries_new
(
&
backend
->
entries
)
<
0
)
{
if
(
git_config_
list_new
(
&
backend
->
config_list
)
<
0
)
{
git__free
(
backend
);
return
-
1
;
}
if
(
git_str_set
(
&
backend
->
cfg
,
cfg
,
len
)
<
0
)
{
git_config_
entries_free
(
backend
->
entries
);
git_config_
list_free
(
backend
->
config_list
);
git__free
(
backend
);
return
-
1
;
}
...
...
src/libgit2/config_snapshot.c
View file @
650a9dff
...
...
@@ -8,12 +8,12 @@
#include "config_backend.h"
#include "config.h"
#include "config_
entries
.h"
#include "config_
list
.h"
typedef
struct
{
git_config_backend
parent
;
git_mutex
values_mutex
;
git_config_
entries
*
entries
;
git_config_
list
*
config_list
;
git_config_backend
*
source
;
}
config_snapshot_backend
;
...
...
@@ -28,30 +28,30 @@ static int config_snapshot_iterator(
struct
git_config_backend
*
backend
)
{
config_snapshot_backend
*
b
=
GIT_CONTAINER_OF
(
backend
,
config_snapshot_backend
,
parent
);
git_config_
entries
*
entries
=
NULL
;
git_config_
list
*
config_list
=
NULL
;
int
error
;
if
((
error
=
git_config_
entries_dup
(
&
entries
,
b
->
entries
))
<
0
||
(
error
=
git_config_
entries_iterator_new
(
iter
,
entries
))
<
0
)
if
((
error
=
git_config_
list_dup
(
&
config_list
,
b
->
config_list
))
<
0
||
(
error
=
git_config_
list_iterator_new
(
iter
,
config_list
))
<
0
)
goto
out
;
out:
/* Let iterator delete duplicated
entries
when it's done */
git_config_
entries_free
(
entries
);
/* Let iterator delete duplicated
config_list
when it's done */
git_config_
list_free
(
config_list
);
return
error
;
}
/* release the map containing the entry as an equivalent to freeing it */
static
void
config_snapshot_entry_free
(
git_config_entry
*
entry
)
{
git_config_
entries
*
entries
=
(
git_config_entries
*
)
entry
->
payload
;
git_config_
entries_free
(
entries
);
git_config_
list
*
config_list
=
(
git_config_list
*
)
entry
->
payload
;
git_config_
list_free
(
config_list
);
}
static
int
config_snapshot_get
(
git_config_backend
*
cfg
,
const
char
*
key
,
git_config_entry
**
out
)
{
config_snapshot_backend
*
b
=
GIT_CONTAINER_OF
(
cfg
,
config_snapshot_backend
,
parent
);
git_config_
entries
*
entries
=
NULL
;
git_config_
list
*
config_list
=
NULL
;
git_config_entry
*
entry
;
int
error
=
0
;
...
...
@@ -60,17 +60,17 @@ static int config_snapshot_get(git_config_backend *cfg, const char *key, git_con
return
-
1
;
}
entries
=
b
->
entries
;
git_config_
entries_incref
(
entries
);
config_list
=
b
->
config_list
;
git_config_
list_incref
(
config_list
);
git_mutex_unlock
(
&
b
->
values_mutex
);
if
((
error
=
(
git_config_
entries_get
(
&
entry
,
entries
,
key
)))
<
0
)
{
git_config_
entries_free
(
entries
);
if
((
error
=
(
git_config_
list_get
(
&
entry
,
config_list
,
key
)))
<
0
)
{
git_config_
list_free
(
config_list
);
return
error
;
}
entry
->
free
=
config_snapshot_entry_free
;
entry
->
payload
=
entries
;
entry
->
payload
=
config_list
;
*
out
=
entry
;
return
0
;
...
...
@@ -135,7 +135,7 @@ static void config_snapshot_free(git_config_backend *_backend)
if
(
backend
==
NULL
)
return
;
git_config_
entries_free
(
backend
->
entries
);
git_config_
list_free
(
backend
->
config_list
);
git_mutex_free
(
&
backend
->
values_mutex
);
git__free
(
backend
);
}
...
...
@@ -143,7 +143,7 @@ static void config_snapshot_free(git_config_backend *_backend)
static
int
config_snapshot_open
(
git_config_backend
*
cfg
,
git_config_level_t
level
,
const
git_repository
*
repo
)
{
config_snapshot_backend
*
b
=
GIT_CONTAINER_OF
(
cfg
,
config_snapshot_backend
,
parent
);
git_config_
entries
*
entries
=
NULL
;
git_config_
list
*
config_list
=
NULL
;
git_config_iterator
*
it
=
NULL
;
git_config_entry
*
entry
;
int
error
;
...
...
@@ -152,12 +152,12 @@ static int config_snapshot_open(git_config_backend *cfg, git_config_level_t leve
GIT_UNUSED
(
level
);
GIT_UNUSED
(
repo
);
if
((
error
=
git_config_
entries_new
(
&
entries
))
<
0
||
if
((
error
=
git_config_
list_new
(
&
config_list
))
<
0
||
(
error
=
b
->
source
->
iterator
(
&
it
,
b
->
source
))
<
0
)
goto
out
;
while
((
error
=
git_config_next
(
&
entry
,
it
))
==
0
)
if
((
error
=
git_config_
entries_dup_entry
(
entries
,
entry
))
<
0
)
if
((
error
=
git_config_
list_dup_entry
(
config_list
,
entry
))
<
0
)
goto
out
;
if
(
error
<
0
)
{
...
...
@@ -166,12 +166,12 @@ static int config_snapshot_open(git_config_backend *cfg, git_config_level_t leve
error
=
0
;
}
b
->
entries
=
entries
;
b
->
config_list
=
config_list
;
out:
git_config_iterator_free
(
it
);
if
(
error
)
git_config_
entries_free
(
entries
);
git_config_
list_free
(
config_list
);
return
error
;
}
...
...
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