1. 15 Feb, 2019 8 commits
    • oidmap: remove legacy low-level interface · bd66925a
      Remove the low-level interface that was exposing implementation details of
      `git_oidmap` 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 high-level iteration interface · 18cf5698
      Currently, our headers need to leak some implementation details of maps due to
      their direct use of indices in the implementation of their foreach macros. This
      makes it impossible to completely hide the map structures away, and also makes
      it impossible to include the khash implementation header in the C files of the
      respective map only.
      
      This is now being fixed by providing a high-level iteration interface
      `map_iterate`, which takes as inputs the map that shall be iterated over, an
      iterator as well as the locations where keys and values shall be put into. For
      simplicity's sake, the iterator is a simple `size_t` that shall initialized to
      `0` on the first call. All existing foreach macros are then adjusted to make use
      of this new function.
      Patrick Steinhardt committed
    • maps: use high-level function to check existence of keys · c50a8ac2
      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.
      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
    • oidmap: introduce high-level setter for key/value pairs · 2e0a3048
      Currently, one would use either `git_oidmap_insert` to insert key/value pairs
      into a map or `git_oidmap_put` to insert a key only. These function have
      historically been macros, which is why their syntax is kind of weird: instead of
      returning an error code directly, they instead have 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.Furthermore, `git_oidmap_put` is tightly
      coupled with implementation details of the map as it exposes the index of
      inserted entries.
      
      Introduce a new function `git_oidmap_set`, which takes as parameters the map,
      key and value and directly returns an error code. Convert all trivial callers of
      `git_oidmap_insert` and `git_oidmap_put` to make use of it.
      Patrick Steinhardt committed
    • oidmap: introduce high-level getter for values · 9694ef20
      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_oidmap_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.
      Patrick Steinhardt committed
    • maps: provide a uniform entry count interface · 7e926ef3
      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.
      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
  2. 28 Nov, 2018 3 commits
    • 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
    • khash: implement map-specific foreach macros · 5bfb3b58
      The current foreach map macros simply redirect to the type-indifferent
      `kh_foreach` macro. As this type-indifferent macro directly accesses the
      structures, the current implementation makes it impossible to make the
      stuctures private to the implementation only. And making them private is
      required to move out the khash include into the implementations to
      decrease the namespace leak.
      Patrick Steinhardt committed
    • khash: implement begin/end via functions instead of macros · 382b668b
      Right now, the `git_*map_begin()` and `git_*map_end()` helpers are
      implemented via macros which simply redirect to `kh_begin` and `kh_end`.
      As these macros refer to members of the map structures, they make it
      impossible to move the khash include into the implementation files.
      
      Implement these helpers as real functions instead to further decouple
      the headers from implementations.
      Patrick Steinhardt committed
  3. 03 Jul, 2017 1 commit
    • Make sure to always include "common.h" first · 0c7f49dd
      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.
      Patrick Steinhardt committed
  4. 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
  5. 17 Feb, 2017 10 commits
  6. 12 Sep, 2015 1 commit
  7. 15 Feb, 2015 1 commit
  8. 13 Feb, 2015 1 commit
  9. 30 Apr, 2014 2 commits
  10. 22 Apr, 2013 2 commits
  11. 08 Jan, 2013 1 commit
  12. 29 Jul, 2012 1 commit
  13. 12 Jul, 2012 1 commit
  14. 25 Apr, 2012 2 commits
    • Rename git_khash_str to git_strmap, etc. · c2b67043
      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`.
      Russell Belfer committed
    • Convert hashtable usage over to khash · 01fed0a8
      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.
      Russell Belfer committed