summaryrefslogtreecommitdiff
path: root/src/submodule.c
Commit message (Collapse)AuthorAgeFilesLines
* submodule: refactor code to match current coding stylePatrick Steinhardt2020-01-061-57/+48
| | | | | | The submodule code has grown out-of-date regarding its coding style. Update `git_submodule_reload` and `git_submodule_sync` to more closely resemble what the rest of our code base uses.
* submodule sync, fix edge case with submodule sync on empty repokdj0c2020-01-061-1/+1
|
* Fix git_submodule_sync with relative urlkdj0c2020-01-061-4/+6
| | | | | git_submodule_sync should resolve submodule before writing to .git/config to have the same behavior as git_submodule_init, which does the right thing.
* submodule: provide a wrapper for simple submodule clone stepsEtienne Samson2019-10-171-0/+59
|
* configuration: cvar -> configmapPatrick Steinhardt2019-07-181-21/+21
| | | | | `cvar` is an unhelpful name. Refactor its usage to `configmap` for more clarity.
* Rename opt init functions to `options_init`Edward Thomson2019-06-141-1/+6
| | | | | | | | | | | | | In libgit2 nomenclature, when we need to verb a direct object, we name a function `git_directobject_verb`. Thus, if we need to init an options structure named `git_foo_options`, then the name of the function that does that should be `git_foo_options_init`. The previous names of `git_foo_init_options` is close - it _sounds_ as if it's initializing the options of a `foo`, but in fact `git_foo_options` is its own noun that should be respected. Deprecate the old names; they'll now call directly to the new ones.
* maps: use high-level function to check existence of keysPatrick Steinhardt2019-02-151-3/+1
| | | | | | Some callers were still using the tightly-coupled pattern of `lookup_index` and `valid_index` to verify that an entry exists in a map. Instead, use the more high-level `exists` functions to decouple map users from its implementation.
* strmap: introduce high-level setter for key/value pairsPatrick Steinhardt2019-02-151-15/+5
| | | | | | | | | | | | 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-27/+7
| | | | | | | | | | | | | | 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: provide a uniform entry count interfacePatrick Steinhardt2019-02-151-1/+1
| | | | | | | | | There currently exist two different function names for getting the entry count of maps, where offmaps offset and string maps use `num_entries` and OID maps use `size`. In most programming languages with built-in map types, this is simply called `size`, which is also shorter to type. Thus, this commit renames the other two functions `num_entries` to match the common way and adjusts all callers.
* 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-43/+43
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* submodule: grab the error while loading from configEtienne Samson2019-01-041-1/+1
| | | | | | | | Previously, an error in `git_config_next` would be mistaken as a successful load, because the previous call would have succeeded. Coverity saw the subsequent check for a completed iteration as dead, so let's make it useful again. CID 1391374
* object_type: use new enumeration namesethomson/index_fixesEdward Thomson2018-12-011-2/+2
| | | | Use the new object_type enumeration names within the codebase.
* index: use new enum and structure namesEdward Thomson2018-12-011-1/+1
| | | | Use the new-style index names throughout our own codebase.
* khash: remove intricate knowledge of khash typesPatrick Steinhardt2018-11-281-7/+7
| | | | | | | 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.
* submodule: remove string map implementation that strips trailing slashesPatrick Steinhardt2018-11-281-29/+0
| | | | | | | The submodule code currently has its own implementation of a string map, which overrides the hashing and hash equals functions with functions that ignore potential trailing slashes. These functions aren't actually used by our code, making them useless.
* submodule: ignore path and url attributes if they look like optionsCarlos Martín Nieto2018-10-051-8/+23
| | | | | | | | | | | These can be used to inject options in an implementation which performs a recursive clone by executing an external command via crafted url and path attributes such that it triggers a local executable to be run. The library is not vulnerable as we do not rely on external executables but a user of the library might be relying on that so we add this protection. This matches this aspect of git's fix for CVE-2018-17456.
* config: rename "config_file.h" to "config_backend.h"Patrick Steinhardt2018-09-281-13/+13
| | | | | | | | | | The header "config_file.h" has a list of inline-functions to access the contents of a config backend without directly messing with the struct's function pointers. While all these functions are called "git_config_file_*", they are in fact completely backend-agnostic and don't care whether it is a file or not. Rename all the function to instead be backend-agnostic versions called "git_config_backend_*" and rename the header to match.
* submodule: fix submodule names depending on config-owned memoryPatrick Steinhardt2018-09-211-4/+6
| | | | | | | | | | When populating the list of submodule names, we use the submodule configuration entry's name as the key in the map of submodule names. This creates a hidden dependency on the liveliness of the configuration that was used to parse the submodule, which is fragile and unexpected. Fix the issue by duplicating the string before writing it into the submodule name map.
* submodule: don't leak memory when failing to insert the namesEtienne Samson2018-07-061-1/+2
| | | Reported by Coverity, CID 1393237
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-30/+31
|
* submodule: remove useless mask computationsPatrick Steinhardt2018-05-301-18/+1
| | | | | | | | | | | | | | | Previous to dfda2f68e (submodule: remove the per-repo cache, 2015-04-27), we tried to cache our submodules per repository to avoid having to reload it too frequently. As it created some headaches with regards to multithreading, we removed that cache. Previous to that removal, we had to compute what submodule status to refresh. The mask computation was not removed, though, resulting in confusing and actually dead code. While it seems like the mask is currently in use in a conditional, it is not, as we unconditionally assign to the mask previous to that condition. Remove all mask computations to clean up stale code.
* submodule: refactor loading submodule namesPatrick Steinhardt2018-05-301-12/+24
| | | | | | | | | The function `load_submodule_names` was always being called with a newly allocated string map, which was then getting filled by the function. Move the string map allocation into `load_submodule_names`, instead, and pass the whole map back to the caller in case no error occurs. This change helps to avoid misuse by handing in pre-populated maps.
* submodule: detect duplicated submodule pathsPatrick Steinhardt2018-05-301-0/+7
| | | | | | | | | | | | | When loading submodule names, we build a map of submodule paths and their respective names. While looping over the configuration keys, we do not check though whether a submodule path was seen already. This leads to a memory leak in case we have multiple submodules with the same path, as we just overwrite the old value in the map in that case. Fix the error by verifying that the path to be added is not yet part of the string map. Git does not allow to have multiple submodules for a path anyway, so we now do the same and detect this duplication, reporting it to the user.
* submodule: plug leaks from the escape detectionCarlos Martín Nieto2018-05-241-3/+10
|
* submodule: replace index with strchr which exists on WindowsCarlos Martín Nieto2018-05-241-1/+1
|
* submodule: the repostiory for _name_is_valid should not be constCarlos Martín Nieto2018-05-241-3/+2
| | | | | We might modify caches due to us trying to load the configuration to figure out what kinds of filesystem protections we should have.
* path: reject .gitmodules as a symlinkCarlos Martín Nieto2018-05-231-1/+1
| | | | | | | | Any part of the library which asks the question can pass in the mode to have it checked against `.gitmodules` being a symlink. This is particularly relevant for adding entries to the index from the worktree and for checking out files.
* submodule: also validate Windows-separated paths for validityCarlos Martín Nieto2018-05-141-9/+28
| | | | | | | | Otherwise we would also admit `..\..\foo\bar` as a valid path and fail to protect Windows users. Ideally we would check for both separators without the need for the copied string, but this'll get us over the RCE.
* submodule: ignore submodules which include path traversal in their nameCarlos Martín Nieto2018-05-091-3/+25
| | | | | | | | | | | | | | If the we decide that the "name" of the submodule (i.e. its path inside `.git/modules/`) is trying to escape that directory or otherwise trick us, we ignore the configuration for that submodule. This leaves us with a half-configured submodule when looking it up by path, but it's the same result as if the configuration really were missing. The name check is potentially more strict than it needs to be, but it lets us re-use the check we're doing for the checkout. The function that encapsulates this logic is ready to be exported but we don't want to do that in a security release so it remains internal for now.
* Merge pull request #4522 from csware/submodules-should-report-parse-errorsEdward Thomson2018-04-171-18/+27
|\ | | | | Submodules-API should report .gitmodules parse errors instead of ignoring them
| * Submodule API should report .gitmodules parse errorsSven Strickroth2018-03-271-18/+27
| | | | | | | | Signed-off-by: Sven Strickroth <email@cs-ware.de>
* | submodule: add more robust error handling when a submodule path is found on addCarson Howard2018-03-281-11/+14
| |
* | submodule: add better error handling to is_path_occupiedCarson Howard2018-03-271-1/+4
| |
* | submodule: change can_add_submodule to is_path_occupiedCarson Howard2018-03-271-6/+11
| |
* | submodule: update index check to check path before directory and fix testsCarson Howard2018-03-271-19/+24
| |
* | submodule: fix styling errorsCarson Howard2018-03-271-29/+36
| |
* | submodule: check index for prefix before adding submoduleCarson Howard2018-03-271-0/+31
|/ | | | | | | submodule: check path and prefix before adding submodule submodule: fix test errors
* config: pass repository when opening config filesPatrick Steinhardt2017-10-091-1/+1
| | | | | | | | | | | | | | | | | Our current configuration logic is completely oblivious of any repository, but only cares for actual file paths. Unfortunately, we are forced to break this assumption by the introduction of conditional includes, which are evaluated in the context of a repository. Right now, only one conditional exists with "gitdir:" -- it will only include the configuration if the current repository's git directory matches the value passed to "gitdir:". To support these conditionals, we have to break our API and make the repository available when opening a configuration file. This commit extends the `open` call of configuration backends to include another repository and adjusts existing code to have it available. This includes the user-visible functions `git_config_add_file_ondisk` and `git_config_add_backend`.
* submodule: refuse lookup in bare repositoriesPatrick Steinhardt2017-08-251-0/+10
| | | | | | | | | | | | | | While it is technically possible to look up submodules inside of a bare repository by reading the submodule configuration of a specific commit, we do not offer this functionality right now. As such, calling both `git_submodule_lookup` and `git_submodule_foreach` should error out early when these functions encounter a bare repository. While `git_submodule_lookup` already does return an error due to not being able to parse the configuration, `git_submodule_foreach` simply returns success and never invokes the callback function. Fix the issue by having both functions check whether the repository is bare and returning an error in that case.
* Make sure to always include "common.h" firstPatrick Steinhardt2017-07-031-2/+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.
* Merge pull request #4163 from pks-t/pks/submodules-with-worktreesEdward Thomson2017-03-221-6/+18
|\ | | | | Worktree fixes
| * submodule: resolve URLs relative to main worktreePatrick Steinhardt2017-03-171-6/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is possible to specify submodule URLs relative to the repository location. E.g. having a submodule with URL "../submodule" will look for the submodule at "repo/../submodule". With the introduction of worktrees, though, we cannot simply resolve the URL relative to the repository location itself. If the repository for which a URL is to be resolved is a working tree, we have to resolve the URL relative to the parent's repository path. Otherwise, the URL would change depending on where the working tree is located. Fix this by special-casing when we have a working tree while getting the URL base.
* | submodule: catch when submodule is not staged on updatePatrick Steinhardt2017-03-141-1/+9
|/ | | | | | | | | | | When calling `git_submodule_update` on a submodule, we have to retrieve the ID of the submodule entry in the index. If the function is called on a submodule which is only partly initialized, the submodule entry may not be added to the index yet. This leads to an assert when trying to look up the blob later on. Fix the issue by checking if the index actually holds the submodule's ID and erroring out if it does not.
* khash: avoid using macro magic to get return addressPatrick Steinhardt2017-02-171-2/+2
|
* khash: avoid using `kh_put` directlyPatrick Steinhardt2017-02-171-1/+1
|
* khash: avoid using `kh_size` directlyPatrick Steinhardt2017-02-171-1/+1
|
* repository: use `git_repository_item_path`Patrick Steinhardt2017-02-131-4/+8
| | | | | | | | | | | | | | The recent introduction of the commondir variable of a repository requires callers to distinguish whether their files are part of the dot-git directory or the common directory shared between multpile worktrees. In order to take the burden from callers and unify knowledge on which files reside where, the `git_repository_item_path` function has been introduced which encapsulate this knowledge. Modify most existing callers of `git_repository_path` to use `git_repository_item_path` instead, thus making them implicitly aware of the common directory.
* Fix uninitialized variable warningMatthew Plough2017-01-271-1/+1
| | | | | | | | | | | | | | | | | | | | Fix the following warning emitted by clang: [ 16%] Building C object CMakeFiles/libgit2_clar.dir/src/submodule.c.o /Users/mplough/devel/external/libgit2/src/submodule.c:408:6: warning: variable 'i' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] if ((error = load_submodule_names(names, cfg))) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/mplough/devel/external/libgit2/src/submodule.c:448:20: note: uninitialized use occurs here git_iterator_free(i); ^ /Users/mplough/devel/external/libgit2/src/submodule.c:408:2: note: remove the 'if' if its condition is always false if ((error = load_submodule_names(names, cfg))) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/mplough/devel/external/libgit2/src/submodule.c:404:17: note: initialize the variable 'i' to silence this warning git_iterator *i; ^ = NULL 1 warning generated.