git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 05/10] dir.[ch]: make DIR_INIT mandatory

From
Elijah Newren <newren@gmail.com>
Date
Oct 4, 2021, 13:45 UTC
Message-ID
<CABPp-BHZZ4ETPAwf_jBZDZfHCvOUsL5Xnz8Ai0dHWAzazz7nnA@mail.gmail.com>
In-Reply-To
<patch-05.10-042080b8d6d-20211004T002226Z-avarab@gmail.com>
On Sun, Oct 3, 2021 at 5:46 PM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

The subject seems misleading; this patch doesn't make DIR_INIT mandatory, it is just updating the docs to reflect that and updating an out-of-date callsite.

Show 50 quoted lines
>
> The dir_init() initializer has been documented as being mandatory
> since eceba532141 (dir: fix problematic API to avoid memory leaks,
> 2020-08-18), but both it and my ce93a4c6127 (dir.[ch]: replace
> dir_init() with DIR_INIT, 2021-07-01) managed to miss this callsite in
> "add-interactive.c" added before those two commits in
> ab1e1cccaf6 (built-in add -i: re-implement `add-untracked` in C,
> 2019-11-29).
>
> In addition my change to remove dir_init() neglected to update this
> documentation. Let's use "must be initialized with" in reference to
> "DIR_INIT". We have one lazy initialization which pre-dates
> eceba532141 in dir.c. Adjusting this callsite is a prerequisite for
> removing it in favor of trusting the macro to initialize the "struct
> dir_struct" correctly.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  add-interactive.c | 2 +-
>  dir.h             | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/add-interactive.c b/add-interactive.c
> index 6498ae196f1..27daea8d1b3 100644
> --- a/add-interactive.c
> +++ b/add-interactive.c
> @@ -826,7 +826,7 @@ static int get_untracked_files(struct repository *r,
>                                struct prefix_item_list *files,
>                                const struct pathspec *ps)
>  {
> -       struct dir_struct dir = { 0 };
> +       struct dir_struct dir = DIR_INIT;
>         size_t i;
>         struct strbuf buf = STRBUF_INIT;
>
> diff --git a/dir.h b/dir.h
> index 83f46c0fb4c..ff3b4a7f602 100644
> --- a/dir.h
> +++ b/dir.h
> @@ -19,7 +19,7 @@
>   * CE_SKIP_WORKTREE marked. If you want to exclude files, make sure you have
>   * loaded the index first.
>   *
> - * - Prepare `struct dir_struct dir` using `dir_init()` function.
> + * - The `struct dir_struct dir` must be initialized with `DIR_INIT`.
>   *
>   * - To add single exclude pattern, call `add_pattern_list()` and then
>   *   `add_pattern()`.
> --
> 2.33.0.1404.g83021034c5d
...other than the subject, the patch looks good
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 19 of 31 in “unpack-trees & dir APIs: fix memory leaks”
  1. 00/10 unpack-trees & dir APIs: fix memory leaksÆvar Arnfjörð Bjarmason, Oct 4, 2021
  2. 02/10 merge-recursive.c: call a new unpack_trees_options_init() functionÆvar Arnfjörð Bjarmason, Oct 4, 2021
  3. Elijah NewrenOct 4, 2021
  4. Ævar Arnfjörð BjarmasonOct 4, 2021
  5. Elijah NewrenOct 4, 2021
  6. 04/10 unpack-trees API: don't have clear_unpack_trees_porcelain() resetÆvar Arnfjörð Bjarmason, Oct 4, 2021
  7. Phillip WoodOct 4, 2021
  8. Ævar Arnfjörð BjarmasonOct 4, 2021
  9. Elijah NewrenOct 4, 2021
  10. Ævar Arnfjörð BjarmasonOct 4, 2021
  11. Elijah NewrenOct 4, 2021
  12. 09/10 merge.c: avoid duplicate unpack_trees_options_release() codeÆvar Arnfjörð Bjarmason, Oct 4, 2021
  13. Elijah NewrenOct 4, 2021
  14. Ævar Arnfjörð BjarmasonOct 4, 2021
  15. 03/10 unpack-trees.[ch]: embed "dir" in "struct unpack_trees_options"Ævar Arnfjörð Bjarmason, Oct 4, 2021
  16. Elijah NewrenOct 4, 2021
  17. 01/10 unpack-trees.[ch]: define and use a UNPACK_TREES_OPTIONS_INITÆvar Arnfjörð Bjarmason, Oct 4, 2021
  18. 05/10 dir.[ch]: make DIR_INIT mandatoryÆvar Arnfjörð Bjarmason, Oct 4, 2021
  19. Elijah NewrenOct 4, 2021
  20. 06/10 dir.c: get rid of lazy initializationÆvar Arnfjörð Bjarmason, Oct 4, 2021
  21. Elijah NewrenOct 4, 2021
  22. 07/10 unpack-trees API: rename clear_unpack_trees_porcelain()Ævar Arnfjörð Bjarmason, Oct 4, 2021
  23. Phillip WoodOct 4, 2021
  24. Ævar Arnfjörð BjarmasonOct 4, 2021
  25. Elijah NewrenOct 4, 2021
  26. 08/10 unpack-trees: don't leak memory in verify_clean_subdirectory()Ævar Arnfjörð Bjarmason, Oct 4, 2021
  27. Elijah NewrenOct 4, 2021
  28. 10/10 built-ins: plug memory leaks with unpack_trees_options_release()Ævar Arnfjörð Bjarmason, Oct 4, 2021
  29. Elijah NewrenOct 4, 2021
  30. Ævar Arnfjörð BjarmasonOct 4, 2021
  31. Elijah NewrenOct 4, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.