summaryrefslogtreecommitdiff
path: root/src/attrcache.c
Commit message (Collapse)AuthorAgeFilesLines
* path: use new length validation functionsEdward Thomson2021-11-091-2/+7
|
* path: separate git-specific path functions from utilEdward Thomson2021-11-091-4/+4
| | | | | | Introduce `git_fs_path`, which operates on generic filesystem paths. `git_path` will be kept for only git-specific path functionality (for example, checking for `.git` in a path).
* str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstrEdward Thomson2021-10-171-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | libgit2 has two distinct requirements that were previously solved by `git_buf`. We require: 1. A general purpose string class that provides a number of utility APIs for manipulating data (eg, concatenating, truncating, etc). 2. A structure that we can use to return strings to callers that they can take ownership of. By using a single class (`git_buf`) for both of these purposes, we have confused the API to the point that refactorings are difficult and reasoning about correctness is also difficult. Move the utility class `git_buf` to be called `git_str`: this represents its general purpose, as an internal string buffer class. The name also is an homage to Junio Hamano ("gitstr"). The public API remains `git_buf`, and has a much smaller footprint. It is generally only used as an "out" param with strict requirements that follow the documentation. (Exceptions exist for some legacy APIs to avoid breaking callers unnecessarily.) Utility functions exist to convert a user-specified `git_buf` to a `git_str` so that we can call internal functions, then converting it back again.
* Homogenize semantics for atomic-related functionslhchavez2021-08-261-7/+6
| | | | | | | | | | | | | | | | | | There were some subtle semantic differences between the various implementations of atomic functions. Now they behave the same, have tests and are better documented to avoid this from happening again in the future. Of note: * The semantics chosen for `git_atomic_compare_and_swap` match `InterlockedCompareExchangePointer`/`__sync_cal_compare_and_swap` now. * The semantics chosen for `git_atomic_add` match `InterlockedAdd`/`__atomic_add_fetch`. * `git_atomic_swap` and `git_atomic_load` still have a bit of semantic difference with the gcc builtins / msvc interlocked operations, since they require an l-value (not a pointer). If desired, this can be homogenized.
* attr: introduce GIT_ATTR_CHECK_INCLUDE_COMMITEdward Thomson2021-07-221-3/+4
| | | | | | | | Introduce `GIT_ATTR_CHECK_INCLUDE_COMMIT`, which like 4fd5748 allows attribute information to be read from files in the repository. 4fd5748 always reads the information from HEAD, while `GIT_ATTR_CHECK_INCLUDE_COMMIT` allows users to provide the commit to read the attributes from.
* attr: include the filename in the attr sourceEdward Thomson2021-07-221-21/+18
| | | | The attribute source object is now the type and the path.
* attr: the attr source is now a structEdward Thomson2021-07-221-3/+4
| | | | | We may want to extend the attribute source; use a structure instead of an enum.
* attr: rename internal attr file source enumEdward Thomson2021-07-221-11/+13
| | | | | | The enum `git_attr_file_source` is better suffixed with a `_t` since it's a type-of source. Similarly, its members should have a matching name.
* attr: validate workdir paths for attribute filesEdward Thomson2021-04-281-3/+8
| | | | | | We should allow attribute files - inside working directories - to have names longer than MAX_PATH when core.longpaths is set. `git_attr_path__init` takes a repository to validate the path with.
* threads: give atomic functions the git_atomic prefixEdward Thomson2020-12-061-5/+5
|
* git_pool_init: handle failure casesethomson/poolinitEdward Thomson2020-06-011-3/+2
| | | | Propagate failures caused by pool initialization errors.
* git_attr_cache_flush: return an intEdward Thomson2020-01-241-1/+3
| | | | | Stop returning a void for functions, future-proofing them to allow them to fail.
* attr: Update definition of binary macroLaurence McGlashan2019-12-121-1/+1
|
* attr_file: ignore macros defined in subdirectoriesPatrick Steinhardt2019-07-121-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Right now, we are unconditionally applying all macros found in a gitatttributes file. But quoting gitattributes(5): Custom macro attributes can be defined only in top-level gitattributes files ($GIT_DIR/info/attributes, the .gitattributes file at the top level of the working tree, or the global or system-wide gitattributes files), not in .gitattributes files in working tree subdirectories. The built-in macro attribute "binary" is equivalent to: So gitattribute files in subdirectories of the working tree may explicitly _not_ contain macro definitions, but we do not currently enforce this limitation. This patch introduces a new parameter to the gitattributes parser that tells whether macros are allowed in the current file or not. If set to `false`, we will still parse macros, but silently ignore them instead of adding them to the list of defined macros. Update all callers to correctly determine whether the to-be-parsed file may contain macros or not. Most importantly, when walking up the directory hierarchy, we will only set it to `true` once it reaches the root directory of the repo itself. Add a test that verifies that we are indeed not applying macros from subdirectories. Previous to these changes, the test would've failed.
* attrcache: fix memory leak if inserting invalid macro to cachePatrick Steinhardt2019-07-121-2/+11
| | | | | | | | | | | | A macro without any assignments is considered an invalid macro by the attributes cache and is thus not getting added to the macro map at all. But as `git_attr_cache__insert_macro` returns success with neither free'ing nor adopting the macro into its map, this will cause a memory leak. Fix this by freeing the macro in the function if it's not going to be added. This is perfectly fine to do, as callers assume that the attrcache will have the macro adopted on success anyway.
* attrcache: fix multiple memory leaks when inserting macrosPatrick Steinhardt2019-07-121-10/+16
| | | | | | | | | | | The function `git_attr_cache__insert_macro` is responsible for adopting macros in the per-repo macro cache. When adding a macro that replaces an already existing macro (e.g. because of re-parsing gitattributes files), then we do not free the previous macro and thus cause a memory leak. Fix this leak by first checking if the cache already has a macro defined with the same name. If so, free it before replacing the cache entry with the new instance.
* pool: use `size_t` for sizesEdward Thomson2019-06-241-1/+1
|
* strmap: introduce high-level setter for key/value pairsPatrick Steinhardt2019-02-151-10/+8
| | | | | | | | | | | | Currently, one would use the function `git_strmap_insert` to insert key/value pairs into a map. This function has historically been a macro, which is why its syntax is kind of weird: instead of returning an error code directly, it instead has to be passed a pointer to where the return value shall be stored. This does not match libgit2's common idiom of directly returning error codes. Introduce a new function `git_strmap_set`, which takes as parameters the map, key and value and directly returns an error code. Convert all callers of `git_strmap_insert` to make use of it.
* strmap: introduce `git_strmap_get` and use it throughout the treePatrick Steinhardt2019-02-151-20/+4
| | | | | | | | | | | | | | The current way of looking up an entry from a map is tightly coupled with the map implementation, as one first has to look up the index of the key and then retrieve the associated value by using the index. As a caller, you usually do not care about any indices at all, though, so this is more complicated than really necessary. Furthermore, it invites for errors to happen if the correct error checking sequence is not being followed. Introduce a new high-level function `git_strmap_get` that takes a map and a key and returns a pointer to the associated value if such a key exists. Otherwise, a `NULL` pointer is returned. Adjust all callers that can trivially be converted.
* maps: use uniform lifecycle management functionsPatrick Steinhardt2019-02-151-2/+2
| | | | | | | | | | | | | | | | Currently, the lifecycle functions for maps (allocation, deallocation, resize) are not named in a uniform way and do not have a uniform function signature. Rename the functions to fix that, and stick to libgit2's naming scheme of saying `git_foo_new`. This results in the following new interface for allocation: - `int git_<t>map_new(git_<t>map **out)` to allocate a new map, returning an error code if we ran out of memory - `void git_<t>map_free(git_<t>map *map)` to free a map - `void git_<t>map_clear(git<t>map *map)` to remove all entries from a map This commit also fixes all existing callers.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-6/+6
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* khash: remove intricate knowledge of khash typesPatrick Steinhardt2018-11-281-3/+3
| | | | | | | Instead of using the `khiter_t`, `git_strmap_iter` and `khint_t` types, simply use `size_t` instead. This decouples code from the khash stuff and makes it possible to move the khash includes into the implementation files.
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-2/+2
|
* Make sure to always include "common.h" firstPatrick Steinhardt2017-07-031-1/+2
| | | | | | | | | | | | | | | | | | | | | | Next to including several files, our "common.h" header also declares various macros which are then used throughout the project. As such, we have to make sure to always include this file first in all implementation files. Otherwise, we might encounter problems or even silent behavioural differences due to macros or defines not being defined as they should be. So in fact, our header and implementation files should make sure to always include "common.h" first. This commit does so by establishing a common include pattern. Header files inside of "src" will now always include "common.h" as its first other file, separated by a newline from all the other includes to make it stand out as special. There are two cases for the implementation files. If they do have a matching header file, they will always include this one first, leading to "common.h" being transitively included as first file. If they do not have a matching header file, they instead include "common.h" as first file themselves. This fixes the outlined problems and will become our standard practice for header and source files inside of the "src/" from now on.
* Add missing license headersPatrick Steinhardt2017-07-031-0/+7
| | | | | Some implementation files were missing the license headers. This commit adds them.
* config, attrcache: don't fallback to dirs literally named `~`Edward Thomson2017-03-231-5/+7
| | | | | | | | | | | | The config and attrcache file reading code would attempt to load a file in a home directory by expanding the `~` and looking for the file, using `git_sysdir_find_global_file`. If the file was not found, the error handling would look for the literal path, eg `~/filename.txt`. Use the new `git_config_expand_global_file` instead, which allows us to get the path to the file separately, when the path is prefixed with `~/`, and fail with a not found error without falling back to looking for the literal path.
* attrcache: remove useless `do_init` indirectionPatrick Steinhardt2017-02-211-1/+1
| | | | | | | | | | | Remove useless indirection from `git_attr_cache__init` to `git_attr_cache__do_init`. The difference is that the `git_attr_cache__init` macro first checks if the cache is already initialized and, if so, not call `git_attr_cache__do_init`. But actually, `git_attr_cache__do_init` already does the same thing and returns immediately if the cache is already initialized. Remove the indirection.
* attrcache: replace existing file entry with `git__swap`Patrick Steinhardt2017-02-211-2/+5
| | | | | | | When doing an upsert of a file, we used to use `git__compare_and_swap`, comparing the entry's file which is to be replaced with itself. This can be more easily formulated by using `git__swap`, which unconditionally replaces the value.
* attrcache: do not lock/unlock the mutex directlyPatrick Steinhardt2017-02-211-3/+3
| | | | | | Improve encapsulation by not referencing the attrcache mutex directly but instead using the `attr_cache_lock` and `attr_cache_unlock` functions.
* strmap: remove GIT__USE_STRMAP macroPatrick Steinhardt2017-02-171-2/+0
|
* khash: avoid using macro magic to get return addressPatrick Steinhardt2017-02-171-2/+2
|
* attr_cache_remove: don't remove given fileEdward Thomson2017-01-231-4/+6
| | | | | If `attr_cache_lookup_entry` fails to find the given file, make sure that we do not try to free the given file.
* giterr_set: consistent error messagesEdward Thomson2016-12-291-3/+3
| | | | | | | | Error messages should be sentence fragments, and therefore: 1. Should not begin with a capital letter, 2. Should not conclude with punctuation, and 3. Should not end a sentence and begin a new one
* pool: Simplify implementationVicent Marti2015-10-281-2/+3
|
* config: borrow refcounted referencescmn/config-borrow-entryCarlos Martín Nieto2015-03-031-1/+2
| | | | | | | | | | | | | | | 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.
* attr_session: keep a temp bufferEdward Thomson2015-02-041-3/+7
|
* attrcache: don't re-read attrs during checkoutEdward Thomson2015-02-031-2/+3
| | | | | | | | | | | During checkout, assume that the .gitattributes files aren't modified during the checkout. Instead, create an "attribute session" during checkout. Assume that attribute data read in the same checkout "session" hasn't been modified since the checkout started. (But allow subsequent checkouts to invalidate the cache.) Further, cache nonexistent git_attr_file data even when .gitattributes files are not found to prevent re-scanning for nonexistent files.
* Merge pull request #2303 from jacquesg/mingw-lseekVicent Marti2014-05-191-1/+1
|\ | | | | WIP: Windows fixes
| * git_pool_mallocsz takes an unsigned longJacques Germishuys2014-05-011-1/+1
| |
* | Increase use of config snapshotsrb/coverity-fixesRussell Belfer2014-05-131-4/+7
|/ | | | And decrease extra reload checks of config data.
* Fix some coverity-found issuesRussell Belfer2014-04-211-6/+4
|
* attrcache: fix use-after-freeCarlos Martín Nieto2014-04-211-1/+1
| | | | Reported by coverity.
* Some memory leak fixesRussell Belfer2014-04-171-26/+28
|
* Fix broken logic for attr cache invalidationRussell Belfer2014-04-171-61/+61
| | | | | | | The checks to see if files were out of date in the attibute cache was wrong because the cache-breaker data wasn't getting stored correctly. Additionally, when the cache-breaker triggered, the old file data was being leaked.
* Fix tests with new attr cache codeRussell Belfer2014-04-171-33/+82
|
* Attribute file cache refactorRussell Belfer2014-04-171-0/+397
This is a big refactoring of the attribute file cache to be a bit simpler which in turn makes it easier to enforce a lock around any updates to the cache so that it can be used in a threaded env. Tons of changes to the attributes and ignores code.