rugged 0.27.10.1 → 0.28.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/rugged/extconf.rb +23 -2
- data/ext/rugged/rugged.c +48 -2
- data/ext/rugged/rugged.h +5 -0
- data/ext/rugged/rugged_allocator.c +89 -0
- data/ext/rugged/rugged_blob.c +3 -3
- data/ext/rugged/rugged_branch.c +1 -1
- data/ext/rugged/rugged_commit.c +8 -8
- data/ext/rugged/rugged_config.c +1 -1
- data/ext/rugged/rugged_diff.c +24 -4
- data/ext/rugged/rugged_note.c +1 -1
- data/ext/rugged/rugged_repo.c +10 -10
- data/ext/rugged/rugged_settings.c +1 -1
- data/lib/rugged/version.rb +1 -1
- data/vendor/libgit2/CMakeLists.txt +69 -47
- data/vendor/libgit2/cmake/Modules/AddCFlagIfSupported.cmake +15 -1
- data/vendor/libgit2/cmake/Modules/EnableWarnings.cmake +5 -8
- data/vendor/libgit2/cmake/Modules/FindmbedTLS.cmake +93 -0
- data/vendor/libgit2/deps/http-parser/CMakeLists.txt +2 -0
- data/vendor/libgit2/deps/http-parser/{LICENSE-MIT → COPYING} +0 -0
- data/vendor/libgit2/deps/regex/COPYING +502 -0
- data/vendor/libgit2/deps/winhttp/COPYING.GPL +993 -0
- data/vendor/libgit2/deps/winhttp/COPYING.LGPL +502 -0
- data/vendor/libgit2/deps/zlib/CMakeLists.txt +1 -0
- data/vendor/libgit2/deps/zlib/COPYING +27 -0
- data/vendor/libgit2/include/git2.h +3 -0
- data/vendor/libgit2/include/git2/annotated_commit.h +9 -0
- data/vendor/libgit2/include/git2/apply.h +129 -0
- data/vendor/libgit2/include/git2/attr.h +19 -8
- data/vendor/libgit2/include/git2/blame.h +41 -24
- data/vendor/libgit2/include/git2/blob.h +1 -1
- data/vendor/libgit2/include/git2/branch.h +1 -1
- data/vendor/libgit2/include/git2/buffer.h +2 -2
- data/vendor/libgit2/include/git2/checkout.h +20 -19
- data/vendor/libgit2/include/git2/cherrypick.h +6 -4
- data/vendor/libgit2/include/git2/clone.h +11 -9
- data/vendor/libgit2/include/git2/commit.h +30 -2
- data/vendor/libgit2/include/git2/common.h +54 -4
- data/vendor/libgit2/include/git2/config.h +18 -7
- data/vendor/libgit2/include/git2/deprecated.h +253 -0
- data/vendor/libgit2/include/git2/describe.h +30 -7
- data/vendor/libgit2/include/git2/diff.h +193 -143
- data/vendor/libgit2/include/git2/errors.h +54 -46
- data/vendor/libgit2/include/git2/ignore.h +2 -2
- data/vendor/libgit2/include/git2/index.h +72 -51
- data/vendor/libgit2/include/git2/indexer.h +30 -4
- data/vendor/libgit2/include/git2/mailmap.h +115 -0
- data/vendor/libgit2/include/git2/merge.h +29 -8
- data/vendor/libgit2/include/git2/net.h +1 -1
- data/vendor/libgit2/include/git2/notes.h +1 -1
- data/vendor/libgit2/include/git2/object.h +16 -16
- data/vendor/libgit2/include/git2/odb.h +10 -10
- data/vendor/libgit2/include/git2/odb_backend.h +7 -7
- data/vendor/libgit2/include/git2/oid.h +1 -1
- data/vendor/libgit2/include/git2/pack.h +2 -2
- data/vendor/libgit2/include/git2/proxy.h +9 -5
- data/vendor/libgit2/include/git2/rebase.h +7 -4
- data/vendor/libgit2/include/git2/refs.h +14 -15
- data/vendor/libgit2/include/git2/refspec.h +17 -0
- data/vendor/libgit2/include/git2/remote.h +92 -16
- data/vendor/libgit2/include/git2/repository.h +52 -37
- data/vendor/libgit2/include/git2/revert.h +5 -3
- data/vendor/libgit2/include/git2/revwalk.h +7 -7
- data/vendor/libgit2/include/git2/signature.h +2 -2
- data/vendor/libgit2/include/git2/stash.h +13 -10
- data/vendor/libgit2/include/git2/status.h +8 -4
- data/vendor/libgit2/include/git2/submodule.h +11 -10
- data/vendor/libgit2/include/git2/sys/alloc.h +101 -0
- data/vendor/libgit2/include/git2/sys/commit.h +1 -1
- data/vendor/libgit2/include/git2/sys/config.h +13 -13
- data/vendor/libgit2/include/git2/sys/filter.h +6 -6
- data/vendor/libgit2/include/git2/sys/index.h +3 -0
- data/vendor/libgit2/include/git2/sys/mempack.h +35 -35
- data/vendor/libgit2/include/git2/sys/merge.h +9 -4
- data/vendor/libgit2/include/git2/sys/odb_backend.h +19 -19
- data/vendor/libgit2/include/git2/sys/path.h +64 -0
- data/vendor/libgit2/include/git2/sys/refdb_backend.h +19 -19
- data/vendor/libgit2/include/git2/sys/stream.h +92 -12
- data/vendor/libgit2/include/git2/sys/transport.h +127 -81
- data/vendor/libgit2/include/git2/tag.h +2 -2
- data/vendor/libgit2/include/git2/trace.h +1 -1
- data/vendor/libgit2/include/git2/transaction.h +1 -0
- data/vendor/libgit2/include/git2/transport.h +47 -18
- data/vendor/libgit2/include/git2/tree.h +3 -3
- data/vendor/libgit2/include/git2/types.h +35 -28
- data/vendor/libgit2/include/git2/version.h +4 -4
- data/vendor/libgit2/include/git2/worktree.h +47 -12
- data/vendor/libgit2/src/CMakeLists.txt +87 -26
- data/vendor/libgit2/src/alloc.c +55 -0
- data/vendor/libgit2/src/alloc.h +40 -0
- data/vendor/libgit2/src/annotated_commit.c +15 -8
- data/vendor/libgit2/src/apply.c +490 -14
- data/vendor/libgit2/src/apply.h +3 -1
- data/vendor/libgit2/src/array.h +2 -2
- data/vendor/libgit2/src/attr.c +11 -11
- data/vendor/libgit2/src/attr_file.c +20 -15
- data/vendor/libgit2/src/attrcache.c +11 -11
- data/vendor/libgit2/src/blame.c +30 -15
- data/vendor/libgit2/src/blame.h +1 -0
- data/vendor/libgit2/src/blame_git.c +16 -13
- data/vendor/libgit2/src/blob.c +50 -28
- data/vendor/libgit2/src/blob.h +18 -1
- data/vendor/libgit2/src/branch.c +38 -38
- data/vendor/libgit2/src/buf_text.c +7 -6
- data/vendor/libgit2/src/buffer.c +55 -50
- data/vendor/libgit2/src/buffer.h +1 -1
- data/vendor/libgit2/src/cache.c +16 -16
- data/vendor/libgit2/src/cache.h +2 -2
- data/vendor/libgit2/src/cc-compat.h +15 -3
- data/vendor/libgit2/src/checkout.c +83 -74
- data/vendor/libgit2/src/cherrypick.c +6 -6
- data/vendor/libgit2/src/clone.c +20 -20
- data/vendor/libgit2/src/commit.c +53 -33
- data/vendor/libgit2/src/commit.h +1 -0
- data/vendor/libgit2/src/commit_list.c +6 -10
- data/vendor/libgit2/src/common.h +32 -30
- data/vendor/libgit2/src/config.c +167 -147
- data/vendor/libgit2/src/config.h +1 -14
- data/vendor/libgit2/src/config_backend.h +84 -0
- data/vendor/libgit2/src/config_cache.c +7 -1
- data/vendor/libgit2/src/config_entries.c +259 -0
- data/vendor/libgit2/src/config_entries.h +23 -0
- data/vendor/libgit2/src/config_file.c +167 -439
- data/vendor/libgit2/src/config_mem.c +224 -0
- data/vendor/libgit2/src/config_parse.c +69 -38
- data/vendor/libgit2/src/config_parse.h +4 -4
- data/vendor/libgit2/src/crlf.c +215 -186
- data/vendor/libgit2/src/delta.c +25 -18
- data/vendor/libgit2/src/describe.c +23 -23
- data/vendor/libgit2/src/diff.c +12 -12
- data/vendor/libgit2/src/diff_driver.c +14 -15
- data/vendor/libgit2/src/diff_file.c +10 -10
- data/vendor/libgit2/src/diff_generate.c +29 -23
- data/vendor/libgit2/src/diff_generate.h +1 -1
- data/vendor/libgit2/src/diff_parse.c +3 -3
- data/vendor/libgit2/src/diff_print.c +17 -17
- data/vendor/libgit2/src/diff_stats.c +22 -7
- data/vendor/libgit2/src/diff_tform.c +12 -12
- data/vendor/libgit2/src/diff_xdiff.c +15 -3
- data/vendor/libgit2/src/errors.c +42 -20
- data/vendor/libgit2/src/features.h.in +2 -1
- data/vendor/libgit2/src/fetch.c +3 -3
- data/vendor/libgit2/src/fetchhead.c +16 -16
- data/vendor/libgit2/src/filebuf.c +28 -28
- data/vendor/libgit2/src/fileops.c +54 -54
- data/vendor/libgit2/src/fileops.h +1 -1
- data/vendor/libgit2/src/filter.c +30 -30
- data/vendor/libgit2/src/filter.h +0 -10
- data/vendor/libgit2/src/global.c +36 -23
- data/vendor/libgit2/src/hash.h +4 -1
- data/vendor/libgit2/src/hash/hash_collisiondetect.h +6 -2
- data/vendor/libgit2/src/hash/hash_common_crypto.h +5 -1
- data/vendor/libgit2/src/hash/hash_generic.h +5 -1
- data/vendor/libgit2/src/hash/hash_mbedtls.c +38 -0
- data/vendor/libgit2/src/hash/hash_mbedtls.h +24 -0
- data/vendor/libgit2/src/hash/hash_openssl.h +8 -4
- data/vendor/libgit2/src/hash/hash_win32.c +13 -13
- data/vendor/libgit2/src/hashsig.c +4 -4
- data/vendor/libgit2/src/idxmap.c +25 -5
- data/vendor/libgit2/src/idxmap.h +4 -18
- data/vendor/libgit2/src/ignore.c +9 -9
- data/vendor/libgit2/src/index.c +280 -198
- data/vendor/libgit2/src/index.h +16 -0
- data/vendor/libgit2/src/indexer.c +311 -139
- data/vendor/libgit2/src/integer.h +32 -22
- data/vendor/libgit2/src/iterator.c +116 -49
- data/vendor/libgit2/src/iterator.h +15 -0
- data/vendor/libgit2/src/khash.h +3 -1
- data/vendor/libgit2/src/mailmap.c +485 -0
- data/vendor/libgit2/src/mailmap.h +35 -0
- data/vendor/libgit2/src/merge.c +89 -59
- data/vendor/libgit2/src/merge_driver.c +7 -7
- data/vendor/libgit2/src/merge_file.c +1 -1
- data/vendor/libgit2/src/mwindow.c +8 -8
- data/vendor/libgit2/src/netops.c +22 -13
- data/vendor/libgit2/src/netops.h +2 -0
- data/vendor/libgit2/src/notes.c +15 -10
- data/vendor/libgit2/src/object.c +118 -67
- data/vendor/libgit2/src/object.h +20 -9
- data/vendor/libgit2/src/object_api.c +8 -8
- data/vendor/libgit2/src/odb.c +72 -72
- data/vendor/libgit2/src/odb.h +7 -7
- data/vendor/libgit2/src/odb_loose.c +46 -46
- data/vendor/libgit2/src/odb_mempack.c +14 -14
- data/vendor/libgit2/src/odb_pack.c +14 -10
- data/vendor/libgit2/src/offmap.c +30 -0
- data/vendor/libgit2/src/offmap.h +20 -11
- data/vendor/libgit2/src/oid.c +6 -6
- data/vendor/libgit2/src/oidmap.c +20 -0
- data/vendor/libgit2/src/oidmap.h +9 -12
- data/vendor/libgit2/src/pack-objects.c +71 -63
- data/vendor/libgit2/src/pack-objects.h +1 -7
- data/vendor/libgit2/src/pack.c +58 -58
- data/vendor/libgit2/src/pack.h +6 -6
- data/vendor/libgit2/src/parse.h +1 -1
- data/vendor/libgit2/src/patch.c +3 -3
- data/vendor/libgit2/src/patch_generate.c +18 -18
- data/vendor/libgit2/src/patch_parse.c +13 -13
- data/vendor/libgit2/src/path.c +93 -225
- data/vendor/libgit2/src/path.h +2 -84
- data/vendor/libgit2/src/pathspec.c +6 -6
- data/vendor/libgit2/src/posix.c +3 -3
- data/vendor/libgit2/src/proxy.c +1 -1
- data/vendor/libgit2/src/push.c +27 -26
- data/vendor/libgit2/src/push.h +2 -1
- data/vendor/libgit2/src/reader.c +265 -0
- data/vendor/libgit2/src/reader.h +107 -0
- data/vendor/libgit2/src/rebase.c +49 -52
- data/vendor/libgit2/src/refdb.c +3 -3
- data/vendor/libgit2/src/refdb_fs.c +181 -103
- data/vendor/libgit2/src/reflog.c +3 -3
- data/vendor/libgit2/src/refs.c +98 -74
- data/vendor/libgit2/src/refs.h +5 -3
- data/vendor/libgit2/src/refspec.c +47 -21
- data/vendor/libgit2/src/refspec.h +1 -1
- data/vendor/libgit2/src/remote.c +219 -166
- data/vendor/libgit2/src/remote.h +9 -0
- data/vendor/libgit2/src/repository.c +173 -133
- data/vendor/libgit2/src/repository.h +6 -3
- data/vendor/libgit2/src/reset.c +8 -8
- data/vendor/libgit2/src/revert.c +6 -6
- data/vendor/libgit2/src/revparse.c +30 -30
- data/vendor/libgit2/src/revwalk.c +60 -30
- data/vendor/libgit2/src/revwalk.h +2 -1
- data/vendor/libgit2/src/settings.c +42 -10
- data/vendor/libgit2/src/signature.c +11 -11
- data/vendor/libgit2/src/sortedcache.c +13 -13
- data/vendor/libgit2/src/stash.c +91 -45
- data/vendor/libgit2/src/status.c +13 -13
- data/vendor/libgit2/src/stdalloc.c +120 -0
- data/vendor/libgit2/src/{streams/curl.h → stdalloc.h} +6 -6
- data/vendor/libgit2/src/stream.h +17 -2
- data/vendor/libgit2/src/streams/mbedtls.c +483 -0
- data/vendor/libgit2/src/streams/mbedtls.h +23 -0
- data/vendor/libgit2/src/streams/openssl.c +204 -114
- data/vendor/libgit2/src/streams/openssl.h +4 -108
- data/vendor/libgit2/src/streams/registry.c +118 -0
- data/vendor/libgit2/src/streams/registry.h +19 -0
- data/vendor/libgit2/src/streams/socket.c +54 -29
- data/vendor/libgit2/src/streams/stransport.c +57 -32
- data/vendor/libgit2/src/streams/stransport.h +5 -0
- data/vendor/libgit2/src/streams/tls.c +50 -19
- data/vendor/libgit2/src/streams/tls.h +12 -4
- data/vendor/libgit2/src/strmap.c +22 -2
- data/vendor/libgit2/src/strmap.h +18 -15
- data/vendor/libgit2/src/submodule.c +179 -155
- data/vendor/libgit2/src/sysdir.c +18 -18
- data/vendor/libgit2/src/tag.c +31 -26
- data/vendor/libgit2/src/tag.h +2 -1
- data/vendor/libgit2/src/trace.c +1 -1
- data/vendor/libgit2/src/trace.h +1 -1
- data/vendor/libgit2/src/trailer.c +6 -6
- data/vendor/libgit2/src/transaction.c +23 -23
- data/vendor/libgit2/src/transport.c +5 -5
- data/vendor/libgit2/src/transports/auth.c +7 -4
- data/vendor/libgit2/src/transports/auth.h +1 -1
- data/vendor/libgit2/src/transports/auth_negotiate.c +12 -11
- data/vendor/libgit2/src/transports/cred.c +18 -18
- data/vendor/libgit2/src/transports/git.c +15 -15
- data/vendor/libgit2/src/transports/http.c +606 -216
- data/vendor/libgit2/src/transports/http.h +2 -0
- data/vendor/libgit2/src/transports/local.c +26 -26
- data/vendor/libgit2/src/transports/smart.c +54 -31
- data/vendor/libgit2/src/transports/smart.h +1 -2
- data/vendor/libgit2/src/transports/smart_pkt.c +43 -40
- data/vendor/libgit2/src/transports/smart_protocol.c +61 -57
- data/vendor/libgit2/src/transports/ssh.c +34 -33
- data/vendor/libgit2/src/transports/winhttp.c +99 -119
- data/vendor/libgit2/src/tree-cache.c +5 -5
- data/vendor/libgit2/src/tree.c +96 -121
- data/vendor/libgit2/src/tree.h +1 -12
- data/vendor/libgit2/src/unix/map.c +2 -2
- data/vendor/libgit2/src/util.c +22 -6
- data/vendor/libgit2/src/util.h +12 -135
- data/vendor/libgit2/src/vector.c +4 -4
- data/vendor/libgit2/src/win32/dir.c +3 -3
- data/vendor/libgit2/src/win32/findfile.c +3 -3
- data/vendor/libgit2/src/win32/map.c +6 -6
- data/vendor/libgit2/src/win32/msvc-compat.h +6 -0
- data/vendor/libgit2/src/win32/path_w32.c +101 -7
- data/vendor/libgit2/src/win32/path_w32.h +18 -0
- data/vendor/libgit2/src/win32/posix_w32.c +24 -43
- data/vendor/libgit2/src/win32/w32_buffer.c +2 -2
- data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +96 -2
- data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +28 -75
- data/vendor/libgit2/src/win32/w32_stack.c +2 -2
- data/vendor/libgit2/src/win32/w32_util.c +1 -69
- data/vendor/libgit2/src/win32/w32_util.h +1 -19
- data/vendor/libgit2/src/worktree.c +75 -54
- data/vendor/libgit2/src/worktree.h +2 -0
- data/vendor/libgit2/src/xdiff/xdiffi.c +7 -5
- data/vendor/libgit2/src/xdiff/xhistogram.c +1 -1
- data/vendor/libgit2/src/xdiff/xmerge.c +15 -15
- data/vendor/libgit2/src/zstream.c +4 -4
- metadata +33 -7
- data/vendor/libgit2/src/config_file.h +0 -73
- data/vendor/libgit2/src/streams/curl.c +0 -385
data/vendor/libgit2/src/config.h
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
|
25
25
|
struct git_config {
|
26
26
|
git_refcount rc;
|
27
|
-
git_vector
|
27
|
+
git_vector backends;
|
28
28
|
};
|
29
29
|
|
30
30
|
extern int git_config__global_location(git_buf *buf);
|
@@ -34,19 +34,6 @@ extern int git_config_rename_section(
|
|
34
34
|
const char *old_section_name, /* eg "branch.dummy" */
|
35
35
|
const char *new_section_name); /* NULL to drop the old section */
|
36
36
|
|
37
|
-
/**
|
38
|
-
* Create a configuration file backend for ondisk files
|
39
|
-
*
|
40
|
-
* These are the normal `.gitconfig` files that Core Git
|
41
|
-
* processes. Note that you first have to add this file to a
|
42
|
-
* configuration object before you can query it for configuration
|
43
|
-
* variables.
|
44
|
-
*
|
45
|
-
* @param out the new backend
|
46
|
-
* @param path where the config file is located
|
47
|
-
*/
|
48
|
-
extern int git_config_file__ondisk(git_config_backend **out, const char *path);
|
49
|
-
|
50
37
|
extern int git_config__normalize_name(const char *in, char **out);
|
51
38
|
|
52
39
|
/* internal only: does not normalize key and sets out to NULL if not found */
|
@@ -0,0 +1,84 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
#ifndef INCLUDE_config_file_h__
|
8
|
+
#define INCLUDE_config_file_h__
|
9
|
+
|
10
|
+
#include "common.h"
|
11
|
+
|
12
|
+
#include "git2/sys/config.h"
|
13
|
+
#include "git2/config.h"
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Create a configuration file backend for ondisk files
|
17
|
+
*
|
18
|
+
* These are the normal `.gitconfig` files that Core Git
|
19
|
+
* processes. Note that you first have to add this file to a
|
20
|
+
* configuration object before you can query it for configuration
|
21
|
+
* variables.
|
22
|
+
*
|
23
|
+
* @param out the new backend
|
24
|
+
* @param path where the config file is located
|
25
|
+
*/
|
26
|
+
extern int git_config_backend_from_file(git_config_backend **out, const char *path);
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Create an in-memory configuration file backend
|
30
|
+
*
|
31
|
+
* @param out the new backend
|
32
|
+
* @param cfg the configuration that is to be parsed
|
33
|
+
* @param len the length of the string pointed to by `cfg`
|
34
|
+
*/
|
35
|
+
extern int git_config_backend_from_string(git_config_backend **out, const char *cfg, size_t len);
|
36
|
+
|
37
|
+
GIT_INLINE(int) git_config_backend_open(git_config_backend *cfg, unsigned int level, const git_repository *repo)
|
38
|
+
{
|
39
|
+
return cfg->open(cfg, level, repo);
|
40
|
+
}
|
41
|
+
|
42
|
+
GIT_INLINE(void) git_config_backend_free(git_config_backend *cfg)
|
43
|
+
{
|
44
|
+
if (cfg)
|
45
|
+
cfg->free(cfg);
|
46
|
+
}
|
47
|
+
|
48
|
+
GIT_INLINE(int) git_config_backend_get_string(
|
49
|
+
git_config_entry **out, git_config_backend *cfg, const char *name)
|
50
|
+
{
|
51
|
+
return cfg->get(cfg, name, out);
|
52
|
+
}
|
53
|
+
|
54
|
+
GIT_INLINE(int) git_config_backend_set_string(
|
55
|
+
git_config_backend *cfg, const char *name, const char *value)
|
56
|
+
{
|
57
|
+
return cfg->set(cfg, name, value);
|
58
|
+
}
|
59
|
+
|
60
|
+
GIT_INLINE(int) git_config_backend_delete(
|
61
|
+
git_config_backend *cfg, const char *name)
|
62
|
+
{
|
63
|
+
return cfg->del(cfg, name);
|
64
|
+
}
|
65
|
+
|
66
|
+
GIT_INLINE(int) git_config_backend_foreach(
|
67
|
+
git_config_backend *cfg,
|
68
|
+
int (*fn)(const git_config_entry *entry, void *data),
|
69
|
+
void *data)
|
70
|
+
{
|
71
|
+
return git_config_backend_foreach_match(cfg, NULL, fn, data);
|
72
|
+
}
|
73
|
+
|
74
|
+
GIT_INLINE(int) git_config_backend_lock(git_config_backend *cfg)
|
75
|
+
{
|
76
|
+
return cfg->lock(cfg);
|
77
|
+
}
|
78
|
+
|
79
|
+
GIT_INLINE(int) git_config_backend_unlock(git_config_backend *cfg, int success)
|
80
|
+
{
|
81
|
+
return cfg->unlock(cfg, success);
|
82
|
+
}
|
83
|
+
|
84
|
+
#endif
|
@@ -58,6 +58,12 @@ static git_cvar_map _cvar_map_safecrlf[] = {
|
|
58
58
|
{GIT_CVAR_STRING, "warn", GIT_SAFE_CRLF_WARN}
|
59
59
|
};
|
60
60
|
|
61
|
+
static git_cvar_map _cvar_map_logallrefupdates[] = {
|
62
|
+
{GIT_CVAR_FALSE, NULL, GIT_LOGALLREFUPDATES_FALSE},
|
63
|
+
{GIT_CVAR_TRUE, NULL, GIT_LOGALLREFUPDATES_TRUE},
|
64
|
+
{GIT_CVAR_STRING, "always", GIT_LOGALLREFUPDATES_ALWAYS},
|
65
|
+
};
|
66
|
+
|
61
67
|
/*
|
62
68
|
* Generic map for integer values
|
63
69
|
*/
|
@@ -76,7 +82,7 @@ static struct map_data _cvar_maps[] = {
|
|
76
82
|
{"core.abbrev", _cvar_map_int, 1, GIT_ABBREV_DEFAULT },
|
77
83
|
{"core.precomposeunicode", NULL, 0, GIT_PRECOMPOSE_DEFAULT },
|
78
84
|
{"core.safecrlf", _cvar_map_safecrlf, ARRAY_SIZE(_cvar_map_safecrlf), GIT_SAFE_CRLF_DEFAULT},
|
79
|
-
{"core.logallrefupdates",
|
85
|
+
{"core.logallrefupdates", _cvar_map_logallrefupdates, ARRAY_SIZE(_cvar_map_logallrefupdates), GIT_LOGALLREFUPDATES_DEFAULT},
|
80
86
|
{"core.protecthfs", NULL, 0, GIT_PROTECTHFS_DEFAULT },
|
81
87
|
{"core.protectntfs", NULL, 0, GIT_PROTECTNTFS_DEFAULT },
|
82
88
|
{"core.fsyncobjectfiles", NULL, 0, GIT_FSYNCOBJECTFILES_DEFAULT },
|
@@ -0,0 +1,259 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include "config_entries.h"
|
9
|
+
|
10
|
+
typedef struct config_entry_list {
|
11
|
+
struct config_entry_list *next;
|
12
|
+
struct config_entry_list *last;
|
13
|
+
git_config_entry *entry;
|
14
|
+
} config_entry_list;
|
15
|
+
|
16
|
+
typedef struct config_entries_iterator {
|
17
|
+
git_config_iterator parent;
|
18
|
+
git_config_entries *entries;
|
19
|
+
config_entry_list *head;
|
20
|
+
} config_entries_iterator;
|
21
|
+
|
22
|
+
struct git_config_entries {
|
23
|
+
git_refcount rc;
|
24
|
+
git_strmap *map;
|
25
|
+
config_entry_list *list;
|
26
|
+
};
|
27
|
+
|
28
|
+
static void config_entry_list_free(config_entry_list *list)
|
29
|
+
{
|
30
|
+
config_entry_list *next;
|
31
|
+
|
32
|
+
while (list != NULL) {
|
33
|
+
next = list->next;
|
34
|
+
|
35
|
+
git__free((char*) list->entry->name);
|
36
|
+
git__free((char *) list->entry->value);
|
37
|
+
git__free(list->entry);
|
38
|
+
git__free(list);
|
39
|
+
|
40
|
+
list = next;
|
41
|
+
};
|
42
|
+
}
|
43
|
+
|
44
|
+
static void config_entry_list_append(config_entry_list **list, config_entry_list *entry)
|
45
|
+
{
|
46
|
+
if (*list)
|
47
|
+
(*list)->last->next = entry;
|
48
|
+
else
|
49
|
+
*list = entry;
|
50
|
+
(*list)->last = entry;
|
51
|
+
}
|
52
|
+
|
53
|
+
int git_config_entries_new(git_config_entries **out)
|
54
|
+
{
|
55
|
+
git_config_entries *entries;
|
56
|
+
int error;
|
57
|
+
|
58
|
+
entries = git__calloc(1, sizeof(git_config_entries));
|
59
|
+
GIT_ERROR_CHECK_ALLOC(entries);
|
60
|
+
GIT_REFCOUNT_INC(entries);
|
61
|
+
|
62
|
+
if ((error = git_strmap_alloc(&entries->map)) < 0)
|
63
|
+
git__free(entries);
|
64
|
+
else
|
65
|
+
*out = entries;
|
66
|
+
|
67
|
+
return error;
|
68
|
+
}
|
69
|
+
|
70
|
+
int git_config_entries_dup(git_config_entries **out, git_config_entries *entries)
|
71
|
+
{
|
72
|
+
git_config_entries *result = NULL;
|
73
|
+
config_entry_list *head;
|
74
|
+
int error;
|
75
|
+
|
76
|
+
if ((error = git_config_entries_new(&result)) < 0)
|
77
|
+
goto out;
|
78
|
+
|
79
|
+
for (head = entries->list; head; head = head->next) {
|
80
|
+
git_config_entry *dup;
|
81
|
+
|
82
|
+
dup = git__calloc(1, sizeof(git_config_entry));
|
83
|
+
dup->name = git__strdup(head->entry->name);
|
84
|
+
GIT_ERROR_CHECK_ALLOC(dup->name);
|
85
|
+
if (head->entry->value) {
|
86
|
+
dup->value = git__strdup(head->entry->value);
|
87
|
+
GIT_ERROR_CHECK_ALLOC(dup->value);
|
88
|
+
}
|
89
|
+
dup->level = head->entry->level;
|
90
|
+
dup->include_depth = head->entry->include_depth;
|
91
|
+
|
92
|
+
if ((error = git_config_entries_append(result, dup)) < 0)
|
93
|
+
goto out;
|
94
|
+
}
|
95
|
+
|
96
|
+
*out = result;
|
97
|
+
result = NULL;
|
98
|
+
|
99
|
+
out:
|
100
|
+
git_config_entries_free(result);
|
101
|
+
return error;
|
102
|
+
}
|
103
|
+
|
104
|
+
void git_config_entries_incref(git_config_entries *entries)
|
105
|
+
{
|
106
|
+
GIT_REFCOUNT_INC(entries);
|
107
|
+
}
|
108
|
+
|
109
|
+
static void config_entries_free(git_config_entries *entries)
|
110
|
+
{
|
111
|
+
config_entry_list *list = NULL, *next;
|
112
|
+
|
113
|
+
git_strmap_foreach_value(entries->map, list, config_entry_list_free(list));
|
114
|
+
git_strmap_free(entries->map);
|
115
|
+
|
116
|
+
list = entries->list;
|
117
|
+
while (list != NULL) {
|
118
|
+
next = list->next;
|
119
|
+
git__free(list);
|
120
|
+
list = next;
|
121
|
+
}
|
122
|
+
|
123
|
+
git__free(entries);
|
124
|
+
}
|
125
|
+
|
126
|
+
void git_config_entries_free(git_config_entries *entries)
|
127
|
+
{
|
128
|
+
if (entries)
|
129
|
+
GIT_REFCOUNT_DEC(entries, config_entries_free);
|
130
|
+
}
|
131
|
+
|
132
|
+
int git_config_entries_append(git_config_entries *entries, git_config_entry *entry)
|
133
|
+
{
|
134
|
+
config_entry_list *existing, *var;
|
135
|
+
int error = 0;
|
136
|
+
size_t pos;
|
137
|
+
|
138
|
+
var = git__calloc(1, sizeof(config_entry_list));
|
139
|
+
GIT_ERROR_CHECK_ALLOC(var);
|
140
|
+
var->entry = entry;
|
141
|
+
|
142
|
+
pos = git_strmap_lookup_index(entries->map, entry->name);
|
143
|
+
if (!git_strmap_valid_index(entries->map, pos)) {
|
144
|
+
/*
|
145
|
+
* We only ever inspect `last` from the first config
|
146
|
+
* entry in a multivar. In case where this new entry is
|
147
|
+
* the first one in the entry map, it will also be the
|
148
|
+
* last one at the time of adding it, which is
|
149
|
+
* why we set `last` here to itself. Otherwise we
|
150
|
+
* do not have to set `last` and leave it set to
|
151
|
+
* `NULL`.
|
152
|
+
*/
|
153
|
+
var->last = var;
|
154
|
+
|
155
|
+
git_strmap_insert(entries->map, entry->name, var, &error);
|
156
|
+
|
157
|
+
if (error > 0)
|
158
|
+
error = 0;
|
159
|
+
} else {
|
160
|
+
existing = git_strmap_value_at(entries->map, pos);
|
161
|
+
config_entry_list_append(&existing, var);
|
162
|
+
}
|
163
|
+
|
164
|
+
var = git__calloc(1, sizeof(config_entry_list));
|
165
|
+
GIT_ERROR_CHECK_ALLOC(var);
|
166
|
+
var->entry = entry;
|
167
|
+
config_entry_list_append(&entries->list, var);
|
168
|
+
|
169
|
+
return error;
|
170
|
+
}
|
171
|
+
|
172
|
+
int config_entry_get(config_entry_list **out, git_config_entries *entries, const char *key)
|
173
|
+
{
|
174
|
+
size_t pos;
|
175
|
+
|
176
|
+
pos = git_strmap_lookup_index(entries->map, key);
|
177
|
+
|
178
|
+
/* no error message; the config system will write one */
|
179
|
+
if (!git_strmap_valid_index(entries->map, pos))
|
180
|
+
return GIT_ENOTFOUND;
|
181
|
+
|
182
|
+
*out = git_strmap_value_at(entries->map, pos);
|
183
|
+
|
184
|
+
return 0;
|
185
|
+
}
|
186
|
+
|
187
|
+
int git_config_entries_get(git_config_entry **out, git_config_entries *entries, const char *key)
|
188
|
+
{
|
189
|
+
config_entry_list *entry;
|
190
|
+
int error;
|
191
|
+
|
192
|
+
if ((error = config_entry_get(&entry, entries, key)) < 0)
|
193
|
+
return error;
|
194
|
+
*out = entry->last->entry;
|
195
|
+
|
196
|
+
return 0;
|
197
|
+
}
|
198
|
+
|
199
|
+
int git_config_entries_get_unique(git_config_entry **out, git_config_entries *entries, const char *key)
|
200
|
+
{
|
201
|
+
config_entry_list *entry;
|
202
|
+
int error;
|
203
|
+
|
204
|
+
if ((error = config_entry_get(&entry, entries, key)) < 0)
|
205
|
+
return error;
|
206
|
+
|
207
|
+
if (entry->next != NULL) {
|
208
|
+
git_error_set(GIT_ERROR_CONFIG, "entry is not unique due to being a multivar");
|
209
|
+
return -1;
|
210
|
+
}
|
211
|
+
|
212
|
+
if (entry->entry->include_depth) {
|
213
|
+
git_error_set(GIT_ERROR_CONFIG, "entry is not unique due to being included");
|
214
|
+
return -1;
|
215
|
+
}
|
216
|
+
|
217
|
+
*out = entry->entry;
|
218
|
+
|
219
|
+
return 0;
|
220
|
+
}
|
221
|
+
|
222
|
+
void config_iterator_free(git_config_iterator *iter)
|
223
|
+
{
|
224
|
+
config_entries_iterator *it = (config_entries_iterator *) iter;
|
225
|
+
git_config_entries_free(it->entries);
|
226
|
+
git__free(it);
|
227
|
+
}
|
228
|
+
|
229
|
+
int config_iterator_next(
|
230
|
+
git_config_entry **entry,
|
231
|
+
git_config_iterator *iter)
|
232
|
+
{
|
233
|
+
config_entries_iterator *it = (config_entries_iterator *) iter;
|
234
|
+
|
235
|
+
if (!it->head)
|
236
|
+
return GIT_ITEROVER;
|
237
|
+
|
238
|
+
*entry = it->head->entry;
|
239
|
+
it->head = it->head->next;
|
240
|
+
|
241
|
+
return 0;
|
242
|
+
}
|
243
|
+
|
244
|
+
int git_config_entries_iterator_new(git_config_iterator **out, git_config_entries *entries)
|
245
|
+
{
|
246
|
+
config_entries_iterator *it;
|
247
|
+
|
248
|
+
it = git__calloc(1, sizeof(config_entries_iterator));
|
249
|
+
GIT_ERROR_CHECK_ALLOC(it);
|
250
|
+
it->parent.next = config_iterator_next;
|
251
|
+
it->parent.free = config_iterator_free;
|
252
|
+
it->head = entries->list;
|
253
|
+
it->entries = entries;
|
254
|
+
|
255
|
+
git_config_entries_incref(entries);
|
256
|
+
*out = &it->parent;
|
257
|
+
|
258
|
+
return 0;
|
259
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include "common.h"
|
9
|
+
|
10
|
+
#include "git2/sys/config.h"
|
11
|
+
#include "config.h"
|
12
|
+
|
13
|
+
typedef struct git_config_entries git_config_entries;
|
14
|
+
|
15
|
+
int git_config_entries_new(git_config_entries **out);
|
16
|
+
int git_config_entries_dup(git_config_entries **out, git_config_entries *entries);
|
17
|
+
void git_config_entries_incref(git_config_entries *entries);
|
18
|
+
void git_config_entries_free(git_config_entries *entries);
|
19
|
+
/* Add or append the new config option */
|
20
|
+
int git_config_entries_append(git_config_entries *entries, git_config_entry *entry);
|
21
|
+
int git_config_entries_get(git_config_entry **out, git_config_entries *entries, const char *key);
|
22
|
+
int git_config_entries_get_unique(git_config_entry **out, git_config_entries *entries, const char *key);
|
23
|
+
int git_config_entries_iterator_new(git_config_iterator **out, git_config_entries *entries);
|
@@ -5,9 +5,8 @@
|
|
5
5
|
* a Linking Exception. For full terms see the included COPYING file.
|
6
6
|
*/
|
7
7
|
|
8
|
-
#include "config_file.h"
|
9
|
-
|
10
8
|
#include "config.h"
|
9
|
+
|
11
10
|
#include "filebuf.h"
|
12
11
|
#include "sysdir.h"
|
13
12
|
#include "buffer.h"
|
@@ -18,74 +17,20 @@
|
|
18
17
|
#include "strmap.h"
|
19
18
|
#include "array.h"
|
20
19
|
#include "config_parse.h"
|
20
|
+
#include "config_entries.h"
|
21
21
|
|
22
22
|
#include <ctype.h>
|
23
23
|
#include <sys/types.h>
|
24
24
|
#include <regex.h>
|
25
25
|
|
26
|
-
typedef struct cvar_t {
|
27
|
-
struct cvar_t *next;
|
28
|
-
git_config_entry *entry;
|
29
|
-
bool included; /* whether this is part of [include] */
|
30
|
-
} cvar_t;
|
31
|
-
|
32
|
-
typedef struct git_config_file_iter {
|
33
|
-
git_config_iterator parent;
|
34
|
-
git_strmap_iter iter;
|
35
|
-
cvar_t* next_var;
|
36
|
-
} git_config_file_iter;
|
37
|
-
|
38
26
|
/* Max depth for [include] directives */
|
39
27
|
#define MAX_INCLUDE_DEPTH 10
|
40
28
|
|
41
|
-
#define CVAR_LIST_HEAD(list) ((list)->head)
|
42
|
-
|
43
|
-
#define CVAR_LIST_TAIL(list) ((list)->tail)
|
44
|
-
|
45
|
-
#define CVAR_LIST_NEXT(var) ((var)->next)
|
46
|
-
|
47
|
-
#define CVAR_LIST_EMPTY(list) ((list)->head == NULL)
|
48
|
-
|
49
|
-
#define CVAR_LIST_APPEND(list, var) do {\
|
50
|
-
if (CVAR_LIST_EMPTY(list)) {\
|
51
|
-
CVAR_LIST_HEAD(list) = CVAR_LIST_TAIL(list) = var;\
|
52
|
-
} else {\
|
53
|
-
CVAR_LIST_NEXT(CVAR_LIST_TAIL(list)) = var;\
|
54
|
-
CVAR_LIST_TAIL(list) = var;\
|
55
|
-
}\
|
56
|
-
} while(0)
|
57
|
-
|
58
|
-
#define CVAR_LIST_REMOVE_HEAD(list) do {\
|
59
|
-
CVAR_LIST_HEAD(list) = CVAR_LIST_NEXT(CVAR_LIST_HEAD(list));\
|
60
|
-
} while(0)
|
61
|
-
|
62
|
-
#define CVAR_LIST_REMOVE_AFTER(var) do {\
|
63
|
-
CVAR_LIST_NEXT(var) = CVAR_LIST_NEXT(CVAR_LIST_NEXT(var));\
|
64
|
-
} while(0)
|
65
|
-
|
66
|
-
#define CVAR_LIST_FOREACH(list, iter)\
|
67
|
-
for ((iter) = CVAR_LIST_HEAD(list);\
|
68
|
-
(iter) != NULL;\
|
69
|
-
(iter) = CVAR_LIST_NEXT(iter))
|
70
|
-
|
71
|
-
/*
|
72
|
-
* Inspired by the FreeBSD functions
|
73
|
-
*/
|
74
|
-
#define CVAR_LIST_FOREACH_SAFE(start, iter, tmp)\
|
75
|
-
for ((iter) = CVAR_LIST_HEAD(vars);\
|
76
|
-
(iter) && (((tmp) = CVAR_LIST_NEXT(iter) || 1));\
|
77
|
-
(iter) = (tmp))
|
78
|
-
|
79
|
-
typedef struct {
|
80
|
-
git_atomic refcount;
|
81
|
-
git_strmap *values;
|
82
|
-
} refcounted_strmap;
|
83
|
-
|
84
29
|
typedef struct {
|
85
30
|
git_config_backend parent;
|
86
31
|
/* mutex to coordinate accessing the values */
|
87
32
|
git_mutex values_mutex;
|
88
|
-
|
33
|
+
git_config_entries *entries;
|
89
34
|
const git_repository *repo;
|
90
35
|
git_config_level_t level;
|
91
36
|
} diskfile_header;
|
@@ -108,144 +53,46 @@ typedef struct {
|
|
108
53
|
diskfile_backend *snapshot_from;
|
109
54
|
} diskfile_readonly_backend;
|
110
55
|
|
111
|
-
|
56
|
+
typedef struct {
|
57
|
+
const git_repository *repo;
|
58
|
+
const char *file_path;
|
59
|
+
git_config_entries *entries;
|
60
|
+
git_config_level_t level;
|
61
|
+
unsigned int depth;
|
62
|
+
} diskfile_parse_state;
|
63
|
+
|
64
|
+
static int config_read(git_config_entries *entries, const git_repository *repo, git_config_file *file, git_config_level_t level, int depth);
|
112
65
|
static int config_write(diskfile_backend *cfg, const char *orig_key, const char *key, const regex_t *preg, const char *value);
|
113
66
|
static char *escape_value(const char *ptr);
|
114
67
|
|
115
|
-
int git_config_file__snapshot(git_config_backend **out, diskfile_backend *in);
|
116
68
|
static int config_snapshot(git_config_backend **out, git_config_backend *in);
|
117
69
|
|
118
70
|
static int config_error_readonly(void)
|
119
71
|
{
|
120
|
-
|
72
|
+
git_error_set(GIT_ERROR_CONFIG, "this backend is read-only");
|
121
73
|
return -1;
|
122
74
|
}
|
123
75
|
|
124
|
-
static void cvar_free(cvar_t *var)
|
125
|
-
{
|
126
|
-
if (var == NULL)
|
127
|
-
return;
|
128
|
-
|
129
|
-
git__free((char*)var->entry->name);
|
130
|
-
git__free((char *)var->entry->value);
|
131
|
-
git__free(var->entry);
|
132
|
-
git__free(var);
|
133
|
-
}
|
134
|
-
|
135
|
-
int git_config_file_normalize_section(char *start, char *end)
|
136
|
-
{
|
137
|
-
char *scan;
|
138
|
-
|
139
|
-
if (start == end)
|
140
|
-
return GIT_EINVALIDSPEC;
|
141
|
-
|
142
|
-
/* Validate and downcase range */
|
143
|
-
for (scan = start; *scan; ++scan) {
|
144
|
-
if (end && scan >= end)
|
145
|
-
break;
|
146
|
-
if (isalnum(*scan))
|
147
|
-
*scan = (char)git__tolower(*scan);
|
148
|
-
else if (*scan != '-' || scan == start)
|
149
|
-
return GIT_EINVALIDSPEC;
|
150
|
-
}
|
151
|
-
|
152
|
-
if (scan == start)
|
153
|
-
return GIT_EINVALIDSPEC;
|
154
|
-
|
155
|
-
return 0;
|
156
|
-
}
|
157
|
-
|
158
|
-
/* Add or append the new config option */
|
159
|
-
static int append_entry(git_strmap *values, cvar_t *var)
|
160
|
-
{
|
161
|
-
git_strmap_iter pos;
|
162
|
-
cvar_t *existing;
|
163
|
-
int error = 0;
|
164
|
-
|
165
|
-
pos = git_strmap_lookup_index(values, var->entry->name);
|
166
|
-
if (!git_strmap_valid_index(values, pos)) {
|
167
|
-
git_strmap_insert(values, var->entry->name, var, &error);
|
168
|
-
} else {
|
169
|
-
existing = git_strmap_value_at(values, pos);
|
170
|
-
while (existing->next != NULL) {
|
171
|
-
existing = existing->next;
|
172
|
-
}
|
173
|
-
existing->next = var;
|
174
|
-
}
|
175
|
-
|
176
|
-
if (error > 0)
|
177
|
-
error = 0;
|
178
|
-
|
179
|
-
return error;
|
180
|
-
}
|
181
|
-
|
182
|
-
static void free_vars(git_strmap *values)
|
183
|
-
{
|
184
|
-
cvar_t *var = NULL;
|
185
|
-
|
186
|
-
if (values == NULL)
|
187
|
-
return;
|
188
|
-
|
189
|
-
git_strmap_foreach_value(values, var,
|
190
|
-
while (var != NULL) {
|
191
|
-
cvar_t *next = CVAR_LIST_NEXT(var);
|
192
|
-
cvar_free(var);
|
193
|
-
var = next;
|
194
|
-
});
|
195
|
-
|
196
|
-
git_strmap_free(values);
|
197
|
-
}
|
198
|
-
|
199
|
-
static void refcounted_strmap_free(refcounted_strmap *map)
|
200
|
-
{
|
201
|
-
if (!map)
|
202
|
-
return;
|
203
|
-
|
204
|
-
if (git_atomic_dec(&map->refcount) != 0)
|
205
|
-
return;
|
206
|
-
|
207
|
-
free_vars(map->values);
|
208
|
-
git__free(map);
|
209
|
-
}
|
210
|
-
|
211
76
|
/**
|
212
77
|
* Take the current values map from the backend and increase its
|
213
78
|
* refcount. This is its own function to make sure we use the mutex to
|
214
79
|
* avoid the map pointer from changing under us.
|
215
80
|
*/
|
216
|
-
static
|
81
|
+
static git_config_entries *diskfile_entries_take(diskfile_header *h)
|
217
82
|
{
|
218
|
-
|
83
|
+
git_config_entries *entries;
|
219
84
|
|
220
85
|
if (git_mutex_lock(&h->values_mutex) < 0) {
|
221
|
-
|
86
|
+
git_error_set(GIT_ERROR_OS, "failed to lock config backend");
|
222
87
|
return NULL;
|
223
88
|
}
|
224
89
|
|
225
|
-
|
226
|
-
|
90
|
+
entries = h->entries;
|
91
|
+
git_config_entries_incref(entries);
|
227
92
|
|
228
93
|
git_mutex_unlock(&h->values_mutex);
|
229
94
|
|
230
|
-
return
|
231
|
-
}
|
232
|
-
|
233
|
-
static int refcounted_strmap_alloc(refcounted_strmap **out)
|
234
|
-
{
|
235
|
-
refcounted_strmap *map;
|
236
|
-
int error;
|
237
|
-
|
238
|
-
map = git__calloc(1, sizeof(refcounted_strmap));
|
239
|
-
GITERR_CHECK_ALLOC(map);
|
240
|
-
|
241
|
-
git_atomic_set(&map->refcount, 1);
|
242
|
-
|
243
|
-
if ((error = git_strmap_alloc(&map->values)) < 0)
|
244
|
-
git__free(map);
|
245
|
-
else
|
246
|
-
*out = map;
|
247
|
-
|
248
|
-
return error;
|
95
|
+
return entries;
|
249
96
|
}
|
250
97
|
|
251
98
|
static void config_file_clear(struct config_file *file)
|
@@ -272,15 +119,15 @@ static int config_open(git_config_backend *cfg, git_config_level_t level, const
|
|
272
119
|
b->header.level = level;
|
273
120
|
b->header.repo = repo;
|
274
121
|
|
275
|
-
if ((res =
|
122
|
+
if ((res = git_config_entries_new(&b->header.entries)) < 0)
|
276
123
|
return res;
|
277
124
|
|
278
125
|
if (!git_path_exists(b->file.path))
|
279
126
|
return 0;
|
280
127
|
|
281
|
-
if (res < 0 || (res = config_read(b->header.
|
282
|
-
|
283
|
-
b->header.
|
128
|
+
if (res < 0 || (res = config_read(b->header.entries, repo, &b->file, level, 0)) < 0) {
|
129
|
+
git_config_entries_free(b->header.entries);
|
130
|
+
b->header.entries = NULL;
|
284
131
|
}
|
285
132
|
|
286
133
|
return res;
|
@@ -313,7 +160,7 @@ static int config_is_modified(int *modified, struct config_file *file)
|
|
313
160
|
}
|
314
161
|
|
315
162
|
out:
|
316
|
-
|
163
|
+
git_buf_dispose(&buf);
|
317
164
|
|
318
165
|
return error;
|
319
166
|
}
|
@@ -321,7 +168,7 @@ out:
|
|
321
168
|
static int config_refresh(git_config_backend *cfg)
|
322
169
|
{
|
323
170
|
diskfile_backend *b = (diskfile_backend *)cfg;
|
324
|
-
|
171
|
+
git_config_entries *entries = NULL, *tmp;
|
325
172
|
git_config_file *include;
|
326
173
|
int error, modified;
|
327
174
|
uint32_t i;
|
@@ -336,7 +183,7 @@ static int config_refresh(git_config_backend *cfg)
|
|
336
183
|
if (!modified)
|
337
184
|
return 0;
|
338
185
|
|
339
|
-
if ((error =
|
186
|
+
if ((error = git_config_entries_new(&entries)) < 0)
|
340
187
|
goto out;
|
341
188
|
|
342
189
|
/* Reparse the current configuration */
|
@@ -345,22 +192,22 @@ static int config_refresh(git_config_backend *cfg)
|
|
345
192
|
}
|
346
193
|
git_array_clear(b->file.includes);
|
347
194
|
|
348
|
-
if ((error = config_read(
|
195
|
+
if ((error = config_read(entries, b->header.repo, &b->file, b->header.level, 0)) < 0)
|
349
196
|
goto out;
|
350
197
|
|
351
198
|
if ((error = git_mutex_lock(&b->header.values_mutex)) < 0) {
|
352
|
-
|
199
|
+
git_error_set(GIT_ERROR_OS, "failed to lock config backend");
|
353
200
|
goto out;
|
354
201
|
}
|
355
202
|
|
356
|
-
tmp = b->header.
|
357
|
-
b->header.
|
358
|
-
|
203
|
+
tmp = b->header.entries;
|
204
|
+
b->header.entries = entries;
|
205
|
+
entries = tmp;
|
359
206
|
|
360
207
|
git_mutex_unlock(&b->header.values_mutex);
|
361
208
|
|
362
209
|
out:
|
363
|
-
|
210
|
+
git_config_entries_free(entries);
|
364
211
|
|
365
212
|
return (error == GIT_ENOTFOUND) ? 0 : error;
|
366
213
|
}
|
@@ -373,149 +220,80 @@ static void backend_free(git_config_backend *_backend)
|
|
373
220
|
return;
|
374
221
|
|
375
222
|
config_file_clear(&backend->file);
|
376
|
-
|
223
|
+
git_config_entries_free(backend->header.entries);
|
377
224
|
git_mutex_free(&backend->header.values_mutex);
|
378
225
|
git__free(backend);
|
379
226
|
}
|
380
227
|
|
381
|
-
static void config_iterator_free(
|
382
|
-
git_config_iterator* iter)
|
383
|
-
{
|
384
|
-
iter->backend->free(iter->backend);
|
385
|
-
git__free(iter);
|
386
|
-
}
|
387
|
-
|
388
|
-
static int config_iterator_next(
|
389
|
-
git_config_entry **entry,
|
390
|
-
git_config_iterator *iter)
|
391
|
-
{
|
392
|
-
git_config_file_iter *it = (git_config_file_iter *) iter;
|
393
|
-
diskfile_header *h = (diskfile_header *) it->parent.backend;
|
394
|
-
git_strmap *values = h->values->values;
|
395
|
-
int err = 0;
|
396
|
-
cvar_t * var;
|
397
|
-
|
398
|
-
if (it->next_var == NULL) {
|
399
|
-
err = git_strmap_next((void**) &var, &(it->iter), values);
|
400
|
-
} else {
|
401
|
-
var = it->next_var;
|
402
|
-
}
|
403
|
-
|
404
|
-
if (err < 0) {
|
405
|
-
it->next_var = NULL;
|
406
|
-
return err;
|
407
|
-
}
|
408
|
-
|
409
|
-
*entry = var->entry;
|
410
|
-
it->next_var = CVAR_LIST_NEXT(var);
|
411
|
-
|
412
|
-
return 0;
|
413
|
-
}
|
414
|
-
|
415
228
|
static int config_iterator_new(
|
416
229
|
git_config_iterator **iter,
|
417
230
|
struct git_config_backend* backend)
|
418
231
|
{
|
419
|
-
diskfile_header *h;
|
420
|
-
git_config_file_iter *it;
|
421
|
-
git_config_backend *snapshot;
|
422
232
|
diskfile_header *bh = (diskfile_header *) backend;
|
233
|
+
git_config_entries *entries;
|
423
234
|
int error;
|
424
235
|
|
425
|
-
if ((error =
|
236
|
+
if ((error = git_config_entries_dup(&entries, bh->entries)) < 0)
|
426
237
|
return error;
|
427
238
|
|
428
|
-
if ((error =
|
429
|
-
|
430
|
-
|
431
|
-
it = git__calloc(1, sizeof(git_config_file_iter));
|
432
|
-
GITERR_CHECK_ALLOC(it);
|
433
|
-
|
434
|
-
h = (diskfile_header *)snapshot;
|
435
|
-
|
436
|
-
/* strmap_begin() is currently a macro returning 0 */
|
437
|
-
GIT_UNUSED(h);
|
438
|
-
|
439
|
-
it->parent.backend = snapshot;
|
440
|
-
it->iter = git_strmap_begin(h->values);
|
441
|
-
it->next_var = NULL;
|
442
|
-
|
443
|
-
it->parent.next = config_iterator_next;
|
444
|
-
it->parent.free = config_iterator_free;
|
445
|
-
*iter = (git_config_iterator *) it;
|
239
|
+
if ((error = git_config_entries_iterator_new(iter, entries)) < 0)
|
240
|
+
goto out;
|
446
241
|
|
447
|
-
|
242
|
+
out:
|
243
|
+
/* Let iterator delete duplicated entries when it's done */
|
244
|
+
git_config_entries_free(entries);
|
245
|
+
return error;
|
448
246
|
}
|
449
247
|
|
450
248
|
static int config_set(git_config_backend *cfg, const char *name, const char *value)
|
451
249
|
{
|
452
250
|
diskfile_backend *b = (diskfile_backend *)cfg;
|
453
|
-
|
454
|
-
|
251
|
+
git_config_entries *entries;
|
252
|
+
git_config_entry *existing;
|
455
253
|
char *key, *esc_value = NULL;
|
456
|
-
|
457
|
-
int rval, ret;
|
254
|
+
int error;
|
458
255
|
|
459
|
-
if ((
|
460
|
-
return
|
256
|
+
if ((error = git_config__normalize_name(name, &key)) < 0)
|
257
|
+
return error;
|
461
258
|
|
462
|
-
if ((
|
259
|
+
if ((entries = diskfile_entries_take(&b->header)) == NULL)
|
463
260
|
return -1;
|
464
|
-
values = map->values;
|
465
|
-
|
466
|
-
/*
|
467
|
-
* Try to find it in the existing values and update it if it
|
468
|
-
* only has one value.
|
469
|
-
*/
|
470
|
-
pos = git_strmap_lookup_index(values, key);
|
471
|
-
if (git_strmap_valid_index(values, pos)) {
|
472
|
-
cvar_t *existing = git_strmap_value_at(values, pos);
|
473
261
|
|
474
|
-
|
475
|
-
|
476
|
-
|
262
|
+
/* Check whether we'd be modifying an included or multivar key */
|
263
|
+
if ((error = git_config_entries_get_unique(&existing, entries, key)) < 0) {
|
264
|
+
if (error != GIT_ENOTFOUND)
|
477
265
|
goto out;
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
giterr_set(GITERR_CONFIG, "modifying included variable is not supported");
|
482
|
-
ret = -1;
|
483
|
-
goto out;
|
484
|
-
}
|
485
|
-
|
266
|
+
error = 0;
|
267
|
+
} else if ((!existing->value && !value) ||
|
268
|
+
(existing->value && value && !strcmp(existing->value, value))) {
|
486
269
|
/* don't update if old and new values already match */
|
487
|
-
|
488
|
-
|
489
|
-
!strcmp(existing->entry->value, value))) {
|
490
|
-
ret = 0;
|
491
|
-
goto out;
|
492
|
-
}
|
270
|
+
error = 0;
|
271
|
+
goto out;
|
493
272
|
}
|
494
273
|
|
495
274
|
/* No early returns due to sanity checks, let's write it out and refresh */
|
496
|
-
|
497
275
|
if (value) {
|
498
276
|
esc_value = escape_value(value);
|
499
|
-
|
277
|
+
GIT_ERROR_CHECK_ALLOC(esc_value);
|
500
278
|
}
|
501
279
|
|
502
|
-
if ((
|
280
|
+
if ((error = config_write(b, name, key, NULL, esc_value)) < 0)
|
503
281
|
goto out;
|
504
282
|
|
505
|
-
|
283
|
+
error = config_refresh(cfg);
|
506
284
|
|
507
285
|
out:
|
508
|
-
|
286
|
+
git_config_entries_free(entries);
|
509
287
|
git__free(esc_value);
|
510
288
|
git__free(key);
|
511
|
-
return
|
289
|
+
return error;
|
512
290
|
}
|
513
291
|
|
514
292
|
/* release the map containing the entry as an equivalent to freeing it */
|
515
|
-
static void
|
293
|
+
static void free_diskfile_entry(git_config_entry *entry)
|
516
294
|
{
|
517
|
-
|
518
|
-
|
295
|
+
git_config_entries *entries = (git_config_entries *) entry->payload;
|
296
|
+
git_config_entries_free(entries);
|
519
297
|
}
|
520
298
|
|
521
299
|
/*
|
@@ -524,36 +302,26 @@ static void release_map(git_config_entry *entry)
|
|
524
302
|
static int config_get(git_config_backend *cfg, const char *key, git_config_entry **out)
|
525
303
|
{
|
526
304
|
diskfile_header *h = (diskfile_header *)cfg;
|
527
|
-
|
528
|
-
|
529
|
-
khiter_t pos;
|
530
|
-
cvar_t *var;
|
305
|
+
git_config_entries *entries = NULL;
|
306
|
+
git_config_entry *entry;
|
531
307
|
int error = 0;
|
532
308
|
|
533
309
|
if (!h->parent.readonly && ((error = config_refresh(cfg)) < 0))
|
534
310
|
return error;
|
535
311
|
|
536
|
-
if ((
|
312
|
+
if ((entries = diskfile_entries_take(h)) == NULL)
|
537
313
|
return -1;
|
538
|
-
values = map->values;
|
539
|
-
|
540
|
-
pos = git_strmap_lookup_index(values, key);
|
541
314
|
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
return GIT_ENOTFOUND;
|
315
|
+
if ((error = (git_config_entries_get(&entry, entries, key))) < 0) {
|
316
|
+
git_config_entries_free(entries);
|
317
|
+
return error;
|
546
318
|
}
|
547
319
|
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
*out = var->entry;
|
553
|
-
(*out)->free = release_map;
|
554
|
-
(*out)->payload = map;
|
320
|
+
entry->free = free_diskfile_entry;
|
321
|
+
entry->payload = entries;
|
322
|
+
*out = entry;
|
555
323
|
|
556
|
-
return
|
324
|
+
return 0;
|
557
325
|
}
|
558
326
|
|
559
327
|
static int config_set_multivar(
|
@@ -571,7 +339,7 @@ static int config_set_multivar(
|
|
571
339
|
|
572
340
|
result = p_regcomp(&preg, regexp, REG_EXTENDED);
|
573
341
|
if (result != 0) {
|
574
|
-
|
342
|
+
git_error_set_regex(&preg, result);
|
575
343
|
result = -1;
|
576
344
|
goto out;
|
577
345
|
}
|
@@ -591,79 +359,62 @@ out:
|
|
591
359
|
|
592
360
|
static int config_delete(git_config_backend *cfg, const char *name)
|
593
361
|
{
|
594
|
-
cvar_t *var;
|
595
362
|
diskfile_backend *b = (diskfile_backend *)cfg;
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
if ((result = git_config__normalize_name(name, &key)) < 0)
|
602
|
-
return result;
|
603
|
-
|
604
|
-
if ((map = refcounted_strmap_take(&b->header)) == NULL)
|
605
|
-
return -1;
|
606
|
-
values = b->header.values->values;
|
607
|
-
|
608
|
-
pos = git_strmap_lookup_index(values, key);
|
609
|
-
git__free(key);
|
363
|
+
git_config_entries *entries = NULL;
|
364
|
+
git_config_entry *entry;
|
365
|
+
char *key = NULL;
|
366
|
+
int error;
|
610
367
|
|
611
|
-
if (
|
612
|
-
|
613
|
-
giterr_set(GITERR_CONFIG, "could not find key '%s' to delete", name);
|
614
|
-
return GIT_ENOTFOUND;
|
615
|
-
}
|
368
|
+
if ((error = git_config__normalize_name(name, &key)) < 0)
|
369
|
+
goto out;
|
616
370
|
|
617
|
-
|
618
|
-
|
371
|
+
if ((entries = diskfile_entries_take(&b->header)) == NULL)
|
372
|
+
goto out;
|
619
373
|
|
620
|
-
|
621
|
-
|
622
|
-
|
374
|
+
/* Check whether we'd be modifying an included or multivar key */
|
375
|
+
if ((error = git_config_entries_get_unique(&entry, entries, key)) < 0) {
|
376
|
+
if (error == GIT_ENOTFOUND)
|
377
|
+
git_error_set(GIT_ERROR_CONFIG, "could not find key '%s' to delete", name);
|
378
|
+
goto out;
|
623
379
|
}
|
624
380
|
|
625
|
-
if (
|
626
|
-
|
627
|
-
return -1;
|
628
|
-
}
|
381
|
+
if ((error = config_write(b, name, entry->name, NULL, NULL)) < 0)
|
382
|
+
goto out;
|
629
383
|
|
630
|
-
if ((
|
631
|
-
|
384
|
+
if ((error = config_refresh(cfg)) < 0)
|
385
|
+
goto out;
|
632
386
|
|
633
|
-
|
387
|
+
out:
|
388
|
+
git_config_entries_free(entries);
|
389
|
+
git__free(key);
|
390
|
+
return error;
|
634
391
|
}
|
635
392
|
|
636
393
|
static int config_delete_multivar(git_config_backend *cfg, const char *name, const char *regexp)
|
637
394
|
{
|
638
395
|
diskfile_backend *b = (diskfile_backend *)cfg;
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
396
|
+
git_config_entries *entries = NULL;
|
397
|
+
git_config_entry *entry = NULL;
|
398
|
+
regex_t preg = { 0 };
|
399
|
+
char *key = NULL;
|
643
400
|
int result;
|
644
|
-
khiter_t pos;
|
645
401
|
|
646
402
|
if ((result = git_config__normalize_name(name, &key)) < 0)
|
647
|
-
|
648
|
-
|
649
|
-
if ((map = refcounted_strmap_take(&b->header)) == NULL)
|
650
|
-
return -1;
|
651
|
-
values = b->header.values->values;
|
652
|
-
|
653
|
-
pos = git_strmap_lookup_index(values, key);
|
403
|
+
goto out;
|
654
404
|
|
655
|
-
if (
|
656
|
-
|
657
|
-
|
658
|
-
giterr_set(GITERR_CONFIG, "could not find key '%s' to delete", name);
|
659
|
-
return GIT_ENOTFOUND;
|
405
|
+
if ((entries = diskfile_entries_take(&b->header)) == NULL) {
|
406
|
+
result = -1;
|
407
|
+
goto out;
|
660
408
|
}
|
661
409
|
|
662
|
-
|
410
|
+
if ((result = git_config_entries_get(&entry, entries, key)) < 0) {
|
411
|
+
if (result == GIT_ENOTFOUND)
|
412
|
+
git_error_set(GIT_ERROR_CONFIG, "could not find key '%s' to delete", name);
|
413
|
+
goto out;
|
414
|
+
}
|
663
415
|
|
664
|
-
result = p_regcomp(&preg, regexp, REG_EXTENDED)
|
665
|
-
|
666
|
-
giterr_set_regex(&preg, result);
|
416
|
+
if ((result = p_regcomp(&preg, regexp, REG_EXTENDED)) != 0) {
|
417
|
+
git_error_set_regex(&preg, result);
|
667
418
|
result = -1;
|
668
419
|
goto out;
|
669
420
|
}
|
@@ -671,21 +422,16 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
|
|
671
422
|
if ((result = config_write(b, name, key, &preg, NULL)) < 0)
|
672
423
|
goto out;
|
673
424
|
|
674
|
-
result = config_refresh(cfg)
|
425
|
+
if ((result = config_refresh(cfg)) < 0)
|
426
|
+
goto out;
|
675
427
|
|
676
428
|
out:
|
429
|
+
git_config_entries_free(entries);
|
677
430
|
git__free(key);
|
678
431
|
regfree(&preg);
|
679
432
|
return result;
|
680
433
|
}
|
681
434
|
|
682
|
-
static int config_snapshot(git_config_backend **out, git_config_backend *in)
|
683
|
-
{
|
684
|
-
diskfile_backend *b = (diskfile_backend *) in;
|
685
|
-
|
686
|
-
return git_config_file__snapshot(out, b);
|
687
|
-
}
|
688
|
-
|
689
435
|
static int config_lock(git_config_backend *_cfg)
|
690
436
|
{
|
691
437
|
diskfile_backend *cfg = (diskfile_backend *) _cfg;
|
@@ -716,24 +462,24 @@ static int config_unlock(git_config_backend *_cfg, int success)
|
|
716
462
|
}
|
717
463
|
|
718
464
|
git_filebuf_cleanup(&cfg->locked_buf);
|
719
|
-
|
465
|
+
git_buf_dispose(&cfg->locked_content);
|
720
466
|
cfg->locked = false;
|
721
467
|
|
722
468
|
return error;
|
723
469
|
}
|
724
470
|
|
725
|
-
int
|
471
|
+
int git_config_backend_from_file(git_config_backend **out, const char *path)
|
726
472
|
{
|
727
473
|
diskfile_backend *backend;
|
728
474
|
|
729
475
|
backend = git__calloc(1, sizeof(diskfile_backend));
|
730
|
-
|
476
|
+
GIT_ERROR_CHECK_ALLOC(backend);
|
731
477
|
|
732
478
|
backend->header.parent.version = GIT_CONFIG_BACKEND_VERSION;
|
733
479
|
git_mutex_init(&backend->header.values_mutex);
|
734
480
|
|
735
481
|
backend->file.path = git__strdup(path);
|
736
|
-
|
482
|
+
GIT_ERROR_CHECK_ALLOC(backend->file.path);
|
737
483
|
git_array_init(backend->file.includes);
|
738
484
|
|
739
485
|
backend->header.parent.open = config_open;
|
@@ -812,7 +558,7 @@ static void backend_readonly_free(git_config_backend *_backend)
|
|
812
558
|
if (backend == NULL)
|
813
559
|
return;
|
814
560
|
|
815
|
-
|
561
|
+
git_config_entries_free(backend->header.entries);
|
816
562
|
git_mutex_free(&backend->header.values_mutex);
|
817
563
|
git__free(backend);
|
818
564
|
}
|
@@ -822,7 +568,7 @@ static int config_readonly_open(git_config_backend *cfg, git_config_level_t leve
|
|
822
568
|
diskfile_readonly_backend *b = (diskfile_readonly_backend *) cfg;
|
823
569
|
diskfile_backend *src = b->snapshot_from;
|
824
570
|
diskfile_header *src_header = &src->header;
|
825
|
-
|
571
|
+
git_config_entries *entries;
|
826
572
|
int error;
|
827
573
|
|
828
574
|
if (!src_header->parent.readonly && (error = config_refresh(&src_header->parent)) < 0)
|
@@ -832,24 +578,24 @@ static int config_readonly_open(git_config_backend *cfg, git_config_level_t leve
|
|
832
578
|
GIT_UNUSED(level);
|
833
579
|
GIT_UNUSED(repo);
|
834
580
|
|
835
|
-
if ((
|
581
|
+
if ((entries = diskfile_entries_take(src_header)) == NULL)
|
836
582
|
return -1;
|
837
|
-
b->header.
|
583
|
+
b->header.entries = entries;
|
838
584
|
|
839
585
|
return 0;
|
840
586
|
}
|
841
587
|
|
842
|
-
int
|
588
|
+
static int config_snapshot(git_config_backend **out, git_config_backend *in)
|
843
589
|
{
|
844
590
|
diskfile_readonly_backend *backend;
|
845
591
|
|
846
592
|
backend = git__calloc(1, sizeof(diskfile_readonly_backend));
|
847
|
-
|
593
|
+
GIT_ERROR_CHECK_ALLOC(backend);
|
848
594
|
|
849
595
|
backend->header.parent.version = GIT_CONFIG_BACKEND_VERSION;
|
850
596
|
git_mutex_init(&backend->header.values_mutex);
|
851
597
|
|
852
|
-
backend->snapshot_from = in;
|
598
|
+
backend->snapshot_from = (diskfile_backend *) in;
|
853
599
|
|
854
600
|
backend->header.parent.readonly = 1;
|
855
601
|
backend->header.parent.version = GIT_CONFIG_BACKEND_VERSION;
|
@@ -904,24 +650,14 @@ static char *escape_value(const char *ptr)
|
|
904
650
|
ptr++;
|
905
651
|
}
|
906
652
|
|
907
|
-
if (git_buf_oom(&buf))
|
908
|
-
git_buf_free(&buf);
|
653
|
+
if (git_buf_oom(&buf))
|
909
654
|
return NULL;
|
910
|
-
}
|
911
655
|
|
912
656
|
return git_buf_detach(&buf);
|
913
657
|
}
|
914
658
|
|
915
|
-
struct parse_data {
|
916
|
-
const git_repository *repo;
|
917
|
-
const char *file_path;
|
918
|
-
git_strmap *values;
|
919
|
-
git_config_level_t level;
|
920
|
-
int depth;
|
921
|
-
};
|
922
|
-
|
923
659
|
static int parse_include(git_config_parser *reader,
|
924
|
-
|
660
|
+
diskfile_parse_state *parse_data, const char *file)
|
925
661
|
{
|
926
662
|
struct config_file *include;
|
927
663
|
git_buf path = GIT_BUF_INIT;
|
@@ -946,11 +682,11 @@ static int parse_include(git_config_parser *reader,
|
|
946
682
|
git_array_init(include->includes);
|
947
683
|
include->path = git_buf_detach(&path);
|
948
684
|
|
949
|
-
result = config_read(parse_data->
|
685
|
+
result = config_read(parse_data->entries, parse_data->repo,
|
950
686
|
include, parse_data->level, parse_data->depth+1);
|
951
687
|
|
952
688
|
if (result == GIT_ENOTFOUND) {
|
953
|
-
|
689
|
+
git_error_clear();
|
954
690
|
result = 0;
|
955
691
|
}
|
956
692
|
|
@@ -995,7 +731,7 @@ static int do_match_gitdir(
|
|
995
731
|
*matches = (error == 0);
|
996
732
|
|
997
733
|
out:
|
998
|
-
|
734
|
+
git_buf_dispose(&path);
|
999
735
|
return error;
|
1000
736
|
}
|
1001
737
|
|
@@ -1026,7 +762,7 @@ static const struct {
|
|
1026
762
|
};
|
1027
763
|
|
1028
764
|
static int parse_conditional_include(git_config_parser *reader,
|
1029
|
-
|
765
|
+
diskfile_parse_state *parse_data, const char *section, const char *file)
|
1030
766
|
{
|
1031
767
|
char *condition;
|
1032
768
|
size_t i;
|
@@ -1061,15 +797,16 @@ static int parse_conditional_include(git_config_parser *reader,
|
|
1061
797
|
static int read_on_variable(
|
1062
798
|
git_config_parser *reader,
|
1063
799
|
const char *current_section,
|
1064
|
-
char *var_name,
|
1065
|
-
char *var_value,
|
800
|
+
const char *var_name,
|
801
|
+
const char *var_value,
|
1066
802
|
const char *line,
|
1067
803
|
size_t line_len,
|
1068
804
|
void *data)
|
1069
805
|
{
|
1070
|
-
|
806
|
+
diskfile_parse_state *parse_data = (diskfile_parse_state *)data;
|
1071
807
|
git_buf buf = GIT_BUF_INIT;
|
1072
|
-
|
808
|
+
git_config_entry *entry;
|
809
|
+
const char *c;
|
1073
810
|
int result = 0;
|
1074
811
|
|
1075
812
|
GIT_UNUSED(line);
|
@@ -1083,56 +820,50 @@ static int read_on_variable(
|
|
1083
820
|
git_buf_puts(&buf, current_section);
|
1084
821
|
git_buf_putc(&buf, '.');
|
1085
822
|
}
|
1086
|
-
git__strtolower(var_name);
|
1087
|
-
git_buf_puts(&buf, var_name);
|
1088
|
-
git__free(var_name);
|
1089
823
|
|
1090
|
-
|
1091
|
-
|
1092
|
-
return -1;
|
1093
|
-
}
|
824
|
+
for (c = var_name; *c; c++)
|
825
|
+
git_buf_putc(&buf, git__tolower(*c));
|
1094
826
|
|
1095
|
-
|
1096
|
-
|
1097
|
-
var->entry = git__calloc(1, sizeof(git_config_entry));
|
1098
|
-
GITERR_CHECK_ALLOC(var->entry);
|
827
|
+
if (git_buf_oom(&buf))
|
828
|
+
return -1;
|
1099
829
|
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
830
|
+
entry = git__calloc(1, sizeof(git_config_entry));
|
831
|
+
GIT_ERROR_CHECK_ALLOC(entry);
|
832
|
+
entry->name = git_buf_detach(&buf);
|
833
|
+
entry->value = var_value ? git__strdup(var_value) : NULL;
|
834
|
+
entry->level = parse_data->level;
|
835
|
+
entry->include_depth = parse_data->depth;
|
1104
836
|
|
1105
|
-
if ((result =
|
837
|
+
if ((result = git_config_entries_append(parse_data->entries, entry)) < 0)
|
1106
838
|
return result;
|
1107
839
|
|
1108
840
|
result = 0;
|
1109
841
|
|
1110
842
|
/* Add or append the new config option */
|
1111
|
-
if (!git__strcmp(
|
1112
|
-
result = parse_include(reader, parse_data,
|
1113
|
-
else if (!git__prefixcmp(
|
1114
|
-
!git__suffixcmp(
|
843
|
+
if (!git__strcmp(entry->name, "include.path"))
|
844
|
+
result = parse_include(reader, parse_data, entry->value);
|
845
|
+
else if (!git__prefixcmp(entry->name, "includeif.") &&
|
846
|
+
!git__suffixcmp(entry->name, ".path"))
|
1115
847
|
result = parse_conditional_include(reader, parse_data,
|
1116
|
-
|
1117
|
-
|
848
|
+
entry->name, entry->value);
|
1118
849
|
|
1119
850
|
return result;
|
1120
851
|
}
|
1121
852
|
|
1122
853
|
static int config_read(
|
1123
|
-
|
854
|
+
git_config_entries *entries,
|
1124
855
|
const git_repository *repo,
|
1125
856
|
git_config_file *file,
|
1126
857
|
git_config_level_t level,
|
1127
858
|
int depth)
|
1128
859
|
{
|
1129
|
-
|
860
|
+
diskfile_parse_state parse_data;
|
1130
861
|
git_config_parser reader;
|
1131
862
|
git_buf contents = GIT_BUF_INIT;
|
1132
863
|
int error;
|
1133
864
|
|
1134
865
|
if (depth >= MAX_INCLUDE_DEPTH) {
|
1135
|
-
|
866
|
+
git_error_set(GIT_ERROR_CONFIG, "maximum config include depth reached");
|
1136
867
|
return -1;
|
1137
868
|
}
|
1138
869
|
|
@@ -1154,14 +885,14 @@ static int config_read(
|
|
1154
885
|
|
1155
886
|
parse_data.repo = repo;
|
1156
887
|
parse_data.file_path = file->path;
|
1157
|
-
parse_data.
|
888
|
+
parse_data.entries = entries;
|
1158
889
|
parse_data.level = level;
|
1159
890
|
parse_data.depth = depth;
|
1160
891
|
|
1161
892
|
error = git_config_parse(&reader, NULL, read_on_variable, NULL, NULL, &parse_data);
|
1162
893
|
|
1163
894
|
out:
|
1164
|
-
|
895
|
+
git_buf_dispose(&contents);
|
1165
896
|
return error;
|
1166
897
|
}
|
1167
898
|
|
@@ -1180,7 +911,7 @@ static int write_section(git_buf *fbuf, const char *key)
|
|
1180
911
|
char *escaped;
|
1181
912
|
git_buf_put(&buf, key, dot - key);
|
1182
913
|
escaped = escape_value(dot + 1);
|
1183
|
-
|
914
|
+
GIT_ERROR_CHECK_ALLOC(escaped);
|
1184
915
|
git_buf_printf(&buf, " \"%s\"", escaped);
|
1185
916
|
git__free(escaped);
|
1186
917
|
}
|
@@ -1190,7 +921,7 @@ static int write_section(git_buf *fbuf, const char *key)
|
|
1190
921
|
return -1;
|
1191
922
|
|
1192
923
|
result = git_buf_put(fbuf, git_buf_cstr(&buf), buf.size);
|
1193
|
-
|
924
|
+
git_buf_dispose(&buf);
|
1194
925
|
|
1195
926
|
return result;
|
1196
927
|
}
|
@@ -1299,8 +1030,8 @@ static int write_on_section(
|
|
1299
1030
|
static int write_on_variable(
|
1300
1031
|
git_config_parser *reader,
|
1301
1032
|
const char *current_section,
|
1302
|
-
char *var_name,
|
1303
|
-
char *var_value,
|
1033
|
+
const char *var_name,
|
1034
|
+
const char *var_value,
|
1304
1035
|
const char *line,
|
1305
1036
|
size_t line_len,
|
1306
1037
|
void *data)
|
@@ -1329,9 +1060,6 @@ static int write_on_variable(
|
|
1329
1060
|
if (has_matched && write_data->preg != NULL)
|
1330
1061
|
has_matched = (regexec(write_data->preg, var_value, 0, NULL, 0) == 0);
|
1331
1062
|
|
1332
|
-
git__free(var_name);
|
1333
|
-
git__free(var_value);
|
1334
|
-
|
1335
1063
|
/* If this isn't the name/value we're looking for, simply dump the
|
1336
1064
|
* existing data back out and continue on.
|
1337
1065
|
*/
|
@@ -1409,7 +1137,7 @@ static int config_write(diskfile_backend *cfg, const char *orig_key, const char
|
|
1409
1137
|
/* Lock the file */
|
1410
1138
|
if ((result = git_filebuf_open(
|
1411
1139
|
&file, cfg->file.path, GIT_FILEBUF_HASH_CONTENTS, GIT_CONFIG_FILE_MODE)) < 0) {
|
1412
|
-
|
1140
|
+
git_buf_dispose(&contents);
|
1413
1141
|
return result;
|
1414
1142
|
}
|
1415
1143
|
|
@@ -1428,12 +1156,12 @@ static int config_write(diskfile_backend *cfg, const char *orig_key, const char
|
|
1428
1156
|
ldot = strrchr(key, '.');
|
1429
1157
|
name = ldot + 1;
|
1430
1158
|
section = git__strndup(key, ldot - key);
|
1431
|
-
|
1159
|
+
GIT_ERROR_CHECK_ALLOC(section);
|
1432
1160
|
|
1433
1161
|
ldot = strrchr(orig_key, '.');
|
1434
1162
|
orig_name = ldot + 1;
|
1435
1163
|
orig_section = git__strndup(orig_key, ldot - orig_key);
|
1436
|
-
|
1164
|
+
GIT_ERROR_CHECK_ALLOC(orig_section);
|
1437
1165
|
|
1438
1166
|
write_data.buf = &buf;
|
1439
1167
|
git_buf_init(&write_data.buffered_comment, 0);
|
@@ -1454,7 +1182,7 @@ static int config_write(diskfile_backend *cfg, const char *orig_key, const char
|
|
1454
1182
|
&write_data);
|
1455
1183
|
git__free(section);
|
1456
1184
|
git__free(orig_section);
|
1457
|
-
|
1185
|
+
git_buf_dispose(&write_data.buffered_comment);
|
1458
1186
|
|
1459
1187
|
if (result < 0) {
|
1460
1188
|
git_filebuf_cleanup(&file);
|
@@ -1464,7 +1192,7 @@ static int config_write(diskfile_backend *cfg, const char *orig_key, const char
|
|
1464
1192
|
if (cfg->locked) {
|
1465
1193
|
size_t len = buf.asize;
|
1466
1194
|
/* Update our copy with the modified contents */
|
1467
|
-
|
1195
|
+
git_buf_dispose(&cfg->locked_content);
|
1468
1196
|
git_buf_attach(&cfg->locked_content, git_buf_detach(&buf), len);
|
1469
1197
|
} else {
|
1470
1198
|
git_filebuf_write(&file, git_buf_cstr(&buf), git_buf_len(&buf));
|
@@ -1472,8 +1200,8 @@ static int config_write(diskfile_backend *cfg, const char *orig_key, const char
|
|
1472
1200
|
}
|
1473
1201
|
|
1474
1202
|
done:
|
1475
|
-
|
1476
|
-
|
1203
|
+
git_buf_dispose(&buf);
|
1204
|
+
git_buf_dispose(&contents);
|
1477
1205
|
git_parse_ctx_clear(&reader.ctx);
|
1478
1206
|
return result;
|
1479
1207
|
}
|