summaryrefslogtreecommitdiff
path: root/src/config.c
Commit message (Collapse)AuthorAgeFilesLines
* 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
|/
* Fix git_submodule_sync and add new config helperRussell Belfer2014-04-011-0/+30
| | | | | | | | | | | | This fixes `git_submodule_sync` to correctly update the remote URL of the default branch of the submodule along with the URL in the parent repository config (i.e. match core Git's behavior). Also move some useful helper logic from the submodule code into a shared config API `git_config__update_entry` that can either set or delete an entry with constraints like not overwriting or not creating a new entry. I used that helper to update a couple other places in the code.
* Added function-based initializers for every options struct.Matthew Bowen2014-03-051-0/+12
| | | | The basic structure of each function is courtesy of arrbee.
* Move system directory cache out of utilsEdward Thomson2014-02-241-5/+5
|
* config: use git_buf for returning pathsCarlos Martín Nieto2014-01-271-46/+6
| | | | Again, we already did this internally, so simply remove the conversions.
* Merge pull request #2059 from linquize/git_config_get_crashEdward Thomson2014-01-181-0/+1
|\ | | | | Fix segfault when calling git_config_get_* functions when a config fails to load
| * Fix segfault when calling git_config_get_* functions when a config fails to loadLinquize2014-01-181-0/+1
| | | | | | | | Reinitialize the result code of get_entry() to GIT_ENOTFOUND
* | Fix a memory leak in `git_config_iterator_glob_new`.Arthur Schreiber2014-01-131-0/+1
| |
* | config: handle NULL pointers passed to git_config_iterator_free()Brodie Rao2014-01-121-0/+3
|/ | | | Signed-off-by: Brodie Rao <brodie@sf.io>
* One more rename/cleanup for callback err functionsRussell Belfer2013-12-111-3/+3
|
* Further callback error check style fixesRussell Belfer2013-12-111-6/+12
| | | | | Okay, I've decided I like the readability of this style much better so I used it everywhere.
* Remove converting user error to GIT_EUSERRussell Belfer2013-12-111-27/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes the behavior of callbacks so that the callback error code is not converted into GIT_EUSER and instead we propagate the return value through to the caller. Instead of using the giterr_capture and giterr_restore functions, we now rely on all functions to pass back the return value from a callback. To avoid having a return value with no error message, the user can call the public giterr_set_str or some such function to set an error message. There is a new helper 'giterr_set_callback' that functions can invoke after making a callback which ensures that some error message was set in case the callback did not set one. In places where the sign of the callback return value is meaningful (e.g. positive to skip, negative to abort), only the negative values are returned back to the caller, obviously, since the other values allow for continuing the loop. The hardest parts of this were in the checkout code where positive return values were overloaded as meaningful values for checkout. I fixed this by adding an output parameter to many of the internal checkout functions and removing the overload. This added some code, but it is probably a better implementation. There is some funkiness in the network code where user provided callbacks could be returning a positive or a negative value and we want to rely on that to cancel the loop. There are still a couple places where an user error might get turned into GIT_EUSER there, I think, though none exercised by the tests.
* Improve GIT_EUSER handlingRussell Belfer2013-12-111-16/+13
| | | | | | | | | | | This adds giterr_user_cancel to return GIT_EUSER and clear any error message that is sitting around. As a result of using that in places, we need to be more thorough with capturing errors that happen inside a callback when used internally. To help with that, this also adds giterr_capture and giterr_restore so that when we internally use a foreach-type function that clears errors and converts them to GIT_EUSER, it is easier to restore not just the return value, but the actual error message text.