summaryrefslogtreecommitdiff
path: root/src/config.c
Commit message (Collapse)AuthorAgeFilesLines
* path: separate git-specific path functions from utilEdward Thomson2021-11-091-1/+1
| | | | | | Introduce `git_fs_path`, which operates on generic filesystem paths. `git_path` will be kept for only git-specific path functionality (for example, checking for `.git` in a path).
* str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstrEdward Thomson2021-10-171-67/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | libgit2 has two distinct requirements that were previously solved by `git_buf`. We require: 1. A general purpose string class that provides a number of utility APIs for manipulating data (eg, concatenating, truncating, etc). 2. A structure that we can use to return strings to callers that they can take ownership of. By using a single class (`git_buf`) for both of these purposes, we have confused the API to the point that refactorings are difficult and reasoning about correctness is also difficult. Move the utility class `git_buf` to be called `git_str`: this represents its general purpose, as an internal string buffer class. The name also is an homage to Junio Hamano ("gitstr"). The public API remains `git_buf`, and has a much smaller footprint. It is generally only used as an "out" param with strict requirements that follow the documentation. (Exceptions exist for some legacy APIs to avoid breaking callers unnecessarily.) Utility functions exist to convert a user-specified `git_buf` to a `git_str` so that we can call internal functions, then converting it back again.
* Fix coding style for pointerpunkymaniac2021-09-091-1/+1
| | | | Make some syntax change to follow coding style.
* buf: remove internal `git_buf_text` namespaceEdward Thomson2021-05-111-2/+1
| | | | | The `git_buf_text` namespace is unnecessary and strange. Remove it, just keep the functions prefixed with `git_buf`.
* config: use GIT_ASSERTEdward Thomson2020-11-271-7/+12
|
* buffer: git_buf_sanitize should return a valueEdward Thomson2020-11-251-6/+24
| | | | | | `git_buf_sanitize` is called with user-input, and wants to sanity-check that input. Allow it to return a value if the input was malformed in a way that we cannot cope.
* Support empty values for git_config_get_mapped and git_config_lookup_map_valueSven Strickroth2020-09-091-5/+1
| | | | Signed-off-by: Sven Strickroth <email@cs-ware.de>
* Fix parsing boolean config values when using git_config_get_mapped and ↵Sven Strickroth2020-09-091-1/+1
| | | | | | git_config_lookup_map_value Signed-off-by: Sven Strickroth <email@cs-ware.de>
* tree-wide: mark local functions as staticPatrick Steinhardt2020-06-091-1/+1
| | | | | | | We've accumulated quite some functions which are never used outside of their respective code unit, but which are lacking the `static` keyword. Add it to reduce their linkage scope and allow the compiler to optimize better.
* global: convert all users of POSIX regex to use our new regexp APIPatrick Steinhardt2019-09-211-26/+17
| | | | | The old POSIX regex API has been superseded by our new regexp API. Convert all users to make use of the new one.
* config: validate ownership of C:\ProgramData\Git\config before using itJohannes Schindelin2019-08-131-1/+8
| | | | | | | | | | | | | | | | When the VirtualStore feature is in effect, it is safe to let random users write into C:\ProgramData because other users won't see those files. This seemed to be the case when we introduced support for C:\ProgramData\Git\config. However, when that feature is not in effect (which seems to be the case in newer Windows 10 versions), we'd rather not use those files unless they come from a trusted source, such as an administrator. This change imitates the strategy chosen by PowerShell's native OpenSSH port to Windows regarding host key files: if a system file is owned neither by an administrator, a system account, or the current user, it is ignored.
* configuration: cvar -> configmapPatrick Steinhardt2019-07-181-14/+14
| | | | | `cvar` is an unhelpful name. Refactor its usage to `configmap` for more clarity.
* regexec: prefix all regexec function calls with p_Edward Thomson2019-05-191-14/+14
| | | | | | | Prefix all the calls to the the regexec family of functions with `p_`. This allows us to swap out all the regular expression functions with our own implementation. Move the declarations to `posix_regex.h` for simpler inclusion.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-35/+35
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* config: assert that our parameters are validEtienne Samson2019-01-041-0/+2
| | | CID 1395011
* config: fix adding files if their parent directory is a filePatrick Steinhardt2018-11-281-1/+1
| | | | | | | | | | | | | When we try to add a configuration file with `git_config_add_file_ondisk`, we treat nonexisting files as empty. We do this by performing a stat call, ignoring ENOENT errors. This works just fine in case the file or any of its parents simply does not exist, but there is also the case where any of the parent directories is not a directory, but a file. So e.g. trying to add a configuration file "/dev/null/.gitconfig" will fail, as `errno` will be ENOTDIR instead of ENOENT. Catch ENOTDIR in addition to ENOENT to fix the issue. Add a test that verifies we are able to add configuration files with such an invalid path file just fine.
* config: add asserts for non-null parameters in lock/unlockEtienne Samson2018-11-021-0/+4
|
* config: remove last instance of `git__strntol64`Patrick Steinhardt2018-10-181-1/+1
| | | | | | | | | When parsing integers from configuration values, we use `git__strtol64`. This is fine to do, as we always sanitize values and can thus be sure that they'll have a terminating `NUL` byte. But as this is the last call-site of `git__strtol64`, let's just pass in the length explicitly by calling `strlen` on the value to be able to remove `git__strtol64` altogether.
* config: rename "config_file.h" to "config_backend.h"Patrick Steinhardt2018-09-281-2/+2
| | | | | | | | | | The header "config_file.h" has a list of inline-functions to access the contents of a config backend without directly messing with the struct's function pointers. While all these functions are called "git_config_file_*", they are in fact completely backend-agnostic and don't care whether it is a file or not. Rename all the function to instead be backend-agnostic versions called "git_config_backend_*" and rename the header to match.
* config: move function normalizing section names into "config.c"Patrick Steinhardt2018-09-281-4/+27
| | | | | | The function `git_config_file_normalize_section` is never being used in any file different than "config.c", but it is implemented in "config_file.c". Move it over and make the symbol static.
* config: make names backend-agnosticPatrick Steinhardt2018-09-281-36/+36
| | | | | | As a last step to make variables and structures more backend agnostic for our `git_config` structure, rename local variables to not be called `file` anymore.
* config: rename `file_internal` and its `file` memberPatrick Steinhardt2018-09-211-42/+42
| | | | | | | Same as with the previous commit, the `file_internal` struct is used to keep track of all the backends that are added to a `git_config` struct. Rename it to `backend_internal` and rename its `file` member to `backend` to make the implementation more backend-agnostic.
* config: rename `files` vector to `backends`Patrick Steinhardt2018-09-211-28/+28
| | | | | | | | | | | | | | Originally, the `git_config` struct is a collection of all the parsed configuration files from different scopes (system-wide config, user-specific config as well as the repo-specific config files). Historically, we didn't and don't yet have any other configuration backends than the one for files, which is why the field holding the config backends is called `files`. But in fact, nothing dictates that the vector of backends actually holds file backends only, as they are generic and custom backends can be implemented by users. Rename the member to be called `backends` to clarify that there is nothing specific to files here.
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-3/+3
|
* config: pass repository when opening config filesPatrick Steinhardt2017-10-091-8/+10
| | | | | | | | | | | | | | | | | Our current configuration logic is completely oblivious of any repository, but only cares for actual file paths. Unfortunately, we are forced to break this assumption by the introduction of conditional includes, which are evaluated in the context of a repository. Right now, only one conditional exists with "gitdir:" -- it will only include the configuration if the current repository's git directory matches the value passed to "gitdir:". To support these conditionals, we have to break our API and make the repository available when opening a configuration file. This commit extends the `open` call of configuration backends to include another repository and adjusts existing code to have it available. This includes the user-visible functions `git_config_add_file_ondisk` and `git_config_add_backend`.
* Make sure to always include "common.h" firstPatrick Steinhardt2017-07-031-2/+2
| | | | | | | | | | | | | | | | | | | | | | Next to including several files, our "common.h" header also declares various macros which are then used throughout the project. As such, we have to make sure to always include this file first in all implementation files. Otherwise, we might encounter problems or even silent behavioural differences due to macros or defines not being defined as they should be. So in fact, our header and implementation files should make sure to always include "common.h" first. This commit does so by establishing a common include pattern. Header files inside of "src" will now always include "common.h" as its first other file, separated by a newline from all the other includes to make it stand out as special. There are two cases for the implementation files. If they do have a matching header file, they will always include this one first, leading to "common.h" being transitively included as first file. If they do not have a matching header file, they instead include "common.h" as first file themselves. This fixes the outlined problems and will become our standard practice for header and source files inside of the "src/" from now on.
* Merge pull request #4179 from libgit2/ethomson/expand_tildeCarlos Martín Nieto2017-05-201-13/+1
|\ | | | | Introduce home directory expansion function for config files, attribute files
| * config: expand paths with `git_sysdir_expand...`ethomson/expand_tildeEdward Thomson2017-03-231-13/+1
| |
* | config: skip r/o backends when writingPatrick Steinhardt2017-04-261-22/+41
|/ | | | | | | | | | | | Configuration backends have a readonly-flag which is currently used to distinguish configuration snapshots. But somewhat unexpectedly, we do not use the flag to prevent writing to a readonly backend but happily proceed to do so. This commit modifies logic to also honor the readonly flag for configuration setters. We will now traverse through all backends and pick the first one which is not marked as read-only whenever we want to write new configuration.
* giterr_set: consistent error messagesEdward Thomson2016-12-291-12/+12
| | | | | | | | Error messages should be sentence fragments, and therefore: 1. Should not begin with a capital letter, 2. Should not conclude with punctuation, and 3. Should not end a sentence and begin a new one
* Make sure we use the `C` locale for `regcomp` on macOS.Arthur Schreiber2016-10-061-3/+3
|
* config: add a ProgramData levelcmn/programdata-configCarlos Martín Nieto2015-10-211-0/+10
| | | | | This is where portable git stores the global configuration which we can use to adhere to it even though git isn't quite installed on the system.
* Fix build warning: implicit declaration of function ↵Leo Yang2015-08-171-0/+1
| | | | ‘git_transaction_config_new’
* config: perform unlocking via git_transactioncmn/config-txCarlos Martín Nieto2015-08-121-2/+6
| | | | | This makes the API for commiting or discarding changes the same as for references.
* config: expose locking via the main APICarlos Martín Nieto2015-08-121-0/+31
| | | | | | | | | This lock/unlock pair allows for the cller to lock a configuration file to avoid concurrent operations. It also allows for a transactional approach to updating a configuration file. If multiple updates must be made atomically, they can be done while the config is locked.
* config: provide a function to reverse-lookup mapped cvarsCarlos Martín Nieto2015-06-221-0/+20
|
* Do not call regfree() on an empty regex that is not successfully created by ↵Yong Li2015-04-291-3/+2
| | | | | | regcomp (also removed an unused member "has_regex" from all_iter)
* Fix checking of return value for regcomp.Patrick Steinhardt2015-04-101-3/+3
| | | | | | | | The regcomp function returns a non-zero value if compilation of a regular expression fails. In most places we only check for negative values, but positive values indicate an error, as well. Fix this tree-wide, fixing a segmentation fault when calling git_config_iterator_glob_new with an invalid regexp.
* config: borrow refcounted referencescmn/config-borrow-entryCarlos Martín Nieto2015-03-031-21/+98
| | | | | | | | | | | | | | | This changes the get_entry() method to return a refcounted version of the config entry, which you have to free when you're done. This allows us to avoid freeing the memory in which the entry is stored on a refresh, which may happen at any time for a live config. For this reason, get_string() has been forbidden on live configs and a new function get_string_buf() has been added, which stores the string in a git_buf which the user then owns. The functions which parse the string value takea advantage of the borrowing to parse safely and then release the entry.
* config: add parsing and getter for pathscmn/config-get-pathCarlos Martín Nieto2015-01-141-0/+41
|
* config: remove the refresh function and backend fieldcmn/config-refresh-removeCarlos Martín Nieto2014-10-231-17/+0
| | | | | | We have been refreshing on read and write for a while now, so git_config_refresh() is at best a no-op, and might just end up wasting cycles.
* config: initialize the errorCarlos Martín Nieto2014-05-301-1/+1
| | | | | The error would be uninitialized if we take a snapshot of a config with no backends.
* Some coverity inspired cleanupsRussell Belfer2014-05-131-6/+6
|
* Merge pull request #2334 from libgit2/rb/fix-2333Russell Belfer2014-05-121-0/+3
|\ | | | | Be more careful with user-supplied buffers
| * Be more careful with user-supplied buffersrb/fix-2333Russell Belfer2014-05-081-0/+3
| | | | | | | | | | | | | | | | | | | | | | This adds in missing calls to `git_buf_sanitize` and fixes a number of places where `git_buf` APIs could inadvertently write NUL terminator bytes into invalid buffers. This also changes the behavior of `git_buf_sanitize` to NUL terminate a buffer if it can and of `git_buf_shorten` to do nothing if it can. Adds tests of filtering code with zeroed (i.e. unsanitized) buffer which was previously triggering a segfault.
* | Merge pull request #2188 from libgit2/cmn/config-snapshotRussell Belfer2014-05-121-0/+32
|\ \ | |/ |/| Configuration snapshotting
| * config: implement config snapshottingCarlos Martín Nieto2014-04-181-0/+32
| | | | | | | | | | | | | | | | | | | | | | In order to have consistent views of the config files for remotes, submodules et al. and a configuration that represents what is currently stored on-disk, we need a way to provide a view of the configuration that does not change. The goal here is to provide the snapshotting part by creating a read-only copy of the state of the configuration at a particular point in time, which does not change when a repository's main config changes.
* | Improve handling of fake home directoryRussell Belfer2014-05-021-10/+8
| | | | | | | | | | | | | | | | | | | | There are a few tests that set up a fake home directory and a fake GLOBAL search path so that we can test things in global ignore or attribute or config files. This cleans up that code to work more robustly even if there is a test failure. This also fixes some valgrind warnings where scanning search paths for separators could end up doing a little bit of sketchy data access when coming to the end of search list.
* | Fix remaining init_options inconsistenciesRussell Belfer2014-05-021-9/+4
| | | | | | | | | | There were a couple of "init_opts()" functions a few more cases of structure initialization that I somehow missed.
* | Check for NULL before passing it to vsnprintfJacques Germishuys2014-04-301-2/+2
|/