1. 08 Jun, 2020 1 commit
  2. 24 Jun, 2019 1 commit
  3. 15 Feb, 2019 6 commits
    • idxmap: remove legacy low-level interface · df42f368
      Remove the low-level interface that was exposing implementation details of
      `git_idxmap` to callers. From now on, only the high-level functions shall be
      used to retrieve or modify values of a map. Adjust remaining existing callers.
      Patrick Steinhardt committed
    • maps: provide return value when deleting entries · 84a089da
      Currently, the delete functions of maps do not provide a return value. Like
      this, it is impossible to tell whether the entry has really been deleted or not.
      Change the implementation to provide either a return value of zero if the entry
      has been successfully deleted or `GIT_ENOTFOUND` if the key could not be found.
      
      Convert callers to the `delete_at` functions to instead use this higher-level
      interface.
      Patrick Steinhardt committed
    • idxmap: have `resize` functions return proper error code · 8da93944
      The currently existing function `git_idxmap_resize` and
      `git_idxmap_icase_resize` do not return any error codes at all due to their
      previous implementation making use of a macro. Due to that, it is impossible to
      see whether the resize operation might have failed due to an out-of-memory
      situation.
      
      Fix this by providing a proper error code. Adjust callers to make use of it.
      Patrick Steinhardt committed
    • idxmap: introduce high-level setter for key/value pairs · 661fc57b
      Currently, one would use the function `git_idxmap_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_idxmap_set`, which takes as parameters the map,
      key and value and directly returns an error code. Convert all callers of
      `git_idxmap_insert` to make use of it.
      Patrick Steinhardt committed
    • idxmap: introduce high-level getter for values · d00c24a9
      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 new high-level functions `git_idxmap_get` and `git_idxmap_icase_get`
      that take a map and a key and return 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.
      Patrick Steinhardt committed
    • maps: use uniform lifecycle management functions · 351eeff3
      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.
      Patrick Steinhardt committed
  4. 22 Jan, 2019 1 commit
  5. 01 Dec, 2018 1 commit
  6. 28 Nov, 2018 1 commit
    • khash: move khash include into implementation files · f2f5ec84
      The current map implementations directly include the "khash.h" headers
      into their own headers to make available a set of static functions,
      defines et cetera. Besides leaking the complete khash namespace into
      files wherever khashes are used, this also triggers Clang's
      -Wunused-function warnings when some of the static functions are not
      being used at all.
      
      Fix the issue by moving the includes into the respective map
      implementation files. Add forward declares for all the map types to make
      them known.
      Patrick Steinhardt committed
  7. 20 Mar, 2017 1 commit
    • map: remove `*map_free` macros · 94af9155
      The `map_free` functions were not implemented as functions but instead
      as macros which also set the map to NULL. While this is most certainly
      sensible in most cases, we should prefer the more obvious behavior,
      namingly leaving the map pointer intact.
      
      Furthermore, this macro has been refactored incorrectly during the
      map-refactorings: the two statements are not actually grouped together
      by a `do { ... } while (0)` block, as it is required for macros to
      match the behavior of functions more closely. This has led to at least
      one subtle nesting error in `pack-objects.c`. The following code block
      
      ```
          if (pb->object_ix)
              git_oidmap_free(pb->object_ix);
      ```
      
      would be expanded to
      
      ```
          if (pb->object_ix)
              git_oidmap__free(pb->object_ix); pb->object_ix = NULL;
      ```
      
      which is not what one woudl expect. While it is not a bug here as it
      would simply become a no-op, the wrong implementation could lead to bugs
      in other occasions.
      
      Fix this by simply removing the macro altogether and replacing it with
      real function calls. This leaves the burden of setting the pointer to
      NULL afterwards to the caller, but this is actually expected and behaves
      like other `free` functions.
      Patrick Steinhardt committed
  8. 17 Feb, 2017 2 commits