1. 23 Feb, 2022 1 commit
  2. 05 Jan, 2022 1 commit
  3. 09 Nov, 2021 1 commit
  4. 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
  5. 26 Sep, 2021 1 commit
  6. 25 Sep, 2021 1 commit
  7. 21 Sep, 2021 1 commit
  8. 22 Jul, 2021 4 commits
  9. 28 Apr, 2021 2 commits
  10. 25 Nov, 2020 1 commit
  11. 11 Aug, 2019 1 commit
  12. 12 Jul, 2019 1 commit
    • 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
  13. 04 Jul, 2019 1 commit
  14. 26 Jun, 2019 2 commits
    • attr: fix attribute lookup if repo has no common directory · 82c7a9bc
      If creating a repository without a common directory (e.g. by
      using `git_repository_new`), then `git_repository_item_path` will
      return `GIT_ENOTFOUND` for every file that's usually located in
      this directory. While we do not care for this case when looking
      up the "info/attributes" file, we fail to properly ignore these
      errors when setting up or collecting attributes files. Thus, the
      gitattributes lookup is broken and will only ever return
      `GIT_ENOTFOUND`.
      
      Fix this issue by properly ignoring `GIT_ENOTFOUND` returned by
      `git_repository_item_path`.
      Patrick Steinhardt committed
    • attr: refactor setup to match current coding style · 5452e49f
      The code in the `attr_setup` function is not really matching our
      current coding style. Besides alignment issues, it's also hard to
      see what functions calls depend on one another because they're
      split up over multiple conditional statements.
      
      Fix these issues by grouping together dependent function calls
      and adjusting the alignment.
      Patrick Steinhardt committed
  15. 16 Jun, 2019 1 commit
  16. 15 Feb, 2019 2 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
    • 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
  17. 22 Jan, 2019 1 commit
  18. 10 Jun, 2018 1 commit
  19. 01 Feb, 2018 1 commit
    • attr: avoid stat'ting files for bare repositories · e28e17e6
      Depending on whether the path we want to look up an attribute for is a
      file or a directory, the fnmatch function will be called with different
      flags. Because of this, we have to first stat(3) the path to determine
      whether it is a file or directory in `git_attr_path__init`. This is
      wasteful though in bare repositories, where we can already be assured
      that the path will never exist at all due to there being no worktree. In
      this case, we will execute an unnecessary syscall, which might be
      noticeable on networked file systems.
      
      What happens right now is that we always pass the `GIT_DIR_FLAG_UNKOWN`
      flag to `git_attr_path__init`, which causes it to `stat` the file itself
      to determine its type. As it is calling `git_path_isdir` on the path,
      which will always return `false` in case the path does not exist, we end
      up with the path always being treated as a file in case of a bare
      repository. As such, we can just check the bare-repository case in all
      callers and then pass in `GIT_DIR_FLAG_FALSE` ourselves, avoiding the
      need to `stat`. While this may not always be correct, it at least is no
      different from our current behavior.
      Patrick Steinhardt committed
  20. 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
  21. 17 Feb, 2017 2 commits
  22. 13 Feb, 2017 1 commit
    • repository: use `git_repository_item_path` · c5f3da96
      The recent introduction of the commondir variable of a repository
      requires callers to distinguish whether their files are part of
      the dot-git directory or the common directory shared between
      multpile worktrees. In order to take the burden from callers and
      unify knowledge on which files reside where, the
      `git_repository_item_path` function has been introduced which
      encapsulate this knowledge.
      
      Modify most existing callers of `git_repository_path` to use
      `git_repository_item_path` instead, thus making them implicitly
      aware of the common directory.
      Patrick Steinhardt committed
  23. 12 May, 2015 1 commit
  24. 28 Apr, 2015 1 commit
  25. 19 Feb, 2015 1 commit
  26. 15 Feb, 2015 1 commit
  27. 04 Feb, 2015 2 commits
  28. 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
  29. 17 Sep, 2014 3 commits