1. 17 Oct, 2021 1 commit
    • str: introduce `git_str` for internal, `git_buf` is external · f0e693b1
      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.
      Edward Thomson committed
  2. 26 Aug, 2021 1 commit
    • Homogenize semantics for atomic-related functions · 74708a81
      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.
      lhchavez committed
  3. 25 Aug, 2021 1 commit
  4. 11 May, 2021 1 commit
  5. 06 Dec, 2020 1 commit
  6. 27 Nov, 2020 1 commit
  7. 21 Sep, 2019 1 commit
  8. 16 Jun, 2019 1 commit
  9. 19 May, 2019 2 commits
    • diff_driver: detect memory allocation errors when loading diff driver · 31f8f82a
      When searching for a configuration key for the diff driver, we construct
      the config key by modifying a buffer and then passing it to
      `git_config_get_multivar_foreach`. We do not check though whether the
      modification of the buffer actually succeded, so we could in theory end
      up passing the OOM buffer to the config function.
      
      Fix that by checking return codes. While at it, switch to use
      `git_buf_PUTS` to avoid repetition of the appended string to calculate
      its length.
      Patrick Steinhardt committed
    • regexec: prefix all regexec function calls with p_ · 02683b20
      Prefix all the calls to the the regexec family of functions with `p_`.
      This allows us to swap out all the regular expression functions with our
      own implementation.  Move the declarations to `posix_regex.h` for
      simpler inclusion.
      Edward Thomson committed
  10. 15 Feb, 2019 3 commits
    • strmap: introduce high-level setter for key/value pairs · 03555830
      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.
      Patrick Steinhardt committed
    • strmap: introduce `git_strmap_get` and use it throughout the tree · ef507bc7
      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.
      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
  11. 22 Jan, 2019 1 commit
  12. 28 Nov, 2018 1 commit
  13. 10 Jun, 2018 1 commit
  14. 03 Jan, 2018 1 commit
    • diff_generate: avoid excessive stats of .gitattribute files · d8896bda
      When generating a diff between two trees, for each file that is to be
      diffed we have to determine whether it shall be treated as text or as
      binary files. While git has heuristics to determine which kind of diff
      to generate, users can also that default behaviour by setting or
      unsetting the 'diff' attribute for specific files.
      
      Because of that, we have to query gitattributes in order to determine
      how to diff the current files. Instead of hitting the '.gitattributes'
      file every time we need to query an attribute, which can get expensive
      especially on networked file systems, we try to cache them instead. This
      works perfectly fine for every '.gitattributes' file that is found, but
      we hit cache invalidation problems when we determine that an attribuse
      file is _not_ existing. We do create an entry in the cache for missing
      '.gitattributes' files, but as soon as we hit that file again we
      invalidate it and stat it again to see if it has now appeared.
      
      In the case of diffing large trees with each other, this behaviour is
      very suboptimal. For each pair of files that is to be diffed, we will
      repeatedly query every directory component leading towards their
      respective location for an attributes file. This leads to thousands or
      even hundreds of thousands of wasted syscalls.
      
      The attributes cache already has a mechanism to help in that scenario in
      form of the `git_attr_session`. As long as the same attributes session
      is still active, we will not try to re-query the gitmodules files at all
      but simply retain our currently cached results. To fix our problem, we
      can create a session at the top-most level, which is the initialization
      of the `git_diff` structure, and use it in order to look up the correct
      diff driver. As the `git_diff` structure is used to generate patches for
      multiple files at once, this neatly solves our problem by retaining the
      session until patches for all files have been generated.
      
      The fix has been tested with linux.git by calling
      `git_diff_tree_to_tree` and `git_diff_to_buf` with v4.10^{tree} and
      v4.14^{tree}.
      
                      | time    | .gitattributes stats
          without fix | 33.201s | 844614
          with fix    | 30.327s | 4441
      
      While execution only improved by roughly 10%, the stat(3) syscalls for
      .gitattributes files decreased by 99.5%. The benchmarks were quite
      simple with best-of-three timings on Linux ext4 systems. One can assume
      that for network based file systems the performance gain will be a lot
      larger due to a much higher latency.
      Patrick Steinhardt committed
  15. 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
  16. 17 Feb, 2017 2 commits
  17. 29 Dec, 2016 1 commit
  18. 06 Oct, 2016 1 commit
  19. 21 Jun, 2016 1 commit
  20. 26 May, 2016 1 commit
  21. 15 Aug, 2015 1 commit
  22. 10 Apr, 2015 1 commit
    • Fix checking of return value for regcomp. · 129022ee
      The regcomp function returns a non-zero value if compilation of
      a regular expression fails. In most places we only check for
      negative values, but positive values indicate an error, as well.
      Fix this tree-wide, fixing a segmentation fault when calling
      git_config_iterator_glob_new with an invalid regexp.
      Patrick Steinhardt committed
  23. 03 Mar, 2015 1 commit
    • config: borrow refcounted references · 9a97f49e
      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.
      Carlos Martín Nieto committed
  24. 19 Feb, 2015 1 commit
  25. 15 Feb, 2015 1 commit
  26. 13 Feb, 2015 2 commits
  27. 16 May, 2014 1 commit
  28. 13 May, 2014 1 commit
  29. 12 May, 2014 1 commit
  30. 07 May, 2014 1 commit
  31. 18 Apr, 2014 1 commit
  32. 17 Apr, 2014 1 commit
  33. 27 Jan, 2014 1 commit
    • Update Javascript userdiff driver and tests · 082e82db
      Writing a sample Javascript driver pointed out some extra
      whitespace handling that needed to be done in the diff driver.
      This adds some tests with some sample javascript code that I
      pulled off of GitHub just to see what would happen.  Also, to
      clean up the userdiff test data, I did a "git gc" and packed
      up the test objects.
      Russell Belfer committed
  34. 24 Jan, 2014 2 commits