src/config_file.c


Log

Author Commit Date CI Message
Linquize 991dab2d 2014-07-16T21:09:53 Make sure \n is at the end of config file before a new section is written
Philip Kelley 4af0ef96 2014-05-15T11:09:49 Fix mutex init/free in config_file.c
Russell Belfer a37aa82e 2014-05-13T15:54:23 Some coverity inspired cleanups
Russell Belfer b1914c36 2014-05-12T10:24:46 Minor fixes for warnings and error propagation
Carlos Martín Nieto 2280b388 2014-04-09T13:17:51 config: share the strmap on snapshot Now that our strmap is no longer modified but replaced, we can use the same strmap for the snapshot's values and it will be freed when we don't need it anymore.
Carlos Martín Nieto 4b99b8f5 2014-04-09T13:08:01 config: refcount the values map This is mostly groundwork to let us re-use the map in the snapshots.
Carlos Martín Nieto 8c1f4ab4 2014-04-09T12:26:53 config: refresh on delete When we delete an entry, we also want to refresh the configuration to catch any changes that happened externally. This allows us to simplify the logic, as we no longer need to delete these variables internally. The whole state will be refreshed and the deleted entries won't be there.
Carlos Martín Nieto 523032cd 2014-03-31T09:58:44 config: refresh before reading a value With the isolation of complex reads, we can now try to refresh the on-disk file before reading a value from it. This changes the semantics a bit, as before we could be sure that a string we got from the configuration was valid until we wrote or refreshed. This is no longer the case, as a read can also invalidate the pointer.
Carlos Martín Nieto eaf37034 2014-03-31T08:53:56 config: refresh the values on write When writing out, parse the resulting file instead of adding or replacing the value locally. This has the effect of reading external changes as well.
Carlos Martín Nieto 0500a1ef 2014-03-31T08:32:45 config: use a snapshot for the iterator
Carlos Martín Nieto bd95f836 2014-03-31T08:08:17 config: split out the refresh step This will be used by the writing commands in a later step.
Carlos Martín Nieto c047317e 2014-03-18T17:54:32 config: make refresh atomic Current code sets the active map to a new one and builds it whilst it's active. This is a race condition with someone else trying to access the same config. Instead, let's build up our new map and swap the active and new one.
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 40ed4990 2014-02-11T14:45:37 Add diff threading tests and attr file cache locks This adds a basic test of doing simultaneous diffs on multiple threads and adds basic locking for the attr file cache because that was the immediate problem that arose from these tests.
Edward Thomson 83634d38 2014-02-24T17:43:10 Move system directory cache out of utils
Arthur Schreiber a8e4cb11 2014-01-13T22:12:17 Fix a memory leak in `config_parse`.
Robert Konrad 6014b7b5 2013-12-30T18:08:04 Fixed a compile error in VS2013.
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.
Vicent Marti a1d35ede 2013-11-10T16:41:41 config_file: style
Vicent Martí b9cb72c2 2013-11-10T07:33:11 Merge pull request #1950 from csware/quote-config-values Correctly quote config values while saving
Sven Strickroth 590c5efb 2013-11-07T17:51:43 Rename method Signed-off-by: Sven Strickroth <email@cs-ware.de>
Sven Strickroth fde93250 2013-11-07T13:17:36 Correctly quote config values while saving If the value contains a command (; or #) char or starts or ends with space it needs to be quoted. Signed-off-by: Sven Strickroth <email@cs-ware.de>
nulltoken 61080a95 2013-11-05T15:10:02 Fix leaks
nulltoken e8162fd0 2013-11-05T12:01:14 Propagate ELOCKED error when updating the config
Edward Thomson 1d3a8aeb 2013-11-04T18:28:57 move mode_t to filebuf_open instead of _commit
Carlos Martín Nieto a7a64d2c 2013-11-02T18:36:34 remote: don't write too much when dealing with multivars We used to move `data_start` forward, which is wrong as that needs to point to the beginning of the buffer in order to perform size calculations. Introduce a `write_start` variable which indicates where we should start writing from, which is what the `data_start` was being wrongly reused to be.
Vicent Marti b22593fb 2013-11-01T17:28:59 config_file: Style fixes
Daniel Rodríguez Troitiño a71331eb 2013-10-31T23:41:48 Fix memory leaks.
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.
Linquize 566dd8ce 2013-09-30T23:38:22 Config subsection name should allow to have ']' and '\\' should allow to escape any characters
Vicent Martí 92d19d16 2013-09-21T09:34:03 Merge pull request #1840 from linquize/warning Fix warning
Linquize 66566516 2013-09-08T17:15:42 Fix warning
Russell Belfer a9f51e43 2013-09-11T22:00:36 Merge git_buf and git_buffer This makes the git_buf struct that was used internally into an externally available structure and eliminates the git_buffer. As part of that, some of the special cases that arose with the externally used git_buffer were blended into the git_buf, such as being careful about git_buf objects that may have a NULL ptr and allowing for bufs with a valid ptr and size but zero asize as a way of referring to externally owned data.
Carlos Martín Nieto 53ea0513 2013-09-07T19:07:39 config: handle realloc issues from larger depths As the include depth increases, the chance of a realloc increases. This means that whenever we run git_array_alloc() or call config_parse(), we need to remember what our reader's index is so we can look it up again.
Carlos Martín Nieto 69789922 2013-09-07T18:50:35 config: return an error when reaching the maximum include depth
Carlos Martín Nieto 73fc5e01 2013-09-06T21:12:26 config: fix variable overriding When two or more variables of the same name exist and the user asks for a scalar, we must return the latest value assign to it.
Carlos Martín Nieto a9fb7989 2013-09-06T20:51:35 config: refresh included files We need to refresh the variables from the included files if they are changed, so loop over all included files and re-parse the files if any of them has changed.
Carlos Martín Nieto 19be0692 2013-09-06T20:34:02 config: keep a list of included files When refreshing we need to refresh if any of the files have been touched, so we need to keep the list.
Carlos Martín Nieto d8d25acb 2013-09-05T19:24:20 config: add support for include directives Relative, absolute and home-relative paths are supported. The recursion limit it set at 10, just like in git.
Carlos Martín Nieto d209cc47 2013-09-05T18:06:12 config: decouple the backend from the reader at the low level In order to support config includes, we must differentiate between the backend's main file and the file we are currently parsing. This lays the groundwork for includes, keeping the current behaviours.
Vicent Martí b8b22d77 2013-08-28T06:04:51 Merge pull request #1772 from libgit2/config-iter Configuration iterators redux
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 43e5dda7 2013-08-12T11:21:57 config: get rid of a useless asignment
Carlos Martín Nieto 5880962d 2013-08-09T09:05:19 config: introduce _iterator_new() As the name suggests, it iterates over all the entries
Russell Belfer 7f7ebe13 2013-08-08T12:57:13 Merge pull request #1771 from nvloff/write_empty_config_value config: allow setting empty string as value
Nikolai Vladimirov c57f6682 2013-08-08T21:17:32 config: allow empty string as value `git_config_set_string(config, "config.section", "")` fails when escaping the value. The buffer in `escape_value` is allocated without NULL-termination. And in case of empty string 0 is passed for buffer size in `git_buf_grow`. `git_buf_detach` returns NULL when the allocated size is 0 and that leads to an error return in `GITERR_CHECK_ALLOC` called after `escape_value` The change in `config_file.c` was suggested by Russell Belfer <rb@github.com>
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 82ae6fcd 2013-08-08T11:55:47 config: compilation fixes
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`
Nico von Geyso 6385fc5f 2013-03-17T20:39:01 added new type and several functions to git_strmap This step is needed to easily add iterators to git_config_backend As well use these new git_strmap functions to implement foreach * git_strmap_iter * git_strmap_has_data(...) * git_strmap_begin(...) * git_strmap_end(...) * git_strmap_next(...)
Edward Thomson 2d9f5b9f 2013-08-07T11:11:55 Parse config headers with quoted quotes Parse config headers that have the last quote on the line quoted instead of walking off the end.
Russell Belfer 278ce746 2013-07-01T10:20:38 Add helpful buffer shorten function
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.
Linquize e583334c 2013-05-10T21:42:22 Fix broken build when MSVC SDL checks is enabled
Vicent Martí a472f887 2013-04-22T07:44:32 Merge pull request #1493 from carlosmn/remotes Revamp the refspec handling
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.
Carlos Martín Nieto e5a27f03 2013-04-20T15:25:39 config: allow setting multivars when none exist yet Adding a multivar when there are no variables with that name set should set the variable instead of failing.
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.
Carlos Martín Nieto 9f35754a 2013-01-25T13:29:28 config: support trailing backslashes Check whether the backslash at the end of the line is being escaped or not so as not to consider it a continuation marker when it's e.g. a Windows-style path.
Edward Thomson 359fc2d2 2013-01-08T17:07:25 update copyrights
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
delanne f2696fa4 2012-11-26T12:12:41 Fix invalid read reported by valgrind
Martin Woodward 826bc4a8 2012-11-23T13:31:22 Remove use of English expletives Remove words such as fuck, crap, shit etc. Remove other potentially offensive words from comments. Tidy up other geopolicital terms in comments.
Carlos Martín Nieto 47db054d 2012-11-13T13:41:01 config: distinguish between a lone variable name and one without rhs '[section] variable' and '[section] variable =' behave differently when parsed as booleans, so we need to store that distinction internally.
delanne bcad677b 2012-11-08T12:28:21 - Update 'tests-clar/resources/config/config11' in order to reproduce the invalidread with the unittest (just added some \n at the end of the file) - Fix config_file.c
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.
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
yorah f8ede948 2012-09-18T14:10:40 Fix adding variable to config file with no trailing newline This can occur after a manual modification of a config file.
Carlos Martín Nieto b200a813 2012-09-14T20:43:47 config: fix Unicode BOM detection Defining the BOM as a string makes the array include the NUL-terminator, which means that the memcpy is going to check for that as well and thus never match for a nonempty file. Define the array as three chars, which makes the size correct.
Russell Belfer f335ecd6 2012-08-30T14:24:16 Diff iterators This refactors the diff output code so that an iterator object can be used to traverse and generate the diffs, instead of just the `foreach()` style with callbacks. The code has been rearranged so that the two styles can still share most functions. This also replaces `GIT_REVWALKOVER` with `GIT_ITEROVER` and uses that as a common error code for marking the end of iteration when using a iterator style of object.
Russell Belfer 0c8858de 2012-08-03T14:28:07 Fix valgrind issues and leaks This fixes up a number of problems flagged by valgrind and also cleans up the internal `git_submodule` allocation handling overall with a simpler model.
Russell Belfer aa13bf05 2012-08-02T13:00:58 Major submodule rewrite This replaces the old submodule API with a new extended API that supports most of the things that can be done with `git submodule`.
Russell Belfer 616c1433 2012-08-12T11:53:58 Clean up code Okay, this is probably cleaner and it is also less net change from the original version
Russell Belfer a1ecddf0 2012-08-12T07:59:30 Fix config parser boundary logic The config file parser was not working right if there was no whitespace between the value name and the equals sign. This fixes that.
Russell Belfer 5dca2010 2012-08-03T17:08:01 Update iterators for consistency across library This updates all the `foreach()` type functions across the library that take callbacks from the user to have a consistent behavior. The rules are: * A callback terminates the loop by returning any non-zero value * Once the callback returns non-zero, it will not be called again (i.e. the loop stops all iteration regardless of state) * If the callback returns non-zero, the parent fn returns GIT_EUSER * Although the parent returns GIT_EUSER, no error will be set in the library and `giterr_last()` will return NULL if called. This commit makes those changes across the library and adds tests for most of the iteration APIs to make sure that they follow the above rules.
Carlos Martín Nieto 5d9cfa07 2012-07-20T17:52:53 config: escape subsection names when creating them This allows us to set options like "some.foo\\ish.var". This closes #830
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.
Carlos Martín Nieto 49938cad 2012-06-11T16:28:51 config: correctly escape quotes in the value When a configuration option is set, we didn't check to see whether there was any escaping needed. Escape the available characters so we can unescape them correctly when we read them.
Carlos Martín Nieto 1d4dcc4b 2012-06-01T11:48:58 config: set an error message when asked to delete a non-existent key
Vicent Martí 904b67e6 2012-05-18T01:48:50 errors: Rename error codes
Vicent Martí e172cf08 2012-05-18T01:21:06 errors: Rename the generic return codes
Vicent Martí 0f49200c 2012-05-09T04:37:02 msvc: Do not use `isspace` Locale-aware bullshit bitting my ass again yo
Carlos Martín Nieto 3df9cc59 2012-05-03T16:07:22 config: don't use freed memory on error Change the order and set a NULL so we don't try to access freed memory in case of an error.
Russell Belfer b709e951 2012-05-04T11:06:12 Fix memory leaks and use after free
Vicent Martí 40879fac 2012-05-02T15:59:02 Merge branch 'new-error-handling' into development Conflicts: .travis.yml include/git2/diff.h src/config_file.c src/diff.c src/diff_output.c src/mwindow.c src/path.c tests-clar/clar_helpers.c tests-clar/object/tree/frompath.c tests/t00-core.c tests/t03-objwrite.c tests/t08-tag.c tests/t10-refs.c tests/t12-repo.c tests/t18-status.c tests/test_helpers.c tests/test_main.c
nulltoken fa6420f7 2012-04-29T21:46:33 buf: deploy git_buf_len()
Russell Belfer c2b67043 2012-04-25T15:20:28 Rename git_khash_str to git_strmap, etc. This renamed `git_khash_str` to `git_strmap`, `git_hash_oid` to `git_oidmap`, and deletes `git_hashtable` from the tree, plus adds unit tests for `git_strmap`.
Russell Belfer 01fed0a8 2012-04-25T10:36:01 Convert hashtable usage over to khash This updates khash.h with some extra features (like error checking on allocations, ability to use wrapped malloc, foreach calls, etc), creates two high-level wrappers around khash: `git_khash_str` and `git_khash_oid` for string-to-void-ptr and oid-to-void-ptr tables, then converts all of the old usage of `git_hashtable` over to use these new hashtables. For `git_khash_str`, I've tried to create a set of macros that yield an API not too unlike the old `git_hashtable` API. Since the oid hashtable is only used in one file, I haven't bother to set up all those macros and just use the khash APIs directly for now.
Russell Belfer 2bc8fa02 2012-04-17T10:14:24 Implement git_pool paged memory allocator This adds a `git_pool` object that can do simple paged memory allocation with free for the entire pool at once. Using this, you can replace many small allocations with large blocks that can then cheaply be doled out in small pieces. This is best used when you plan to free the small blocks all at once - for example, if they represent the parsed state from a file or data stream that are either all kept or all discarded. There are two real patterns of usage for `git_pools`: either for "string" allocation, where the item size is a single byte and you end up just packing the allocations in together, or for "fixed size" allocation where you are allocating a large object (e.g. a `git_oid`) and you generally just allocation single objects that can be tightly packed. Of course, you can use it for other things, but those two cases are the easiest.
Carlos Martín Nieto a7d19b97 2012-04-25T15:47:53 config: also allow escaping outside of a quoted string This limitation was a misparsing of the documentation.
Carlos Martín Nieto 2c1075d6 2012-03-16T12:52:49 config: parse quoted values Variable values may be quoted to include newlines, literal quotes and other characters. Add support for these and test it.
Carlos Martín Nieto 8e8b6b01 2012-04-04T13:13:43 Clean up valgrind warnings