1. 09 Jun, 2020 1 commit
    • tree-wide: do not compile deprecated functions with hard deprecation · c6184f0c
      When compiling libgit2 with -DDEPRECATE_HARD, we add a preprocessor
      definition `GIT_DEPRECATE_HARD` which causes the "git2/deprecated.h"
      header to be empty. As a result, no function declarations are made
      available to callers, but the implementations are still available to
      link against. This has the problem that function declarations also
      aren't visible to the implementations, meaning that the symbol's
      visibility will not be set up correctly. As a result, the resulting
      library may not expose those deprecated symbols at all on some platforms
      and thus cause linking errors.
      
      Fix the issue by conditionally compiling deprecated functions, only.
      While it becomes impossible to link against such a library in case one
      uses deprecated functions, distributors of libgit2 aren't expected to
      pass -DDEPRECATE_HARD anyway. Instead, users of libgit2 should manually
      define GIT_DEPRECATE_HARD to hide deprecated functions. Using "real"
      hard deprecation still makes sense in the context of CI to test we don't
      use deprecated symbols ourselves and in case a dependant uses libgit2 in
      a vendored way and knows it won't ever use any of the deprecated symbols
      anyway.
      Patrick Steinhardt committed
  2. 01 Apr, 2020 1 commit
  3. 07 Feb, 2020 1 commit
  4. 25 Nov, 2019 1 commit
  5. 23 Aug, 2019 1 commit
    • indexer: catch OOM when adding expected OIDs · a477bff1
      When adding OIDs to the indexer's map of yet-to-be-seen OIDs to verify
      that packfiles are complete, we do so by first allocating a new OID and
      then calling `git_oidmap_set` on it. There was no check for memory
      allocation errors in place, though, leading to possible segfaults due to
      trying to copy data to a `NULL` pointer.
      
      Verify the result of `git__malloc` with `GIT_ERROR_CHECK_ALLOC` to fix
      the issue.
      Patrick Steinhardt committed
  6. 14 Jun, 2019 1 commit
    • Rename opt init functions to `options_init` · 0b5ba0d7
      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.
      Edward Thomson committed
  7. 22 Feb, 2019 1 commit
  8. 15 Feb, 2019 3 commits
    • indexer: use map iterator to delete expected OIDs · c976b4f9
      To compute whether there are objects missing in a packfile, the indexer keeps
      around a map of OIDs that it still expects to see. This map does not store any
      values at all, but in fact the keys are owned by the map itself. Right now, we
      free these keys by iterating over the map and freeing the key itself, which is
      kind of awkward as keys are expected to be constant.
      
      We can make this a bit prettier by inserting the OID as value, too. As we
      already store the `NULL` pointer either way, this does not increase memory
      usage, but makes the code a tad more clear. Furthermore, we convert the
      previously existing map iteration via indices to make use of an iterator,
      instead.
      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
    • 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
  9. 22 Jan, 2019 1 commit
  10. 01 Dec, 2018 1 commit
  11. 28 Nov, 2018 1 commit
  12. 20 Jul, 2018 1 commit
  13. 16 Jul, 2018 1 commit
  14. 12 Jul, 2018 2 commits
  15. 22 Jun, 2018 6 commits
    • indexer: add ability to select connectivity checks · 5ec4aee9
      Right now, we simply turn on connectivity checks in the indexer as soon
      as we have access to an object database. But seeing that the
      connectivity checks may incur additional overhead, we do want the user
      to decide for himself whether he wants to allow those checks.
      Furthermore, it might also be desirable to check connectivity in case
      where no object database is given at all, e.g. in case where a fully
      connected pack file is expected.
      
      Add a flag `verify` to `git_indexer_options` to enable additional
      verification checks. Also avoid to query the ODB in case none is given
      to allow users to enable checks when they do not have an ODB.
      Patrick Steinhardt committed
    • indexer: introduce options struct to `git_indexer_new` · c16556aa
      We strive to keep an options structure to many functions to be able to
      extend options in the future without breaking the API. `git_indexer_new`
      doesn't have one right now, but we want to be able to add an option
      for enabling strict packfile verification.
      
      Add a new `git_indexer_options` structure and adjust callers to use
      that.
      Patrick Steinhardt committed
    • indexer: check pack file connectivity · a616fb16
      When passing `--strict` to `git-unpack-objects`, core git will verify
      the pack file that is currently being read. In addition to the typical
      checksum verification, this will especially cause it to verify object
      connectivity of the received pack file. So it checks, for every received
      object, if all the objects it references are either part of the local
      object database or part of the pack file. In libgit2, we currently have
      no such mechanism, which leaves us unable to verify received pack files
      prior to writing them into our local object database.
      
      This commit introduce the concept of `expected_oids` to the indexer.
      When pack file verification is turned on by a new flag, the indexer will
      try to parse each received object first. If the object has any links to
      other objects, it will check if those links are already satisfied by
      known objects either part of the object database or objects it has
      already seen as part of that pack file. If not, it will add them to the
      list of `expected_oids`. Furthermore, the indexer will remove the
      current object from the `expected_oids` if it is currently being
      expected.
      
      Like this, we are able to verify whether all object links are being
      satisfied. As soon as we hit the end of the object stream and have
      resolved all objects as well as deltified objects, we assert that
      `expected_oids` is in fact empty. This should always be the case for a
      valid pack file with full connectivity.
      Patrick Steinhardt committed
    • indexer: extract function reading stream objects · be41c384
      The loop inside of `git_indexer_append` iterates over every object that
      is to be stored as part of the index. While the logic to retrieve every
      object from the packfile stream is rather involved, it currently just
      part of the loop, making it unnecessarily hard to follow.
      
      Move the logic into its own function `read_stream_object`, which unpacks
      a single object from the stream. Note that there is some subtletly here
      involving the special error `GIT_EBUFS`, which indicates to the indexer
      that no more data is currently available. So instead of returning an
      error and aborting the whole loop in that case, we do have to catch that
      value and return successfully to wait for more data to be read.
      Patrick Steinhardt committed
    • indexer: remove useless local variable · 6568f374
      The `processed` variable local to `git_indexer_append` counts how many
      objects have already been processed. But actually, whenever it gets
      assigned to, we are also assigning the same value to the
      `stats->indexed_objects` struct member. So in fact, it is being quite
      useless due to always having the same value as the `indexer_objects`
      member and makes it a bit harder to understand the code. We can just
      remove the variable to fix that.
      Patrick Steinhardt committed
  16. 10 Jun, 2018 2 commits
  17. 09 Feb, 2018 1 commit
  18. 23 Dec, 2017 1 commit
    • Fix unpack double free · c3514b0b
      If an element has been cached, but then the call to
      packfile_unpack_compressed() fails, the very next thing that happens is
      that its data is freed and then the element is not removed from the
      cache, which frees the data again.
      
      This change sets obj->data to NULL to avoid the double-free. It also
      stops trying to resolve deltas after two continuous failed rounds of
      resolution, and adds a test for this.
      lhchavez committed
  19. 08 Dec, 2017 1 commit
  20. 06 Dec, 2017 1 commit
  21. 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
  22. 08 Jun, 2017 1 commit
    • settings: rename `GIT_OPT_ENABLE_SYNCHRONOUS_OBJECT_CREATION` · 6c23704d
      Initially, the setting has been solely used to enable the use of
      `fsync()` when creating objects. Since then, the use has been extended
      to also cover references and index files. As the option is not yet part
      of any release, we can still correct this by renaming the option to
      something more sensible, indicating not only correlation to objects.
      
      This commit renames the option to `GIT_OPT_ENABLE_FSYNC_GITDIR`. We also
      move the variable from the object to repository source code.
      Patrick Steinhardt committed
  23. 19 May, 2017 1 commit
    • indexer: name pack files after trailer hash · c0e54155
      Upstream git.git has changed the way how packfiles are named.
      Previously, they were using a hash of the contained object's OIDs, which
      has then been changed to use the hash of the complete packfile instead.
      See 1190a1acf (pack-objects: name pack files after trailer hash,
      2013-12-05) in the git.git repository for more information on this
      change.
      
      This commit changes our logic to match the behavior of core git.
      Chris Hescock committed
  24. 02 Mar, 2017 1 commit
  25. 28 Feb, 2017 3 commits
  26. 17 Feb, 2017 4 commits