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 * License: GPL-2.0(Linking Exception) 9 */ 10 module libgit2.sys.config; 11 12 13 private static import libgit2.config; 14 private static import libgit2.types; 15 private import libgit2.common: GIT_EXTERN; 16 17 /* 18 * @file git2/sys/config.h 19 * @brief Git config backend routines 20 * @defgroup git_backend Git custom backend APIs 21 * @ingroup Git 22 * @{ 23 */ 24 extern (C): 25 nothrow @nogc: 26 27 /** 28 * Every iterator must have this struct as its first element, so the 29 * API can talk to it. You'd define your iterator as 30 * 31 * struct my_iterator { 32 * .git_config_iterator parent; 33 * ... 34 * } 35 * 36 * and assign `iter->parent.backend` to your `git_config_backend`. 37 */ 38 struct git_config_iterator 39 { 40 .git_config_backend* backend; 41 uint flags; 42 43 /** 44 * Return the current entry and advance the iterator. The 45 * memory belongs to the library. 46 */ 47 int function(libgit2.config.git_config_entry** entry, .git_config_iterator* iter) next; 48 49 /** 50 * Free the iterator 51 */ 52 void function(.git_config_iterator* iter) free; 53 } 54 55 /** 56 * Generic backend that implements the interface to 57 * access a configuration file 58 */ 59 struct git_config_backend 60 { 61 uint version_; 62 63 /** 64 * True if this backend is for a snapshot 65 */ 66 int readonly; 67 68 libgit2.types.git_config* cfg; 69 70 /* Open means open the file/database and parse if necessary */ 71 int function(.git_config_backend*, libgit2.config.git_config_level_t level, const (libgit2.types.git_repository)* repo) open; 72 int function(.git_config_backend*, const (char)* key, libgit2.config.git_config_entry** entry) get; 73 int function(.git_config_backend*, const (char)* key, const (char)* value) set; 74 int function(.git_config_backend* cfg, const (char)* name, const (char)* regexp, const (char)* value) set_multivar; 75 int function(.git_config_backend*, const (char)* key) del; 76 int function(.git_config_backend*, const (char)* key, const (char)* regexp) del_multivar; 77 int function(.git_config_iterator**, .git_config_backend*) iterator; 78 79 /** 80 * Produce a read-only version of this backend 81 */ 82 int function(.git_config_backend**, .git_config_backend*) snapshot; 83 84 /** 85 * Lock this backend. 86 * 87 * Prevent any writes to the data store backing this 88 * backend. Any updates must not be visible to any other 89 * readers. 90 */ 91 int function(.git_config_backend*) lock; 92 93 /** 94 * Unlock the data store backing this backend. If success is 95 * true, the changes should be committed, otherwise rolled 96 * back. 97 */ 98 int function(.git_config_backend*, int success) unlock; 99 100 void function(.git_config_backend*) free; 101 } 102 103 enum GIT_CONFIG_BACKEND_VERSION = 1; 104 105 pragma(inline, true) 106 pure nothrow @safe @nogc @live 107 .git_config_backend GIT_CONFIG_BACKEND_INIT() 108 109 do 110 { 111 .git_config_backend OUTPUT = 112 { 113 version_: .GIT_CONFIG_BACKEND_VERSION, 114 }; 115 116 return OUTPUT; 117 } 118 119 /** 120 * Initializes a `git_config_backend` with default values. Equivalent to 121 * creating an instance with GIT_CONFIG_BACKEND_INIT. 122 * 123 * Params: 124 * backend = the `git_config_backend` struct to initialize. 125 * version_ = Version of struct; pass `GIT_CONFIG_BACKEND_VERSION` 126 * 127 * Returns: Zero on success; -1 on failure. 128 */ 129 @GIT_EXTERN 130 int git_config_init_backend(.git_config_backend* backend, uint version_); 131 132 /** 133 * Add a generic config file instance to an existing config 134 * 135 * Note that the configuration object will free the file 136 * automatically. 137 * 138 * Further queries on this config object will access each 139 * of the config file instances in order (instances with 140 * a higher priority level will be accessed first). 141 * 142 * Params: 143 * cfg = the configuration to add the file to 144 * file = the configuration file (backend) to add 145 * level = the priority level of the backend 146 * repo = optional repository to allow parsing of conditional includes 147 * force = if a config file already exists for the given priority level, replace it 148 * 149 * Returns: 0 on success, git_error_code.GIT_EEXISTS when adding more than one file for a given priority level (and force_replace set to 0), or error code 150 */ 151 @GIT_EXTERN 152 int git_config_add_backend(libgit2.types.git_config* cfg, .git_config_backend* file, libgit2.config.git_config_level_t level, const (libgit2.types.git_repository)* repo, int force); 153 154 /* @} */