summaryrefslogtreecommitdiff
path: root/src/config.c
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Add config read fns with controlled error behaviorRussell Belfer2013-12-111-67/+114
| | | | | | | | | | | | | | | | | | | | | | | | This adds `git_config__lookup_entry` which will look up a key in a config and return either the entry or NULL if the key was not present. Optionally, it can either suppress all errors or can return them (although not finding the key is not an error for this function). Unlike other accessors, this does not normalize the config key string, so it must only be used when the key is known to be in normalized form (i.e. all lower-case before the first dot and after the last dot, with no invalid characters). This also adds three high-level helper functions to look up config values with no errors and a fallback value. The three functions are for string, bool, and int values, and will resort to the fallback value for any error that arises. They are: * `git_config__get_string_force` * `git_config__get_bool_force` * `git_config__get_int_force` None of them normalize the config `key` either, so they can only be used for internal cases where the key is known to be in normal format.
* Fix saving remotes with several fetch/push ref specs.Daniel Rodríguez Troitiño2013-11-011-0/+13
| | | | | | | | | | | | | | | | | | | | | | At some moment git_config_delete_entry lost the ability to delete one entry of a multivar configuration. The moment you had more than one fetch or push ref spec for a remote you will not be able to save that remote anymore. The changes in network::remote::remotes::save show that problem. I needed to create a new git_config_delete_multivar because I was not able to remove one or several entries of a multivar config with the current API. Several tries modifying how git_config_set_multivar(..., NULL) behaved were not successful. git_config_delete_multivar is very similar to git_config_set_multivar, and delegates into config_delete_multivar of config_file. This function search for the cvar_t that will be deleted, storing them in a temporal array, and rebuilding the linked list. After calling config_write to delete the entries, the cvar_t stored in the temporal array are freed. There is a little fix in config_write, it avoids an infinite loop when using a regular expression (case for the multivars). This error was found by the test network::remote::remotes::tagopt.
* config: don't special-case the multivar iteratorCarlos Martín Nieto2013-08-141-49/+74
| | | | | Build it on top of the normal iterator instead, which lets use re-use a lot of code.
* config: deduplicate iterator creationCarlos Martín Nieto2013-08-121-12/+9
| | | | | When the glob iterator is passed NULL regexp, call the non-globbing iterator so we don't have to special-case which functions to call.
* config: handle empty backends when iteratingCarlos Martín Nieto2013-08-121-1/+6
|
* config: implement _foreach and _foreach_match on top of the iterator directlyCarlos Martín Nieto2013-08-121-11/+20
| | | | | | Use a glob iterator instead of going through git_config_backend_foreach_match. This function is left as it's exposed in the API.
* config: introduce a regex-filtering iteratorCarlos Martín Nieto2013-08-121-0/+61
|
* config: introduce _iterator_new()Carlos Martín Nieto2013-08-121-29/+94
| | | | As the name suggests, it iterates over all the entries
* config: fix leaks in the iteratorsCarlos Martín Nieto2013-08-081-0/+8
|
* config: add _next() and _iterator_free()Carlos Martín Nieto2013-08-081-0/+10
| | | | Make it look like the refs iterator API.
* config: working multivar iteratorCarlos Martín Nieto2013-08-081-34/+57
| | | | Implement the foreach version as a wrapper around the iterator.
* config: hopefully get the iterator to work on multivarsCarlos Martín Nieto2013-08-081-5/+76
|
* config: initial multivar iteratorCarlos Martín Nieto2013-08-081-0/+18
|
* config: move next() and free() into the iteratorCarlos Martín Nieto2013-08-081-4/+4
| | | | | Like we have in the references iterator, next and free belong in the iterator itself.
* config: get_multivar -> get_multivar_foreachCarlos Martín Nieto2013-08-081-2/+2
| | | | | The plain function will return an iterator, so move this one out of the way.
* config: saner iterator errorsCarlos Martín Nieto2013-08-081-2/+4
| | | | | Really report an error in foreach if we fail to allocate the iterator, and don't fail if the config is emtpy.
* Don't typedef a pointerCarlos Martín Nieto2013-08-081-2/+2
| | | | Make the iterator structure opaque and make sure it compiles.
* replaced foreach() with non callback based iterations in git_config_backendNico von Geyso2013-08-081-1/+45
| | | | | | | | | new functions in struct git_config_backend: * iterator_new(...) * iterator_free(...) * next(...) The old callback based foreach style can still be used with `git_config_backend_foreach_match`
* A little git_config_get_multivar code cleanupRussell Belfer2013-07-091-11/+5
|
* Fix return value in git_config_get_multivarJ. David Ibáñez2013-07-091-3/+10
| | | | | | | | If there is not an error, the return value was always the return value of the last call to file->get_multivar With this commit GIT_ENOTFOUND is only returned if all the calls to filge-get_multivar return GIT_ENOTFOUND.