summaryrefslogtreecommitdiff
path: root/src/config_file.c
Commit message (Collapse)AuthorAgeFilesLines
* config: implement basic transactional supportCarlos Martín Nieto2015-08-121-12/+81
| | | | | | | When a configuration file is locked, any updates made to it will be done to the in-memory copy of the file. This allows for multiple updates to happen while we hold the lock, preventing races during complex config-file manipulation.
* config: write the modified file to memoryCarlos Martín Nieto2015-08-121-8/+12
| | | | | | | | | | Instead of writing into the filebuf directly, make the functions to write the modified config file write into a buffer which can then be dumped into the lockfile for committing. This allows us to re-use the same code for modifying a locked configuration, as we can simply skip the last step of dumping the data to disk.
* git__tolower: a tolower() that isn't dumbEdward Thomson2015-05-291-2/+2
| | | | | | | | Some brain damaged tolower() implementations appear to want to take the locale into account, and this may require taking some insanely aggressive lock on the locale and slowing down what should be the most trivial of trivial calls for people who just want to downcase ASCII.
* config: plug a couple of leaksCarlos Martín Nieto2015-05-051-4/+7
|
* config: cleanup some now-unused variablesEdward Thomson2015-05-041-7/+16
|
* config: lock the file for write before readingEdward Thomson2015-05-041-8/+7
| | | | | | | When writing a configuration file, we want to take a lock on the new file (eg, `config.lock`) before opening the configuration file (`config`) for reading so that we can prevent somebody from changing the contents underneath us.
* config: write existing lines as-is when rewritingEdward Thomson2015-05-041-28/+70
| | | | | | | | When updating a configuration file, we want to copy the old data from the file to preserve comments and funny whitespace, instead of writing it in some "canonical" format. Thus, we keep a pointer to the start of the line and the line length to preserve these things we don't care to rewrite.
* config: examine whole file when writingEdward Thomson2015-05-041-396/+384
| | | | | | | | | | | | | | | | Previously we would try to be clever when writing the configuration file and try to stop parsing (and simply copy the rest of the old file) when we either found the value we were trying to write, or when we left the section that value was in, the assumption being that there was no more work to do. Regrettably, you can have another section with the same name later in the file, and we must cope with that gracefully, thus we read the whole file in order to write a new file. Now, writing a file looks even more than reading. Pull the config parsing out into its own function that can be used by both reading and writing the configuration.
* config: peek returns '\n' on EOF; handle in writeEdward Thomson2015-04-231-1/+1
|
* config: validate config keysEdward Thomson2015-04-231-13/+41
|
* git_config_delete: search until last section.Ryan Roden-Corrent2015-04-211-1/+4
| | | | | | | | If git_config_delete is to work properly in the presence of duplicate section headers, it cannot stop searching at the end of the first matching section, as there may be another matching section later. When config_write is used for deletion (value = NULL), it may only terminate when the desired key is found or there are no sections left to parse.
* config_file: comment char can be invalid escapeEdward Thomson2015-04-201-2/+10
| | | | | | Don't assume that comment chars are comment chars, they may be (an attempt to be escaped). If so, \; is not a valid escape sequence, complain.
* config_file: parse multilines generouslyEdward Thomson2015-04-201-54/+38
| | | | | Combine unquoting and multiline detection to avoid ambiguity when parsing.
* Fix checking of return value for regcomp.Patrick Steinhardt2015-04-101-2/+2
| | | | | | | | 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-8/+16
| | | | | | | | | | | | | | | 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.
* Remove extra semicolon outside of a functionStefan Widgren2015-02-151-1/+1
| | | | | Without this change, compiling with gcc and pedantic generates warning: ISO C does not allow extra ‘;’ outside of a function.
* Merge pull request #2895 from ethomson/alloc_overflowCarlos Martín Nieto2015-02-151-9/+22
|\ | | | | allocations: test for overflow of requested size
| * Make our overflow check look more like gcc/clang'sEdward Thomson2015-02-131-13/+11
| | | | | | | | | | | | | | | | | | Make our overflow checking look more like gcc and clang's, so that we can substitute it out with the compiler instrinsics on platforms that support it. This means dropping the ability to pass `NULL` as an out parameter. As a result, the macros also get updated to reflect this as well.
| * overflow checking: don't make callers set oomEdward Thomson2015-02-121-2/+0
| | | | | | | | | | | | Have the ALLOC_OVERFLOW testing macros also simply set_oom in the case where a computation would overflow, so that callers don't need to.
| * allocations: test for overflow of requested sizeEdward Thomson2015-02-121-8/+25
| | | | | | | | | | Introduce some helper macros to test integer overflow from arithmetic and set error message appropriately.
* | Reinit `reader` pointer after reading included config fileYury G. Kudryashov2015-02-131-0/+1
|/ | | | | | Fixes #2869. If included file includes more files, it may reallocate cfg_file->readers, hence invalidate not only `r` pointer, but `result` pointer as well.
* Plug some leaksJacques Germishuys2014-12-291-7/+5
|
* Spelling fixesWill Stamper2014-12-041-1/+1
|
* Clean up issues include.path issues found during code review.John Fultz2014-11-021-2/+9
| | | | | | | | * Error-handling is cleaned up to only let a file-not-found error through, not other sorts of errors. And when a file-not-found error happens, we clean up the error. * Test now checks that file-not-found introduces no error. And other minor cleanups.
* Make config reading continue after hitting a missing include file.John Fultz2014-11-011-7/+6
| | | | | | | | | | | For example, if you have [include] path = foo and foo didn't exist, git_config_open_ondisk() would just give up on the rest of the file. Now it ignores the unresolved include without error and continues reading the rest of the file.
* config: remove the refresh function and backend fieldcmn/config-refresh-removeCarlos Martín Nieto2014-10-231-9/+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.
* Patch from @carlosmn to refresh the parent config before snapshotting.refresh-config-snapshotAlan Rogers2014-10-231-1/+6
|
* config: Fix multiple trailing spaces before comments not completely trimmedLinquize2014-10-041-1/+1
|
* config: a multiline var can start immediatelyCarlos Martín Nieto2014-08-091-1/+1
| | | | | | | | | | | | | | | | | In the check for multiline, we traverse the backslashes from the end backwards and int the end assert that we haven't gone past the beginning of the line. We make sure of this in the loop condition, but we also check in the return value. However, for certain configurations, a line in a multiline variable might be empty to aid formatting. In that case, 'end' == 'start', since we ended up looking at the first char which made it a multiline. There is no need for the (end > start) check in the return, since the loop guarantees we won't go further back than the first char in the line, and we do accept the first char to be the final backslash. This fixes #2483.
* Make sure \n is at the end of config file before a new section is writtenLinquize2014-07-161-3/+3
|
* Fix mutex init/free in config_file.cPhilip Kelley2014-05-151-1/+4
|
* Some coverity inspired cleanupsRussell Belfer2014-05-131-3/+5
|
* Minor fixes for warnings and error propagationRussell Belfer2014-05-121-8/+5
|
* config: share the strmap on snapshotCarlos Martín Nieto2014-04-181-54/+2
| | | | | | 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.
* config: refcount the values mapCarlos Martín Nieto2014-04-181-43/+131
| | | | This is mostly groundwork to let us re-use the map in the snapshots.
* config: refresh on deleteCarlos Martín Nieto2014-04-181-51/+12
| | | | | | | | | 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.
* config: refresh before reading a valueCarlos Martín Nieto2014-04-181-3/+12
| | | | | | | | | | 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.
* config: refresh the values on writeCarlos Martín Nieto2014-04-181-82/+17
| | | | | | 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.
* config: use a snapshot for the iteratorCarlos Martín Nieto2014-04-181-3/+17
|
* config: split out the refresh stepCarlos Martín Nieto2014-04-181-14/+25
| | | | This will be used by the writing commands in a later step.
* config: make refresh atomicCarlos Martín Nieto2014-04-181-23/+16
| | | | | | | | 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.
* config: implement config snapshottingCarlos Martín Nieto2014-04-181-67/+263
| | | | | | | | | | | 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.
* Add diff threading tests and attr file cache locksRussell Belfer2014-04-171-7/+13
| | | | | | 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.
* Move system directory cache out of utilsEdward Thomson2014-02-241-2/+2
|
* Fix a memory leak in `config_parse`.Arthur Schreiber2014-01-131-1/+3
|
* Fixed a compile error in VS2013.Robert Konrad2014-01-021-1/+1
|
* Add config read fns with controlled error behaviorRussell Belfer2013-12-111-11/+2
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* config_file: styleVicent Marti2013-11-101-18/+18
|
* Merge pull request #1950 from csware/quote-config-valuesVicent Martí2013-11-101-2/+24
|\ | | | | Correctly quote config values while saving
| * Rename methodSven Strickroth2013-11-071-3/+3
| | | | | | | | Signed-off-by: Sven Strickroth <email@cs-ware.de>