src/config.c


Log

Author Commit Date CI Message
Leo Yang 26ea28f3 2015-08-17T15:18:47 Fix build warning: implicit declaration of function ‘git_transaction_config_new’
Carlos Martín Nieto 5340d63d 2015-07-12T12:50:23 config: perform unlocking via git_transaction This makes the API for commiting or discarding changes the same as for references.
Carlos Martín Nieto 36f784b5 2015-06-01T20:02:23 config: expose locking via the main API 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.
Carlos Martín Nieto 15c38103 2015-05-09T11:22:27 config: provide a function to reverse-lookup mapped cvars
Yong Li e30438cc 2015-04-29T13:40:42 Do not call regfree() on an empty regex that is not successfully created by regcomp (also removed an unused member "has_regex" from all_iter)
Patrick Steinhardt 129022ee 2015-04-10T09:36:38 Fix checking of return value for regcomp. 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.
Carlos Martín Nieto 9a97f49e 2014-12-21T15:31:03 config: borrow refcounted references 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.
Carlos Martín Nieto eac773d9 2015-01-14T15:05:43 config: add parsing and getter for paths
Carlos Martín Nieto 55cb4999 2014-10-23T19:05:02 config: remove the refresh function and backend field 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.
Carlos Martín Nieto 5f0527ae 2014-05-30T13:06:34 config: initialize the error The error would be uninitialized if we take a snapshot of a config with no backends.
Russell Belfer a37aa82e 2014-05-13T15:54:23 Some coverity inspired cleanups
Russell Belfer af567e88 2014-05-12T10:44:13 Merge pull request #2334 from libgit2/rb/fix-2333 Be more careful with user-supplied buffers
Russell Belfer d2c4d1c6 2014-05-12T10:04:52 Merge pull request #2188 from libgit2/cmn/config-snapshot Configuration snapshotting
Russell Belfer 1e4976cb 2014-05-08T10:17:14 Be more careful with user-supplied buffers 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.
Russell Belfer 0f603132 2014-05-01T14:47:33 Improve handling of fake home directory 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.
Russell Belfer bc91347b 2014-04-30T11:16:31 Fix remaining init_options inconsistencies There were a couple of "init_opts()" functions a few more cases of structure initialization that I somehow missed.
Jacques Germishuys 183aa4f8 2014-04-30T17:46:53 Check for NULL before passing it to vsnprintf
Carlos Martín Nieto 55ebd7d3 2014-03-13T17:11:34 config: implement config snapshotting 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.
Russell Belfer 8286300a 2013-12-18T11:48:57 Fix git_submodule_sync and add new config helper 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.
Matthew Bowen b9f81997 2014-03-05T21:49:23 Added function-based initializers for every options struct. The basic structure of each function is courtesy of arrbee.
Edward Thomson 83634d38 2014-02-24T17:43:10 Move system directory cache out of utils
Carlos Martín Nieto ee550477 2014-01-26T16:11:18 config: use git_buf for returning paths Again, we already did this internally, so simply remove the conversions.
Edward Thomson b97e55f2 2014-01-18T14:48:59 Merge pull request #2059 from linquize/git_config_get_crash Fix segfault when calling git_config_get_* functions when a config fails to load
Linquize c24130e0 2014-01-18T22:58:31 Fix segfault when calling git_config_get_* functions when a config fails to load Reinitialize the result code of get_entry() to GIT_ENOTFOUND
Arthur Schreiber 1234738e 2014-01-13T22:12:02 Fix a memory leak in `git_config_iterator_glob_new`.
Brodie Rao e3c6a1bf 2014-01-12T23:30:06 config: handle NULL pointers passed to git_config_iterator_free() Signed-off-by: Brodie Rao <brodie@sf.io>
Russell Belfer 26c1cb91 2013-12-09T09:44:03 One more rename/cleanup for callback err functions
Russell Belfer f10d7a36 2013-12-06T15:53:26 Further callback error check style fixes Okay, I've decided I like the readability of this style much better so I used it everywhere.
Russell Belfer 25e0b157 2013-12-06T15:07:57 Remove converting user error to GIT_EUSER 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.
Russell Belfer 96869a4e 2013-12-03T16:45:39 Improve GIT_EUSER handling 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.
Russell Belfer 9f77b3f6 2013-11-25T14:21:34 Add config read fns with controlled error behavior 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.
Daniel Rodríguez Troitiño 3793fa9b 2013-10-31T01:08:50 Fix saving remotes with several fetch/push ref specs. 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.
Carlos Martín Nieto f4be8209 2013-08-14T00:45:05 config: don't special-case the multivar iterator Build it on top of the normal iterator instead, which lets use re-use a lot of code.
Carlos Martín Nieto 86c02614 2013-08-09T11:05:02 config: deduplicate iterator creation 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.
Carlos Martín Nieto d8289b9f 2013-08-09T11:03:13 config: handle empty backends when iterating
Carlos Martín Nieto d8488b98 2013-08-09T10:37:35 config: implement _foreach and _foreach_match on top of the iterator directly Use a glob iterator instead of going through git_config_backend_foreach_match. This function is left as it's exposed in the API.
Carlos Martín Nieto 54f3a572 2013-08-09T10:29:11 config: introduce a regex-filtering iterator
Carlos Martín Nieto 5880962d 2013-08-09T09:05:19 config: introduce _iterator_new() As the name suggests, it iterates over all the entries
Carlos Martín Nieto a319ffae 2013-08-08T21:00:33 config: fix leaks in the iterators
Carlos Martín Nieto 1e96c9d5 2013-08-08T20:47:06 config: add _next() and _iterator_free() Make it look like the refs iterator API.
Carlos Martín Nieto 99dfb538 2013-08-08T17:57:59 config: working multivar iterator Implement the foreach version as a wrapper around the iterator.
Carlos Martín Nieto cca5df63 2013-08-08T16:59:39 config: hopefully get the iterator to work on multivars
Carlos Martín Nieto 3a7ffc29 2013-08-08T16:18:07 config: initial multivar iterator
Carlos Martín Nieto eba73992 2013-08-08T14:39:32 config: move next() and free() into the iterator Like we have in the references iterator, next and free belong in the iterator itself.
Carlos Martín Nieto 4efa3290 2013-08-08T13:41:18 config: get_multivar -> get_multivar_foreach The plain function will return an iterator, so move this one out of the way.
Carlos Martín Nieto 84fec6f6 2013-08-08T13:14:35 config: saner iterator errors Really report an error in foreach if we fail to allocate the iterator, and don't fail if the config is emtpy.
Carlos Martín Nieto 4d588d97 2013-08-08T11:24:47 Don't typedef a pointer Make the iterator structure opaque and make sure it compiles.
Nico von Geyso a603c191 2013-03-18T21:02:36 replaced foreach() with non callback based iterations in git_config_backend 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`
Russell Belfer e4fda954 2013-07-09T16:46:18 A little git_config_get_multivar code cleanup
J. David Ibáñez 07fba63e 2013-07-06T23:51:40 Fix return value in git_config_get_multivar 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.
Russell Belfer 37f66e82 2013-06-12T15:21:21 Fix Windows warnings This fixes problems with missing function prototypes and 64-bit data issues on Windows.
Vicent Marti 6de9b2ee 2013-06-12T21:10:33 util: It's called `memzero`
Vicent Marti eb58e2d0 2013-06-12T21:05:48 Merge remote-tracking branch 'arrbee/minor-paranoia' into development
Russell Belfer 3e9e6cda 2013-06-07T09:54:33 Add safe memset and use it This adds a `git__memset` routine that will not be optimized away and updates the places where I memset() right before a free() call to use it.
Russell Belfer f658dc43 2013-05-31T14:09:58 Zero memory for major objects before freeing By zeroing out the memory when we free larger objects (i.e. those that serve as collections of other data, such as repos, odb, refdb), I'm hoping that it will be easier for libgit2 bindings to find errors in their object management code.
Russell Belfer 16adc9fa 2013-05-24T10:35:58 Typedef git_config_level_t and use it everywhere The GIT_CONFIG_LEVEL constants actually work well as an enum because they are mutually exclusive, so this adds a typedef to the enum and uses that everywhere that one of these constants are expected, instead of the old code that typically used an unsigned int.
Russell Belfer 0700ca1a 2013-05-23T16:11:53 More config code checks and cleanups
Russell Belfer 3b32b6d3 2013-05-23T09:19:42 More tests of config with various absent files Plus a bit of extra paranoia to ensure config object has valid contents.
Linquize 0cb16fe9 2013-05-15T20:26:55 Unify whitespaces to tabs
Carlos Martín Nieto 5d831887 2013-05-07T00:10:02 config: convenience function to open global/xdg The rules for which one to open is a bit silly, so let's make it easier for our users.
Carlos Martín Nieto a4b75dcf 2013-05-06T21:51:25 repo: unconditionally create a global config backend When a repository is initialised, we need to probe to see if there is a global config to load. If this is not the case, the user isn't able to write to the global config without creating the backend and adding it themselves, which is inconvenient and overly complex. Unconditionally create and add a backend for the global config file regardless of whether it exists as a convenience for users. To enable this, we allow creating backends to files that do not exist yet, changing the semantics somewhat, and making some tests invalid.
Russell Belfer 3f663178 2013-05-01T13:38:56 More care catching and setting config errors
Russell Belfer 0a1755c0 2013-04-30T03:15:45 Catch issue in config set with no config file This prevents a segfault when setting a value in the config of a repository that doesn't have a config file.
Russell Belfer 6be368bf 2013-04-22T16:24:53 Clear repo config cache when cfgs are set This is a conservative change, but it seemed like the only safe thing to do -- i.e. clear the cvar cache when a config gets set.
Russell Belfer ab01cbd4 2013-04-22T14:24:12 Add configs to repo config cache This adds a bunch of additional config values to the repository config value cache and makes it easier to add a simple boolean config without creating enum values for each possible setting. Also, this fixes a bug in git_config_refresh where the config cache was not being cleared which could lead to potential incorrect values. The work to start using the new cached configs will come in the next couple of commits...
Russell Belfer 83041c71 2013-04-19T11:52:04 Move git_config_backend to include/git2/sys Moving backend implementor objects into include/git2/sys so the APIs can be isolated from the ones that normal libgit2 users would be likely to use.
Vicent Martí 5b27bf7e 2013-03-18T16:17:14 Merge pull request #1417 from arrbee/opts-for-paths Implement opts interface for global/system file search paths
Russell Belfer 41954a49 2013-03-18T14:19:35 Switch search paths to classic delimited strings This switches the APIs for setting and getting the global/system search paths from using git_strarray to using a simple string with GIT_PATH_LIST_SEPARATOR delimited paths, just as the environment PATH variable would contain. This makes it simpler to get and set the value. I also added code to expand "$PATH" when setting a new value to embed the old value of the path. This means that I no longer require separate actions to PREPEND to the value.
Vicent Martí 50eb8520 2013-03-18T14:05:31 Merge pull request #1420 from KindDragon/static-code-analyzer-warnings Several warnings detected by static code analyzer fixed
Arkadiy Shapkin 10c06114 2013-03-17T04:46:46 Several warnings detected by static code analyzer fixed Implicit type conversion argument of function to size_t type Suspicious sequence of types castings: size_t -> int -> size_t Consider reviewing the expression of the 'A = B == C' kind. The expression is calculated as following: 'A = (B == C)' Unsigned type is never < 0
Russell Belfer 5540d947 2013-03-15T16:39:00 Implement global/system file search paths The goal of this work is to expose the search logic for "global", "system", and "xdg" files through the git_libgit2_opts() interface. Behind the scenes, I changed the logic for finding files to have a notion of a git_strarray that represents a search path and to store a separate search path for each of the three tiers of config file. For each tier, I implemented a function to initialize it to default values (generally based on environment variables), and then general interfaces to get it, set it, reset it, and prepend new directories to it. Next, I exposed these interfaces through the git_libgit2_opts interface, reusing the GIT_CONFIG_LEVEL_SYSTEM, etc., constants for the user to control which search path they were modifying. There are alternative designs for the opts interface / argument ordering, so I'm putting this phase out for discussion. Additionally, I ended up doing a little bit of clean up regarding attr.h and attr_file.h, adding a new attrcache.h so the other two files wouldn't have to be included in so many places.
Carlos Martín Nieto 48bde2f1 2013-03-08T02:11:34 config: don't allow passing NULL as a value to set Passing NULL is non-sensical. The error message leaves to be desired, though, as it leaks internal implementation details. Catch it at the `git_config_set_string` level and set an appropriate error message.
Russell Belfer 487fc724 2013-03-01T13:41:53 Allow empty config object and use it This removes assertions that prevent us from having an empty git_config object and then updates some tests that were dependent on global config state to use an empty config before running anything.
Russell Belfer 1e7799e8 2013-01-29T12:15:18 Implement config key validation rules This is a new implementation of core git's config key checking rules that prevents non-alphanumeric characters (and '-') for the top-level section and key names inside of config files. This also validates the target section name when renaming sections.
Edward Thomson 359fc2d2 2013-01-08T17:07:25 update copyrights
Ben Straub c7231c45 2012-11-30T16:31:42 Deploy GITERR_CHECK_VERSION
Ben Straub 69177621 2012-11-29T14:07:50 Deploy git_config_backend version
Russell Belfer 7bf87ab6 2012-11-28T09:58:48 Consolidate text buffer functions There are many scattered functions that look into the contents of buffers to do various text manipulations (such as escaping or unescaping data, calculating text stats, guessing if content is binary, etc). This groups all those functions together into a new file and converts the code to use that. This has two enhancements to existing functionality. The old text stats function is significantly rewritten and the BOM detection code was extended (although largely we can't deal with anything other than a UTF8 BOM).
Ben Straub 54b2a37a 2012-11-20T16:02:25 Clean up config.h
Russell Belfer cc6b4162 2012-11-20T10:24:18 It is okay to not have a .gitconfig file Opening a repo is generating an error if you don't have a .gitconfig file in your home directory, but that should be legal.
nulltoken 270160b9 2012-11-17T13:39:24 config: Opening a nonexistent file returns ENOTFOUND
Michael Schubert 0ec11828 2012-11-16T02:17:57 Fix -Wmaybe-uninitialized warning
Carlos Martín Nieto 6132a54e 2012-11-13T16:13:10 Fix a few valgrind errors
Carlos Martín Nieto 0da81d2b 2012-11-13T14:43:23 config: return an emtpy string when there is no value Returning NULL for the string when we haven't signaled an error condition is counter-intuitive and causes unnecessary edge cases. Return an empty string when asking for a string value for a configuration variable such as '[section] var' to avoid these edge cases. If the distinction between no value and an empty value is needed, this can be retrieved from the entry directly. As a side-effect, this change stops the int parsing functions from segfaulting on such a variable.
Carlos Martín Nieto 3ee078c0 2012-11-13T13:46:17 config: rename get_config_entry -> config_entry We're already in the git_config namespace, there is no need to repeat it.
nulltoken 55f9837f 2012-11-09T21:49:50 config: make git_config_open_level() work with an empty config
Russell Belfer 744cc03e 2012-10-30T12:10:36 Add git_config_refresh() API to reload config This adds a new API that allows users to reload the config if the file has changed on disk. A new config callback function to refresh the config was added. The modified time and file size are used to test if the file needs to be reloaded (and are now stored in the disk backend object). In writing tests, just using mtime was a problem / race, so I wanted to check file size as well. To support that, I extended `git_futils_readbuffer_updated` to optionally check file size in addition to mtime, and I added a new function `git_filebuf_stats` to fetch the mtime and size for an open filebuf (so that the config could be easily refreshed after a write). Lastly, I moved some similar file checking code for attributes into filebuf. It is still only being used for attrs, but it seems potentially reusable, so I thought I'd move it over.
Russell Belfer 1b934689 2012-10-25T10:55:03 Merge pull request #925 from nulltoken/topic/moving-branch-updates-config Updates config upon moving and deletion of branches
Vicent Marti 505f37b4 2012-10-25T19:22:35 config: Only dereference value on success
nulltoken aba70781 2012-09-11T18:11:26 config: introduce git_config_rename_section()
yorah a1abe66a 2012-09-10T12:11:02 Add config level support in the config API Added `struct git_config_entry`: a git_config_entry contains the key, the value, and the config file level from which a config element was found. Added `git_config_open_level`: build a single-level focused config object from a multi-level one. We are now storing `git_config_entry`s in the khash of the config_file
Sven Strickroth 4258d483 2012-10-02T17:21:07 Rename xdr to xdg Signed-off-by: Sven Strickroth <email@cs-ware.de>
Sven Strickroth c378a118 2012-09-25T00:11:53 git_config_open_default: Honour xdr config Signed-off-by: Sven Strickroth <email@cs-ware.de>
Sven Strickroth d7940ac3 2012-09-25T00:09:44 Fixed missing method Signed-off-by: Sven Strickroth <email@cs-ware.de>
Sven Strickroth 8b4f9b17 2012-09-24T18:59:00 Correctly read xdr compatible %HOME%/.config/git/config config file This file is not just read if the global config file (%HOME%/.gitconfig) is not found, however, it is used everytime but with lower priority. Signed-off-by: Sven Strickroth <email@cs-ware.de>
Russell Belfer 7fbca880 2012-08-24T14:32:45 Support new config locations As of git v1.7.12, $HOME/.config/git/ is supported as a new location for "config", "attributes", and "ignore" files.
Russell Belfer 85bd1746 2012-08-22T16:03:35 Some cleanup suggested during review This cleans up a number of items suggested during code review with @vmg, including: * renaming "outside repo" config API to `git_config_open_default` * killing the `git_config_open_global` API * removing the `git_` prefix from the static functions in fileops * removing some unnecessary functionality from the "cp" command
Russell Belfer ca1b6e54 2012-07-31T17:02:54 Add template dir and set gid to repo init This extends git_repository_init_ext further with support for initializing the repository from an external template directory and with support for the "create shared" type flags that make a set GID repository directory. This also adds tests for much of the new functionality to the existing `repo/init.c` test suite. Also, this adds a bunch of new utility functions including a very general purpose `git_futils_mkdir` (with the ability to make paths and to chmod the paths post-creation) and a file tree copying function `git_futils_cp_r`. Also, this includes some new path functions that were useful to keep the code simple.
nulltoken b8457baa 2012-07-24T07:57:58 portability: Improve x86/amd64 compatibility
Russell Belfer b3ff1dab 2012-07-10T15:22:39 Adding git_config_foreach_match() iteration fn Adding a new config iteration function that let's you iterate over just the config entries that match a particular regular expression. The old foreach becomes a simple use of this with an empty pattern. This also fixes an apparent bug in the existing `git_config_foreach` where returning a non-zero value from the iteration callback was not correctly aborting the iteration and the returned value was not being propogated back to the caller of foreach. Added to tests to cover all these changes.