src/config.c


Log

Author Commit Date CI Message
Vicent Marti fafd4710 2011-09-30T16:08:06 config: Proper type declarations for 64 bit ints
Carlos Martín Nieto 358a15fd 2011-09-30T15:43:58 config: fix check for environment string expansion If ExpandEnvironmentStringsW is successful, it returns the amount of characters written, including the NUL terminator. Thanks to Emeric for reading the MSDN documentation correctly. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Vicent Marti 6c8b458d 2011-09-29T17:04:45 mingw: Fix compilation warnings
Vicent Marti 780bea6e 2011-09-29T16:23:24 mingw: Fix printf identifiers
Carlos Martín Nieto a5b0e7f8 2011-09-27T20:08:13 Really fix MSVC These was left over from the previous PRs. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Carlos Martín Nieto 4c562347 2011-09-22T21:34:46 Add git_config_find_system This allows the library to guess where the system configuration file should be located. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Vicent Marti 01d7fded 2011-09-22T20:44:30 Revert "Rewrite getenv to use Win32 version on Windows" This reverts commit e1b86444676b70154bf8ab450d429bdef57a8276.
nulltoken ad196c6a 2011-09-21T23:17:39 config: make git_config_[get|set]_long() able to properly deal with 8 bytes wide values Should fix issue #419. Signed-off-by: nulltoken <emeric.fermas@gmail.com>
Paul Betts e1b86444 2011-09-21T11:17:30 Rewrite getenv to use Win32 version on Windows
Vicent Martí b3c524d1 2011-09-18T19:46:12 Merge pull request #399 from carlosmn/free-null Add checks for NULL to the config and remote free functions
Vicent Marti 87d9869f 2011-09-19T03:34:49 Tabify everything There were quite a few places were spaces were being used instead of tabs. Try to catch them all. This should hopefully not break anything. Except for `git blame`. Oh well.
Vicent Marti bb742ede 2011-09-19T01:54:32 Cleanup legal data 1. The license header is technically not valid if it doesn't have a copyright signature. 2. The COPYING file has been updated with the different licenses used in the project. 3. The full GPLv2 header in each file annoys me.
Carlos Martín Nieto 2aae2188 2011-09-13T02:05:12 Add checks for NULL to the config and remote free functions Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Vicent Marti 84dd3820 2011-08-18T02:13:51 posix: Properly handle `snprintf` in all platforms
Vicent Marti b08683ff 2011-07-12T02:38:20 config: Rename `del` to `delete
Vicent Marti de18f276 2011-07-07T01:46:20 vector: Timsort all of the things Drop the GLibc implementation of Merge Sort and replace it with Timsort. The algorithm has been tuned to work on arrays of pointers (void **), so there's no longer a need to abstract the byte-width of each element in the array. All the comparison callbacks now take pointers-to-elements, not pointers-to-pointers, so there's now one less level of dereferencing. E.g. int index_cmp(const void *a, const void *b) { - const git_index_entry *entry_a = *(const git_index_entry **)(a); + const git_index_entry *entry_a = (const git_index_entry *)(a); The result is up to a 40% speed-up when sorting vectors. Memory usage remains lineal. A new `bsearch` implementation has been added, whose callback also supplies pointer-to-elements, to uniform the Vector API again.
Carlos Martín Nieto 86b5ab16 2011-06-28T16:08:46 git_config_add_file should rethrow Otherwise, the information about why there was an error gets lost. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 6d4b6097 2011-06-28T15:20:42 Add git_config_del to delete a variable Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Vicent Marti f79026b4 2011-07-04T11:43:34 fileops: Cleanup Cleaned up the structure of the whole OS-abstraction layer. fileops.c now contains a set of utility methods for file management used by the library. These are abstractions on top of the original POSIX calls. There's a new file called `posix.c` that contains emulations/reimplementations of all the POSIX calls the library uses. These are prefixed with `p_`. There's a specific posix file for each platform (win32 and unix). All the path-related methods have been moved from `utils.c` to `path.c` and have their own prefix.
Vicent Marti cfef5fb7 2011-06-29T15:09:21 config: `foreach` now returns variable values too
Vicent Marti 19cb6857 2011-06-18T01:50:48 config: Bring back `git_config_open_global` Scott commands, I obey.
Vicent Marti dbe70bd5 2011-06-18T01:12:58 config: Fix compilation in MSVC
Vicent Marti 40070445 2011-06-18T00:54:24 config: Typorrrrl
Vicent Marti 07ff8817 2011-06-18T00:39:39 config: Cleanup external API Do not mess with environment variables anymore. The new external API has more helper methods, and everything is explicit.
Carlos Martín Nieto f3dad3ac 2011-06-16T20:06:36 Add fall-back support to the configuration If a config has several files, we need to check all of them before we can say that a variable doesn't exist. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Jakob Pfender 68384a27 2011-05-17T17:24:28 config.c: Fix format string error
Vicent Marti 5c36f6db 2011-05-23T20:43:19 config: Cleanup
Vicent Marti b0b527e0 2011-05-20T03:20:12 config: Cleanup & renaming of the external API "git_config_backend" have been renamed to "git_config_file", which implements a generic interface to access a configuration file -- be it either on disk, from a DB or whatever mumbojumbo. I think this makes more sense.
Vicent Marti 8adbf2ed 2011-05-20T02:58:33 Rewrite `git_config_open_global` We have a lot of utility methods that make path building trivial. Use them!
Carlos Martín Nieto 32234541 2011-05-17T14:18:42 Implement git_config_open_global Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Vicent Marti 0da2c700 2011-05-17T15:09:30 utils: Move git__str[n]tolower
Carlos Martín Nieto 29dca088 2011-05-17T13:38:19 Move config to the new error methods Take this opportunity to fix an instance of returning GIT_EOBJCORRUPTED when malloc failed. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto c0335005 2011-05-06T12:42:47 Move config to a backend structure Configuration options can come from different sources. Currently, there is only support for reading them from a flat file, but it might make sense to read it from a database at some point. Move the parsing code into src/config_file.c and create an include file include/git2/config_backend.h to allow for other backends to be developed. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 094aaaae 2011-05-05T15:16:15 config: store the section name separately The section and variable names use different rules, so store them as two different variables internally. This will simplify the configuration-writing code as well later on, but even with parsing, the code is simpler. Take this opportunity to add a variable to the list directly when parsing instead of passing through config_set.
Carlos Martín Nieto 0130d818 2011-04-27T11:20:38 Fix git__strntolower Obviously, the whole string should be lower-cased and not just the last char. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto a68cf94b 2011-04-19T16:40:52 Fix const char ** warning Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto a99264bf 2011-04-19T16:34:22 config: allow uppercase number suffixes Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 52ca4f8a 2011-04-11T17:51:05 Use internal strtol Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 631752aa 2011-04-11T17:49:47 Fix number suffix detection Allow a number not to have a suffix. This broke when adding the suffixes. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto b075b991 2011-04-07T16:54:10 Add getting and setting of long int variables long int is a safer type than int unless the user knows that the variable is going to be quite small. The code has been reworked to use strtol instead of the more complicated sscanf. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 7a4dfd60 2011-04-07T11:30:02 Simplify error path in config_set Many error paths freed their local data althought it is freed later on when the end of the function notices that there was an error. This can cause double frees and invalid memory access. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 493384e3 2011-04-07T11:24:16 config: make cvar_free behave more like other free functions Make cvar_free return void instad of the next element, as it was mostly a hack to make cvar_list_free shorter but it's now using the list macros. Also check if the input is NULL and return immediately in that case. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 6b45cb8a 2011-04-06T18:27:31 config: use and implement list macros Use list macros instead of manually changing the head and/or tail of the variable list.
Carlos Martín Nieto 0d280ea4 2011-04-06T16:31:06 config: use snprintf instead of sprintf Due to the preconditions, there should never be an error, but it pays to be paranoid. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 956ad0ed 2011-04-06T15:51:10 config: free the file buffer earlier There is no need to keep config file in memory until the the configuration is freed. Free the buffer immediately after the configuration has been parsed. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto acab3bc4 2011-04-06T15:31:42 config: move str(n)tolower to the git__ namespace Non-static functions in a library should always have a prefix namespace. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto aa793424 2011-04-06T15:27:12 config: coding style fixes
Carlos Martín Nieto 6776fd51 2011-04-06T15:17:06 config: really compare the variable name case-insensitively Make cvar_name_match really compare the last part of the variable ignoring the case. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 2470be13 2011-04-04T17:06:31 config: variable name on its own means true If a variable name appears on its own in a line, it's assumed the value is true. Store the variable name as NULL in that case. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 9b7a6a99 2011-04-04T16:17:39 config: check for EOF before newline If a line ends at EOF there is no need to check for the newline character and doing so will cause us to read memory beyond the allocatd memory as we check for the Windows-style new-line, which is two bytes long. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto fe116e26 2011-04-04T15:33:14 config: Fix typo and remove debug statement Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 72946881 2011-04-04T15:26:43 config: support multiline values If a variable value has the traditional continuation character (\) as the last non-space character in the line, then we continue reading the value on the next line. Using more than two lines is also supported. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 2454ce78 2011-04-04T11:25:55 config: don't mix buffer reading methods Make header and variable parse functions use their own buffers instead of giving them the line they need to read as a parameter which they mostly ignore. This is in preparation for multiline configuration variables. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 9f1b54d6 2011-04-04T15:07:47 config: also free the file buffer on error On error, the buffer containing the file contents also needs to be freed. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 11d0e705 2011-03-31T10:50:11 Add support for subsections A variable name is stored internally with its section the way it appeared in the configuration file in order to have the information about what parts are case-sensitive inline. Really implement parse_section_header_ext and move the assignment of variables to config_parse. The variable name matching is now done in a case-away way by cvar_name_match and cvar_section_match. Before the user sees it, it's normalized to the two- or three-dot version. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto df22949a 2011-03-31T12:51:17 config_set: really replace the value on overwrite Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 6482929b 2011-03-30T18:51:02 move build_varname above parse_section
Carlos Martín Nieto d7354d70 2011-03-30T16:22:31 build_varname: lowercase the variable name Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 0bbaf9aa 2011-03-30T16:11:55 config_parse: no need to check if current_section is non-null Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 923fe455 2011-03-30T16:02:57 Add strtolower and strntolower functions As parts of variable names are case-sensitive, we need these functions. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 8ecc5ae5 2011-03-30T16:48:14 git_config_set_int: use the right buffer Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto dadc0158 2011-03-30T15:05:15 config: use a singly-linked list instead of a hash table Such a list preserves the order the variables were first read in which will be useful later for merging different data-sets. Furthermore, reading and writing out the same configuration should not reorganize the variables, which could happen when iterating through all the items in a hash table. A hash table is overkill for this small a data-set anyway. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto d28830c2 2011-03-30T13:40:19 Store the parsed variables Store the key-value pair as strings. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 934fcf78 2011-03-30T11:32:08 Initialise the config reader in config_parse git_config_open shouldn't have to initialise variables that are only used inside config_parse and its callees. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 2974aa94 2011-03-30T11:30:40 Determine variable type at runtime Config variables should be interpreted at run-time, as we don't know if a zero means false or zero, or if yes means true or "yes". As a variable has no intrinsic type, git_cvtype is gone and the public API takes care of enforcing a few rules. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 2e445cac 2011-03-30T11:07:09 build_varname: allocate memory Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 9a3c5e55 2011-03-29T17:44:10 Expose config API for setters, getters and foreach These functions can be used to query or modify the variables in a given configuration. No sanity checking is done on the variable names. This is mostly meant as an API preview. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 26faa366 2011-03-29T17:59:13 Add build_varname to make a full var name Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto e15afc8e 2011-03-29T17:37:03 cvar_free: also free the config var's name Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 3d23b74a 2011-03-29T13:50:37 Free the config var hash contents in git_config_free Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 9f7f4122 2011-03-29T12:19:53 Don't leak if config parsing fails Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 4e02504f 2011-03-29T12:10:30 Move config to support the new hash code The hashes have been copied from the references code Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 3b4835c2 2011-03-28T18:07:22 Correctly parse the section header If cfg_readline consumes the line, then parse_section_header will read past it and if we read a character, parse_variable won't have the full name. This solution is a bit hackish, but it's the simplest way to get the code to parse correctly. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 908afb77 2011-03-28T17:53:04 parse_section_header: save the name where it belongs Save the location of the name in section_out instead of returning it as an int. Use the return code to signal success or failure. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto e4c796f1 2011-03-28T17:51:18 Read and parse the confguration when openingt the config file Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto a69053c7 2011-03-28T17:12:53 Convert config.c to LF Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Carlos Martín Nieto 5d4cd003 2011-03-28T17:02:45 Move the struct declaration outside config.c Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Vicent Marti a3002d56 2011-01-29T01:58:55 First version - WIP Signed-off-by: Vicent Marti <tanoku@gmail.com>