# [PATCH] add -i: hide init/clear_add_i_state() functions

6 messages from 2026-10-28 to 2026-11-02. Participants: Junio C Hamano, Ben Knoble, Patrick Steinhardt.
Thread: https://gitlist.dev/t/66695

## Junio C Hamano, 2026-10-28 19:57

Subject: [PATCH] add -i: hide init/clear_add_i_state() functions
Message-ID: <xmqqh5i58uo0.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqh5i58uo0.fsf%40gitster.g

```
The "add -i" machinery is encapsulated in run_add_i() function,
which uses init_add_i_state() to initialize the machinery, does its
thing, and clear_add_i_state() to tear it down.  External callers
have no need to call anything other than run_add_i().

Make init/clear_add_i_state() file-scope static functions, and
"struct add_i_state" type as well.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 add-interactive.c | 11 ++++++++---
 add-interactive.h |  9 ---------
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/add-interactive.c b/add-interactive.c
index 3cf8a1dbf8..9a00daf9f9 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -19,14 +19,19 @@
 #include "prompt.h"
 #include "tree.h"
 
-void init_add_i_state(struct add_i_state *s, struct repository *r,
-		      struct interactive_options *opts)
+struct add_i_state {
+	struct repository *r;
+	struct interactive_config cfg;
+};
+
+static void init_add_i_state(struct add_i_state *s, struct repository *r,
+			     struct interactive_options *opts)
 {
 	s->r = r;
 	interactive_config_init(&s->cfg, r, opts);
 }
 
-void clear_add_i_state(struct add_i_state *s)
+static void clear_add_i_state(struct add_i_state *s)
 {
 	interactive_config_clear(&s->cfg);
 	memset(s, 0, sizeof(*s));
diff --git a/add-interactive.h b/add-interactive.h
index eefa2edc7c..47f67ede82 100644
--- a/add-interactive.h
+++ b/add-interactive.h
@@ -6,15 +6,6 @@
 struct pathspec;
 struct repository;
 
-struct add_i_state {
-	struct repository *r;
-	struct interactive_config cfg;
-};
-
-void init_add_i_state(struct add_i_state *s, struct repository *r,
-		      struct interactive_options *opts);
-void clear_add_i_state(struct add_i_state *s);
-
 int run_add_i(struct repository *r, const struct pathspec *ps,
 	      struct interactive_options *opts);
 
-- 
2.56.0-433-ga9209adf11



```

## Ben Knoble, 2026-10-28 20:48

Subject: Re: [PATCH] add -i: hide init/clear_add_i_state() functions
Message-ID: <2E0FBA76-AB3A-4B5C-A08A-9B3272C65307@gmail.com>
URL: https://gitlist.dev/e/2E0FBA76-AB3A-4B5C-A08A-9B3272C65307%40gmail.com
In-Reply-To: <xmqqh5i58uo0.fsf@gitster.g>

```

> Le 28 oct. 2026 à 16:22, Junio C Hamano <gitster@pobox.com> a écrit :
> 
> ﻿The "add -i" machinery is encapsulated in run_add_i() function,
> which uses init_add_i_state() to initialize the machinery, does its
> thing, and clear_add_i_state() to tear it down.  External callers
> have no need to call anything other than run_add_i().
> 
> Make init/clear_add_i_state() file-scope static functions, and
> "struct add_i_state" type as well.

Yep, narrower interfaces are easier for programmers to consume, thanks. 

> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> add-interactive.c | 11 ++++++++---
> add-interactive.h |  9 ---------
> 2 files changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/add-interactive.c b/add-interactive.c
> index 3cf8a1dbf8..9a00daf9f9 100644
> --- a/add-interactive.c
> +++ b/add-interactive.c
> @@ -19,14 +19,19 @@
> #include "prompt.h"
> #include "tree.h"
> 
> -void init_add_i_state(struct add_i_state *s, struct repository *r,
> -              struct interactive_options *opts)
> +struct add_i_state {
> +    struct repository *r;
> +    struct interactive_config cfg;
> +};
> +
> +static void init_add_i_state(struct add_i_state *s, struct repository *r,
> +                 struct interactive_options *opts)
> {
>    s->r = r;
>    interactive_config_init(&s->cfg, r, opts);
> }
> 
> -void clear_add_i_state(struct add_i_state *s)
> +static void clear_add_i_state(struct add_i_state *s)
> {
>    interactive_config_clear(&s->cfg);
>    memset(s, 0, sizeof(*s));
> diff --git a/add-interactive.h b/add-interactive.h
> index eefa2edc7c..47f67ede82 100644
> --- a/add-interactive.h
> +++ b/add-interactive.h
> @@ -6,15 +6,6 @@
> struct pathspec;
> struct repository;
> 
> -struct add_i_state {
> -    struct repository *r;
> -    struct interactive_config cfg;
> -};
> -
> -void init_add_i_state(struct add_i_state *s, struct repository *r,
> -              struct interactive_options *opts);
> -void clear_add_i_state(struct add_i_state *s);
> -
> int run_add_i(struct repository *r, const struct pathspec *ps,
>          struct interactive_options *opts);
> 
> --
> 2.56.0-433-ga9209adf11

And this matches the log message.

I did not check for callers, but I assume you did your due-diligence there ;) 

```

## Patrick Steinhardt, 2026-10-30 09:38

Subject: Re: [PATCH] add -i: hide init/clear_add_i_state() functions
Message-ID: <auRlfDXPhp3RjNyk@pks.im>
URL: https://gitlist.dev/e/auRlfDXPhp3RjNyk%40pks.im
In-Reply-To: <xmqqh5i58uo0.fsf@gitster.g>

```
On Wed, Oct 28, 2026 at 12:57:51PM -0700, Junio C Hamano wrote:
> The "add -i" machinery is encapsulated in run_add_i() function,
> which uses init_add_i_state() to initialize the machinery, does its
> thing, and clear_add_i_state() to tear it down.  External callers
> have no need to call anything other than run_add_i().
> 
> Make init/clear_add_i_state() file-scope static functions, and
> "struct add_i_state" type as well.

Nice cleanup. For historical context, these declarations are not needed
anymore starting with d51b61f5dab (add-patch: remove dependency on
"add-interactive" subsystem, 2026-03-02).

Thanks!

Patrick


```

## Junio C Hamano, 2026-10-30 15:30

Subject: Re: [PATCH] add -i: hide init/clear_add_i_state() functions
Message-ID: <xmqqv76jxl22.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqv76jxl22.fsf%40gitster.g
In-Reply-To: <auRlfDXPhp3RjNyk@pks.im>

```
Patrick Steinhardt <ps@pks.im> writes:

> On Wed, Oct 28, 2026 at 12:57:51PM -0700, Junio C Hamano wrote:
>> The "add -i" machinery is encapsulated in run_add_i() function,
>> which uses init_add_i_state() to initialize the machinery, does its
>> thing, and clear_add_i_state() to tear it down.  External callers
>> have no need to call anything other than run_add_i().
>> 
>> Make init/clear_add_i_state() file-scope static functions, and
>> "struct add_i_state" type as well.
>
> Nice cleanup. For historical context, these declarations are not needed
> anymore starting with d51b61f5dab (add-patch: remove dependency on
> "add-interactive" subsystem, 2026-03-02).

Thanks.  I did not notice that I gave a backstory for the other
three commits but apparently did so without digging into the history
for this one.

By the way, I queued the patches sent to the list on a branch (I
initially made them on a detached HEAD without keeping a local copy
after sending them out) and tried 'git history reword' to update
this one, but it seems it does not honor the notes.rewriteref
configuration variable.  I wonder if this is a known limitation, or
a deliberate design.

Thanks.




```

## Ben Knoble, 2026-10-30 21:35

Subject: Re: [PATCH] add -i: hide init/clear_add_i_state() functions
Message-ID: <EDD8FC7B-91B4-49CA-AE6B-3475E03EF786@gmail.com>
URL: https://gitlist.dev/e/EDD8FC7B-91B4-49CA-AE6B-3475E03EF786%40gmail.com
In-Reply-To: <xmqqv76jxl22.fsf@gitster.g>

```

> Le 30 oct. 2026 à 11:30, Junio C Hamano <gitster@pobox.com> a écrit :
> 
> ﻿Patrick Steinhardt <ps@pks.im> writes:
> 
>>> On Wed, Oct 28, 2026 at 12:57:51PM -0700, Junio C Hamano wrote:
>>> The "add -i" machinery is encapsulated in run_add_i() function,
>>> which uses init_add_i_state() to initialize the machinery, does its
>>> thing, and clear_add_i_state() to tear it down.  External callers
>>> have no need to call anything other than run_add_i().
>>> 
>>> Make init/clear_add_i_state() file-scope static functions, and
>>> "struct add_i_state" type as well.
>> 
>> Nice cleanup. For historical context, these declarations are not needed
>> anymore starting with d51b61f5dab (add-patch: remove dependency on
>> "add-interactive" subsystem, 2026-03-02).
> 
> Thanks.  I did not notice that I gave a backstory for the other
> three commits but apparently did so without digging into the history
> for this one.
> 
> By the way, I queued the patches sent to the list on a branch (I
> initially made them on a detached HEAD without keeping a local copy
> after sending them out) and tried 'git history reword' to update
> this one, but it seems it does not honor the notes.rewriteref
> configuration variable.  I wonder if this is a known limitation, or
> a deliberate design.

Indeed. I believe it is a known limitation (one I would love to
lift, but will probably not dedicate time to produce code soon). Still, I’ll help
in the usual ways if I can ;)

```

## Patrick Steinhardt, 2026-11-02 08:42

Subject: Re: [PATCH] add -i: hide init/clear_add_i_state() functions
Message-ID: <auhM8Y8mkRMJOdjH@pks.im>
URL: https://gitlist.dev/e/auhM8Y8mkRMJOdjH%40pks.im
In-Reply-To: <EDD8FC7B-91B4-49CA-AE6B-3475E03EF786@gmail.com>

```
On Fri, Oct 30, 2026 at 05:35:20PM -0400, Ben Knoble wrote:
> 
> > Le 30 oct. 2026 à 11:30, Junio C Hamano <gitster@pobox.com> a écrit :
> > 
> > ﻿Patrick Steinhardt <ps@pks.im> writes:
> > 
> >>> On Wed, Oct 28, 2026 at 12:57:51PM -0700, Junio C Hamano wrote:
> >>> The "add -i" machinery is encapsulated in run_add_i() function,
> >>> which uses init_add_i_state() to initialize the machinery, does its
> >>> thing, and clear_add_i_state() to tear it down.  External callers
> >>> have no need to call anything other than run_add_i().
> >>> 
> >>> Make init/clear_add_i_state() file-scope static functions, and
> >>> "struct add_i_state" type as well.
> >> 
> >> Nice cleanup. For historical context, these declarations are not needed
> >> anymore starting with d51b61f5dab (add-patch: remove dependency on
> >> "add-interactive" subsystem, 2026-03-02).
> > 
> > Thanks.  I did not notice that I gave a backstory for the other
> > three commits but apparently did so without digging into the history
> > for this one.
> > 
> > By the way, I queued the patches sent to the list on a branch (I
> > initially made them on a detached HEAD without keeping a local copy
> > after sending them out) and tried 'git history reword' to update
> > this one, but it seems it does not honor the notes.rewriteref
> > configuration variable.  I wonder if this is a known limitation, or
> > a deliberate design.
> 
> Indeed. I believe it is a known limitation (one I would love to
> lift, but will probably not dedicate time to produce code soon).
> Still, I’ll help in the usual ways if I can ;)

Yeah, it's a limitation and not a design decision. I'd be happy to
review any such patch series, as I'm also a bit short on time recently.
Meanwhile I've also created an issue in our bug tracker, so we may pick
this up in the next release cycle.

Patrick


```
