summaryrefslogtreecommitdiff
path: root/src/config_file.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Add git_config_refresh() API to reload configRussell Belfer2012-10-301-6/+43
| | | | | | | | | | | | | | | | | | | | 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.
* Add config level support in the config APIyorah2012-10-231-45/+49
| | | | | | | 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
* Fix adding variable to config file with no trailing newlineyorah2012-10-231-0/+4
| | | | This can occur after a manual modification of a config file.
* config: fix Unicode BOM detectionCarlos Martín Nieto2012-09-141-1/+1
| | | | | | | | 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.
* Diff iteratorsRussell Belfer2012-09-051-0/+1
| | | | | | | | | | | 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.
* Fix valgrind issues and leaksRussell Belfer2012-08-241-2/+4
| | | | | | 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.
* Major submodule rewriteRussell Belfer2012-08-241-0/+6
| | | | | This replaces the old submodule API with a new extended API that supports most of the things that can be done with `git submodule`.
* Clean up codeRussell Belfer2012-08-121-3/+2
| | | | | Okay, this is probably cleaner and it is also less net change from the original version
* Fix config parser boundary logicRussell Belfer2012-08-121-4/+3
| | | | | | The config file parser was not working right if there was no whitespace between the value name and the equals sign. This fixes that.
* Update iterators for consistency across libraryRussell Belfer2012-08-031-1/+3
| | | | | | | | | | | | | | | | | 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.
* config: escape subsection names when creating themCarlos Martín Nieto2012-07-211-2/+5
| | | | | | This allows us to set options like "some.foo\\ish.var". This closes #830
* Adding git_config_foreach_match() iteration fnRussell Belfer2012-07-101-7/+30
| | | | | | | | | | | | | | 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.
* config: correctly escape quotes in the valueCarlos Martín Nieto2012-06-131-6/+47
| | | | | | 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.
* config: set an error message when asked to delete a non-existent keyCarlos Martín Nieto2012-06-011-1/+3
|
* msvc: Do not use `isspace` Vicent Martí2012-05-091-8/+8
| | | | Locale-aware bullshit bitting my ass again yo
* config: don't use freed memory on errorCarlos Martín Nieto2012-05-081-6/+6
| | | | | Change the order and set a NULL so we don't try to access freed memory in case of an error.
* Fix memory leaks and use after freeRussell Belfer2012-05-041-0/+1
|
* Merge branch 'new-error-handling' into developmentVicent Martí2012-05-021-432/+442
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
| * buf: deploy git_buf_len()nulltoken2012-04-301-1/+1
| |
| * Rename git_khash_str to git_strmap, etc.Russell Belfer2012-04-251-29/+29
| | | | | | | | | | | | 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`.
| * Convert hashtable usage over to khashRussell Belfer2012-04-251-36/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Implement git_pool paged memory allocatorRussell Belfer2012-04-251-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * config: also allow escaping outside of a quoted stringCarlos Martín Nieto2012-04-251-6/+0
| | | | | | | | This limitation was a misparsing of the documentation.
| * config: parse quoted valuesCarlos Martín Nieto2012-04-161-21/+85
| | | | | | | | | | Variable values may be quoted to include newlines, literal quotes and other characters. Add support for these and test it.
| * Clean up valgrind warningsCarlos Martín Nieto2012-04-041-0/+1
| |
| * Added submodule API and use in statusRussell Belfer2012-03-281-0/+3
| | | | | | | | | | | | | | | | | | | | When processing status for a newly checked out repo, it is possible that there will be submodules that have not yet been initialized. The only way to distinguish these from untracked directories is to have some knowledge of submodules. This commit adds a new submodule API which, given a name or path, can determine if it appears to be a submodule and can give information about the submodule.
| * error-handling: On-disk config file backendVicent Martí2012-03-091-391/+316
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Includes: - Proper error reporting when encountering syntax errors in a config file (file, line number, column). - Rewritten `config_write`, now with 99% less goto-spaghetti - Error state in `git_filebuf`: filebuf write functions no longer need to be checked for error returns. If any of the writes performed on a buffer fail, the last call to `git_filebuf_commit` or `git_filebuf_hash` will fail accordingly and set the appropiate error message. Baller!
* | config: write out section headers with subsections correctlyCarlos Martín Nieto2012-03-091-10/+6
|/ | | | | | | | | | write_section() mistakenly treated is input as the whole variable name instead of simply the section (and possibly subsection) and would confuse "section.subsection" as a section plus variable name and produce a wrong section header. Fix this and include a test for writing "section.subsection.var" and reading it from the file.
* Clean up GIT_UNUSED macros on all platformsRussell Belfer2012-03-021-2/+1
| | | | | | | | | | | | | | | | | | | It turns out that commit 31e9cfc4cbcaf1b38cdd3dbe3282a8f57e5366a5 did not fix the GIT_USUSED behavior on all platforms. This commit walks through and really cleans things up more thoroughly, getting rid of the unnecessary stuff. To remove the use of some GIT_UNUSED, I ended up adding a couple of new iterators for hashtables that allow you to iterator just over keys or just over values. In making this change, I found a bug in the clar tests (where we were doing *count++ but meant to do (*count)++ to increment the value). I fixed that but then found the test failing because it was not really using an empty repo. So, I took some of the code that I wrote for iterator testing and moved it to clar_helpers.c, then made use of that to make it easier to open fixtures on a per test basis even within a single test file.
* buffer: Unify `git_fbuffer` and `git_buf`Vicent Martí2012-02-271-11/+11
| | | | | | | | | | | | | | This makes so much sense that I can't believe it hasn't been done before. Kill the old `git_fbuffer` and read files straight into `git_buf` objects. Also: In order to fully support 4GB files in 32-bit systems, the `git_buf` implementation has been changed from using `ssize_t` for storage and storing negative values on allocation failure, to using `size_t` and changing the buffer pointer to a magical pointer on allocation failure. Hopefully this won't break anything.
* config: correctly deal with setting a multivar with regex where there are no ↵Carlos Martín Nieto2012-02-251-52/+61
| | | | | | | | | | | | matches We used to erroneously consider "^$" as a special case for appending a value to a multivar. This was a misunderstanding and we should always append a value if there are no existing values that match. While we're in the area, replace all the variables in-memory in one swoop and then replace them on disk so as to avoid matching a value we've just introduced.
* Implement setting multivarsCarlos Martín Nieto2012-02-171-9/+102
|
* Support getting multivarsCarlos Martín Nieto2012-02-171-0/+42
|
* Store multivars in the multimapCarlos Martín Nieto2012-02-171-3/+11
|
* First round of config multimap changesCarlos Martín Nieto2012-02-171-219/+147
| | | | | | Move the configuration to use a multimap instead of a list. This commit doesn't provide any functional changes but changes the support structures.
* Update Copyright headerschu2012-02-131-1/+1
| | | | Signed-off-by: schu <schu-github@schulog.org>
* config_file: fix clang sizeof-pointer-memaccessschu2012-02-131-1/+1
|
* config: don't use 'section "subsection"' internal form on config_setCarlos Martín Nieto2012-01-231-12/+2
| | | | | | | | This had been left over from a time when I believed what the git documentation had to say about case-sensitivity. The rest of the code doesn't recognize this form and we hadn't noticed because most tests don't try to get a recently-set variable but free and reload the configuration, causing the right format to be used.
* config: handle EOF properlyCarlos Martín Nieto2012-01-131-2/+4
| | | | | | | | | | | | | In the main loop we peek to see what kind of line the next one is. If there are multiple newlines before the end of the file, the eof marker won't be set after we read the last line with data and we'll try to peek again. This peek will return LF (as it pretends that we have a newline at EOF so other function don't need any special handling). Fix cfg_getchar so it doesn't try to read past the last character in the file and config_parse so it considers LF as EOF on peek (as we're ignoring spaces) and sets the reader's EOF flag to exit the parsing loop.
* config: Rename the `delete` callback nameVicent Martí2011-12-311-1/+1
| | | | `delete` is a reserved keyword in C++.
* config_file: honor errorschu2011-12-191-3/+6
| | | | | | | | | Return an error if we can't write an updated version of the config file after config_delete. Along with that, fix an uninitialized warning. Signed-off-by: schu <schu-github@schulog.org>
* config: really delete variablesCarlos Martín Nieto2011-12-161-0/+27
| | | | | | Instead of just setting the value to NULL, which gives unwanted results when asking for that variable after deleting it, delete the variable from the list and re-write the file.
* Revert "config: Return ENOTFOUND when a variable was deleted"Carlos Martín Nieto2011-12-161-2/+4
| | | | | | | | | This would make us think that config variables like [core] something is missing.
* config: Return ENOTFOUND when a variable was deletedVicent Marti2011-12-151-4/+2
|
* repository: Change ownership semanticsVicent Marti2011-11-261-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The ownership semantics have been changed all over the library to be consistent. There are no more "borrowed" or duplicated references. Main changes: - `git_repository_open2` and `3` have been dropped. - Added setters and getters to hotswap all the repository owned objects: `git_repository_index` `git_repository_set_index` `git_repository_odb` `git_repository_set_odb` `git_repository_config` `git_repository_set_config` `git_repository_workdir` `git_repository_set_workdir` Now working directories/index files/ODBs and so on can be hot-swapped after creating a repository and between operations. - All these objects now have proper ownership semantics with refcounting: they all require freeing after they are no longer needed (the repository always keeps its internal reference). - Repository open and initialization has been updated to keep in mind the configuration files. Bare repositories are now always detected, and a default config file is created on init. - All the tests affected by these changes have been dropped from the old test suite and ported to the new one.
* config: allow to open and write to a new fileCarlos Martín Nieto2011-11-261-5/+21
|
* filebuf: add GIT_FILEBUF_INIT and protect multiple opens and cleanupsRussell Belfer2011-11-221-1/+1
| | | | | | | | Update all stack allocations of git_filebuf to use GIT_FILEBUF_INIT and make git_filebuf_open and git_filebuf_cleanup safe to be called multiple times on the same buffer. Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Merge pull request #456 from brodie/perm-fixesVicent Martí2011-10-281-1/+1
|\ | | | | Create objects, indexes, and directories with the right file permissions
| * *: correct and codify various file permissionsBrodie Rao2011-10-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following files now have 0444 permissions: - loose objects - pack indexes - pack files - packs downloaded by fetch - packs downloaded by the HTTP transport And the following files now have 0666 permissions: - config files - repository indexes - reflogs - refs This brings libgit2 more in line with Git. Note that git_filebuf_commit() and git_filebuf_commit_at() have both gained a new mode parameter. The latter change fixes an important issue where filebufs created with GIT_FILEBUF_TEMPORARY received 0600 permissions (due to mkstemp(3) usage). Now we chmod() the file before renaming it into place. Tests have been added to confirm that new commit, tag, and tree objects are created with the right permissions. I don't have access to Windows, so for now I've guarded the tests with "#ifndef GIT_WIN32".
* | global: Properly use `git__` memory wrappersVicent Marti2011-10-281-32/+32
| | | | | | | | | | Ensure that all memory related functions (malloc, calloc, strdup, free, etc) are using their respective `git__` wrappers.