Thread (31 messages) flat view 31 messages, 3 authors, 2021-10-04

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

From: Elijah Newren <hidden>
Date: 2021-10-04 13:54:59

On Sun, Oct 3, 2021 at 5:46 PM Ævar Arnfjörð Bjarmason [off-list ref] 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.
quoted hunk ↗ jump to hunk
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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help