Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2] builtin/add.c: replace run_command() with direct apply_all_patches() call
Date: Fri, 10 Jul 2026 11:51:02 -0700	[thread overview]
Message-ID: <xmqqechad6g9.fsf@gitster.g> (raw)
In-Reply-To: <20260710074105.50737-1-gatlavishweshwarreddy26@gmail.com> (Gatla Vishweshwar Reddy's message of "Fri, 10 Jul 2026 13:02:06 +0530")

Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com> writes:

> @@ -187,7 +186,6 @@ static int edit_patch(struct repository *repo,
>  		      const char *prefix)
>  {
>  	char *file = repo_git_path(repo, "ADD_EDIT.patch");
> -	struct child_process child = CHILD_PROCESS_INIT;
>  	struct rev_info rev;
>  	int out;
>  	struct stat st;
> @@ -217,11 +215,17 @@ static int edit_patch(struct repository *repo,
>  	if (!st.st_size)
>  		die(_("empty patch. aborted"));
>
> -	child.git_cmd = 1;
> -	strvec_pushl(&child.args, "apply", "--recount", "--cached", file,
> -		     NULL);
> -	if (run_command(&child))
> +	struct apply_state state;
> +	const char *apply_argv[] = { file, NULL };

These are -Wdeclaration-after-statement violations; we should move
them to the beginning of the function alongside the other variable
declarations.

> +
> +	if (init_apply_state(&state, repo, prefix))
> +		die(_("could not initialize apply state"));
> +	state.cached = 1;
> +	if (check_apply_state(&state, 0))
> +		die(_("could not check apply state"));
> +	if (apply_all_patches(&state, 1, apply_argv, APPLY_OPT_RECOUNT))
>  		die(_("could not apply '%s'"), file);
> +	clear_apply_state(&state);

Does it work properly when run in a subdirectory, such as "cd t &&
git add -e")?  The apply_all_patches() function adjusts the path to
patch files by calling prefix_filename() to prepend state->prefix,
which represents our current directory.

This is not a rhetorical question, as I am unsure what "file"
actually holds at this point after calling repo_git_path().  I don't
know if it is ADD_EDIT.patch relative to a specific directory, an
absolute path to the file, or something else entirely.  It would be
highly beneficial to include a test or two verifying the behavour of
'add -e' from within a subdirectory.

Thanks.

  reply	other threads:[~2026-07-10 18:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09 19:26 [PATCH] builtin/add.c: replace run_command() with direct apply_all_patches() call Gatla Vishweshwar Reddy
2026-07-10  6:41 ` Junio C Hamano
2026-07-10  7:32   ` [PATCH v2] " Gatla Vishweshwar Reddy
2026-07-10 18:51     ` Junio C Hamano [this message]
2026-07-10 19:58       ` [PATCH v3] " Gatla Vishweshwar Reddy
2026-07-11  4:51         ` Junio C Hamano
2026-07-11  6:06           ` [PATCH v4] " Gatla Vishweshwar Reddy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqechad6g9.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=gatlavishweshwarreddy26@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox