1. 01 Jun, 2020 1 commit
  2. 24 Jan, 2020 1 commit
  3. 12 Dec, 2019 1 commit
  4. 12 Jul, 2019 3 commits
    • attr_file: ignore macros defined in subdirectories · f8346905
      Right now, we are unconditionally applying all macros found in a
      gitatttributes file. But quoting gitattributes(5):
      
          Custom macro attributes can be defined only in top-level
          gitattributes files ($GIT_DIR/info/attributes, the .gitattributes
          file at the top level of the working tree, or the global or
          system-wide gitattributes files), not in .gitattributes files in
          working tree subdirectories. The built-in macro attribute "binary"
          is equivalent to:
      
      So gitattribute files in subdirectories of the working tree may
      explicitly _not_ contain macro definitions, but we do not currently
      enforce this limitation.
      
      This patch introduces a new parameter to the gitattributes parser that
      tells whether macros are allowed in the current file or not. If set to
      `false`, we will still parse macros, but silently ignore them instead of
      adding them to the list of defined macros. Update all callers to
      correctly determine whether the to-be-parsed file may contain macros or
      not. Most importantly, when walking up the directory hierarchy, we will
      only set it to `true` once it reaches the root directory of the repo
      itself.
      
      Add a test that verifies that we are indeed not applying macros from
      subdirectories. Previous to these changes, the test would've failed.
      Patrick Steinhardt committed
    • attrcache: fix memory leak if inserting invalid macro to cache · be8f9bb1
      A macro without any assignments is considered an invalid macro by the
      attributes cache and is thus not getting added to the macro map at all.
      But as `git_attr_cache__insert_macro` returns success with neither
      free'ing nor adopting the macro into its map, this will cause a memory
      leak.
      
      Fix this by freeing the macro in the function if it's not going to be
      added. This is perfectly fine to do, as callers assume that the
      attrcache will have the macro adopted on success anyway.
      Patrick Steinhardt committed
    • attrcache: fix multiple memory leaks when inserting macros · 7277bf83
      The function `git_attr_cache__insert_macro` is responsible for adopting
      macros in the per-repo macro cache. When adding a macro that replaces an
      already existing macro (e.g. because of re-parsing gitattributes files),
      then we do not free the previous macro and thus cause a memory leak.
      
      Fix this leak by first checking if the cache already has a macro defined
      with the same name. If so, free it before replacing the cache entry with
      the new instance.
      Patrick Steinhardt committed
  5. 24 Jun, 2019 1 commit
  6. 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
  7. 22 Jan, 2019 1 commit
  8. 28 Nov, 2018 1 commit
  9. 10 Jun, 2018 1 commit
  10. 03 Jul, 2017 2 commits
    • 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
    • Add missing license headers · 2480d0eb
      Some implementation files were missing the license headers. This commit
      adds them.
      Patrick Steinhardt committed
  11. 23 Mar, 2017 1 commit
    • config, attrcache: don't fallback to dirs literally named `~` · 29aef948
      The config and attrcache file reading code would attempt to load a file
      in a home directory by expanding the `~` and looking for the file, using
      `git_sysdir_find_global_file`.  If the file was not found, the error
      handling would look for the literal path, eg `~/filename.txt`.
      
      Use the new `git_config_expand_global_file` instead, which allows us to
      get the path to the file separately, when the path is prefixed with
      `~/`, and fail with a not found error without falling back to looking
      for the literal path.
      Edward Thomson committed
  12. 21 Feb, 2017 3 commits
  13. 17 Feb, 2017 2 commits
  14. 23 Jan, 2017 1 commit
  15. 29 Dec, 2016 1 commit
  16. 28 Oct, 2015 1 commit
  17. 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
  18. 15 Feb, 2015 1 commit
  19. 04 Feb, 2015 1 commit
  20. 03 Feb, 2015 1 commit
    • attrcache: don't re-read attrs during checkout · 9f779aac
      During checkout, assume that the .gitattributes files aren't
      modified during the checkout.  Instead, create an "attribute session"
      during checkout.  Assume that attribute data read in the same
      checkout "session" hasn't been modified since the checkout started.
      (But allow subsequent checkouts to invalidate the cache.)
      
      Further, cache nonexistent git_attr_file data even when .gitattributes
      files are not found to prevent re-scanning for nonexistent files.
      Edward Thomson committed
  21. 13 May, 2014 1 commit
  22. 01 May, 2014 1 commit
  23. 21 Apr, 2014 2 commits
  24. 17 Apr, 2014 4 commits